viewutil

package
v1.14.0 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2023 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

Package viewutil provides utilities and common templates for views across all packages.

Index

Constants

This section is empty.

Variables

View Source
var (
	BaseEn *template.Template
	BaseRu *template.Template
)
View Source
var HeaderLinks []HeaderLink

HeaderLinks is a list off current header links. Feel free to iterate it directly but do not modify it by yourself. Call ParseHeaderLinks if you need to set new header links.

Functions

func Base

func Base(meta Meta, title, body string, bodyAttributes map[string]string, headElements ...string) string

Base is a temporary wrapper around BaseEn and BaseRu, meant to facilitate the migration from qtpl. TODO: get rid of this

func ExecutePage

func ExecutePage(meta Meta, chain Chain, data interface {
	withBaseValues(meta Meta, headerLinks []HeaderLink, commonScripts []string)
})

ExecutePage executes template page in the given chain with the given data that has BaseData nested. It also sets some common BaseData fields

func HttpErr

func HttpErr(meta Meta, status int, name, errMsg string)

HttpErr is used by many handlers to signal errors in a compact way. TODO: get rid of this abomination

func Init

func Init()

Types

type BaseData

type BaseData struct {
	Meta           Meta
	HeadElements   []string
	HeaderLinks    []HeaderLink
	CommonScripts  []string
	EditScripts    []string
	Addr           string
	Title          string // TODO: remove
	Body           string // TODO: remove
	BodyAttributes map[string]string
}

type Chain

type Chain struct {
	// contains filtered or unexported fields
}

Chain represents a chain of different language versions of the same template.

func CopyEnRuWith

func CopyEnRuWith(fsys fs.FS, filename, ruTranslation string) Chain

func (Chain) Get

func (c Chain) Get(meta Meta) *template.Template

Get returns an appropriate language representation for the given locale in meta.

TODO: Get rid of this

type HeaderLink struct {
	// Href is the URL of the link. It goes <a href="here">...</a>.
	Href string
	// Display is what is shown when the link is rendered. It goes <a href="...">here</a>.
	Display string
}

HeaderLink represents a header link. Header links are the links shown in the top gray bar.

type Meta

type Meta struct {
	Lc   *l18n.Localizer
	U    *user.User
	W    io.Writer
	Addr string
}

Meta is a bundle of common stuffs used by views, templates.

func MetaFrom

func MetaFrom(w http.ResponseWriter, rq *http.Request) Meta

MetaFrom makes a Meta from the given data. You are meant to further modify it.

func (Meta) Locale

func (m Meta) Locale() string

Jump to

Keyboard shortcuts

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