frontend

package
v0.0.0-...-54df73f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 30, 2021 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Templater = tmplutil.Templater{
	FileSystem: embedFS,
	Includes: map[string]string{
		"css":        "components/css.html",
		"header":     "components/header.html",
		"footer":     "components/footer.html",
		"empty-card": "components/empty-card.html",
	},
	Functions: template.FuncMap{
		"markup": func(input string) template.HTML {
			return template.HTML(markup.ToHTML(input))
		},
		"rgbaHex": func(rgba [4]float32) string {
			color := colorful.FastLinearRgb(
				float64(rgba[0]),
				float64(rgba[1]),
				float64(rgba[2]),
			)
			return color.Hex()
		},
		"shortErr": func(err string) string {
			parts := strings.Split(err, ": ")
			if len(parts) == 0 {
				return ""
			}

			part := parts[len(parts)-1]

			r, sz := utf8.DecodeRuneInString(part)
			if sz == 0 {
				return ""
			}

			return string(unicode.ToUpper(r)) + part[sz:] + "."
		},
	},
}

Functions

func ExecuteNamedTemplate

func ExecuteNamedTemplate(w http.ResponseWriter, r *http.Request, name string)

ExecuteNamedTemplate executes the named template with the RenderState.

func ExecuteTemplate

func ExecuteTemplate(w http.ResponseWriter, r *http.Request, sub *tmplutil.Subtemplate)

ExecuteTemplate executes the template with the RenderState.

func InjectRenderState

func InjectRenderState(state RenderState) func(http.Handler) http.Handler

InjectRenderState injects the render state.

func MountStatic

func MountStatic() http.Handler

MountStatic mounts the static route.

Types

type RenderState

type RenderState struct {
	Client      *distance.Client
	Observer    *distance.Observer
	SiteName    string
	DistanceURL *url.URL
}

func GetRenderState

func GetRenderState(ctx context.Context) RenderState

GetRenderState gets the render state inside the given context.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL