Documentation ¶
Overview ¶
Package templates handles the website templating system.
This supports several 'themes' and partials for template-reuse
Index ¶
- Constants
- func AbsoluteDate(t time.Time) string
- func Definitions(fsys fs.FS, files []string) error
- func GetTheme(ctx context.Context) string
- func HumanDuration(d time.Duration) string
- func MediaDuration(d time.Duration) string
- func PrintJSON(v any) (template.HTML, error)
- func SafeHTML(v any) (template.HTML, error)
- func SafeHTMLAttr(v any) (template.HTMLAttr, error)
- func SetTheme(ctx context.Context, theme string, override bool) context.Context
- func SetThemeHandler(cookieName string, resolve func(string) string) http.Handler
- func TemplateFuncs() template.FuncMap
- func ThemeCtx(storage radio.StorageService) func(http.Handler) http.Handler
- func TimeagoDuration(d time.Duration) string
- type Executor
- type Site
- type TemplateBundle
- type TemplateSelectable
- type TemplateSelector
- type ThemeBundle
- type Themes
Constants ¶
const ( // the extension used for template files TEMPLATE_EXT = ".tmpl" // the directory for static assets ASSETS_DIR = "assets" // the directory name used for partial templates, these are under <theme>/partials PARTIAL_DIR = "partials" // the directory name for form templates, these are under <theme>/forms FORMS_DIR = "forms" // directory name of the default templates DEFAULT_DIR = "default-light" // directory name of the default admin templates DEFAULT_ADMIN_DIR = "admin-light" // the prefix used on themes that are for the admin panel ADMIN_PREFIX = "admin-" )
const ThemeAdminCookieName = "admin-theme"
const ThemeCookieName = "theme"
Variables ¶
This section is empty.
Functions ¶
func AbsoluteDate ¶
func Definitions ¶
Definitions prints a table showing what templates are defined in this Template and from what file it was loaded. The last template in the table is the one in-use.
func GetTheme ¶
GetTheme returns the theme from the given context. panics if no ThemeKey is found, so make sure ThemeCtx is used
func HumanDuration ¶
func MediaDuration ¶
func SetThemeHandler ¶
func TemplateFuncs ¶
func TimeagoDuration ¶
Types ¶
type Site ¶
type Site struct { Production bool // contains filtered or unexported fields }
Site is an overarching struct containing all the themes of the website.
func FromDirectory ¶
func (*Site) ResolveThemeName ¶
func (*Site) Template ¶
Template returns a Template associated with the theme and page name given.
If theme does not exist it uses the default-theme
func (*Site) Theme ¶
func (s *Site) Theme(name string) ThemeBundle
func (*Site) ThemeNames ¶
type TemplateBundle ¶
type TemplateBundle struct {
// contains filtered or unexported fields
}
TemplateBundle contains all the filenames required to construct a template instance for the page
func (*TemplateBundle) Dump ¶
func (tb *TemplateBundle) Dump() string
func (*TemplateBundle) Files ¶
func (tb *TemplateBundle) Files() []string
Files returns all the files in this bundle sorted in load-order
type TemplateSelectable ¶
type TemplateSelector ¶
type ThemeBundle ¶
type ThemeBundle struct {
// contains filtered or unexported fields
}
ThemeBundle
func (ThemeBundle) Assets ¶
func (tb ThemeBundle) Assets() fs.FS
func (ThemeBundle) Page ¶
func (tb ThemeBundle) Page(name string) (*TemplateBundle, error)
type Themes ¶
type Themes map[string]ThemeBundle