Documentation ¶
Overview ¶
Package templates handles the website templating system.
This supports several 'themes' and partials for template-reuse
Index ¶
- Constants
- func Definitions(fsys fs.FS, files []string) error
- func GetTheme(ctx context.Context) radio.ThemeName
- func IsAdminTheme(name radio.ThemeName) bool
- func SetTheme(ctx context.Context, theme radio.ThemeName, override bool) context.Context
- func SetThemeHandler(cookieName string) http.Handler
- func ThemeCtx(tv *ThemeValues) func(http.Handler) http.Handler
- type Executor
- type Site
- func (s *Site) Executor() Executor
- func (s *Site) Reload() error
- func (s *Site) ResolveThemeName(name radio.ThemeName) radio.ThemeName
- func (s *Site) Template(theme radio.ThemeName, page string) (*template.Template, error)
- func (s *Site) Theme(name radio.ThemeName) ThemeBundle
- func (s *Site) ThemeNames() []radio.ThemeName
- func (s *Site) ThemeNamesAdmin() []radio.ThemeName
- func (s *Site) Themes() []radio.Theme
- func (s *Site) ThemesAdmin() []radio.Theme
- type TemplateBundle
- type TemplateSelectable
- type TemplateSelector
- type ThemeBundle
- type ThemeValues
- type Themes
Constants ¶
const ( // the extension used for template files TEMPLATE_EXT = ".tmpl" // the filename to be used for extra theme information INFORMATION_FILE = "info.toml" // 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 ThemeAdminDefault = "admin-dark"
const ThemeCookieName = "theme"
const ThemeDefault = "default-dark"
Variables ¶
This section is empty.
Functions ¶
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 IsAdminTheme ¶
func SetTheme ¶
SetTheme sets a theme in the context given, does nothing if a theme already exists unless override is set to true
func SetThemeHandler ¶
func ThemeCtx ¶
func ThemeCtx(tv *ThemeValues) func(http.Handler) http.Handler
ThemeCtx adds a theme entry into the context of the request, that is acquirable by calling GetTheme on the request context.
What theme to insert is a priority system that looks like this:
- user-picked (if holiday-theme is set and overwrite-holiday enabled)
- holiday-theme
- user-picked (if dj-theme is set and overwrite-dj enabled)
- dj-theme
- user-picked
- default-theme
Types ¶
type Executor ¶
type Executor interface { Execute(w io.Writer, r *http.Request, input TemplateSelectable) error ExecuteTemplate(ctx context.Context, theme radio.ThemeName, page, template string, output io.Writer, input any) error ExecuteAll(input TemplateSelectable) (map[radio.ThemeName][]byte, error) ExecuteAllAdmin(input TemplateSelectable) (map[radio.ThemeName][]byte, error) }
type Site ¶
type Site struct { // Production indicates if we should reload every page load Production bool // contains filtered or unexported fields }
Site is an overarching struct containing all the themes of the website.
func FromDirectory ¶
func FromDirectory(dir string, state *functions.StatefulFuncs) (*Site, error)
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) ThemeNames ¶
func (*Site) ThemeNamesAdmin ¶
func (*Site) ThemesAdmin ¶
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 ¶
ThemeBundle contains the pages that construct a specific theme as a set of TemplateBundle's
func (ThemeBundle) Assets ¶
func (tb ThemeBundle) Assets() fs.FS
func (ThemeBundle) Page ¶
func (tb ThemeBundle) Page(name string) (*TemplateBundle, error)
Page returns the TemplateBundle associated with the page name given
type ThemeValues ¶
type ThemeValues struct {
// contains filtered or unexported fields
}
func NewThemeValues ¶
func NewThemeValues(resolver func(radio.ThemeName) radio.ThemeName) *ThemeValues
func (*ThemeValues) LoadHoliday ¶
func (tv *ThemeValues) LoadHoliday() radio.ThemeName
func (*ThemeValues) StoreDJ ¶
func (tv *ThemeValues) StoreDJ(theme radio.ThemeName)
func (*ThemeValues) StoreHoliday ¶
func (tv *ThemeValues) StoreHoliday(theme radio.ThemeName)