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 HasField(v any, name string) bool
- func HumanDuration(d time.Duration) string
- func IsImageThread(v string) bool
- func IsValidThread(v string) bool
- func MediaDuration(d time.Duration) string
- func PrettyDuration(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 SafeURL(v any) (template.URL, 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
- func (s *Site) Executor() Executor
- func (s *Site) Reload() error
- func (s *Site) ResolveThemeName(name string) string
- func (s *Site) Template(theme, page string) (*template.Template, error)
- func (s *Site) Theme(name string) ThemeBundle
- func (s *Site) ThemeNames() []string
- func (s *Site) ThemeNamesAdmin() []string
- type SongPairing
- type StatefulFuncs
- 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 ThemeAdminDefault = "admin-dark"
const ThemeCookieName = "theme"
const ThemeDefault = "default-dark"
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 IsImageThread ¶
IsImageThread tells you if the thread is an image thread
func IsValidThread ¶
IsValidThread tells you if a thread is valid, that is not-empty or is the literal 'none'
func MediaDuration ¶
func PrettyDuration ¶
func SetThemeHandler ¶
func TemplateFuncs ¶
func TimeagoDuration ¶
Types ¶
type Executor ¶
type Executor interface { Execute(w io.Writer, r *http.Request, input TemplateSelectable) error ExecuteTemplate(ctx context.Context, theme, page, template string, output io.Writer, input any) error ExecuteAll(input TemplateSelectable) (map[string][]byte, error) ExecuteAllAdmin(input TemplateSelectable) (map[string][]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 *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) Theme ¶
func (s *Site) Theme(name string) ThemeBundle
func (*Site) ThemeNames ¶
func (*Site) ThemeNamesAdmin ¶
type SongPairing ¶
type StatefulFuncs ¶
type StatefulFuncs struct {
// contains filtered or unexported fields
}
func NewStatefulFunctions ¶
func NewStatefulFunctions(status *util.Value[radio.Status]) *StatefulFuncs
func (*StatefulFuncs) FuncMap ¶
func (sf *StatefulFuncs) FuncMap() template.FuncMap
func (*StatefulFuncs) Status ¶
func (sf *StatefulFuncs) Status() radio.Status
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)