Documentation ¶
Index ¶
- Variables
- func FormTemplateContext(tw *Template[FormContext]) func(ctx form.FormContext, r *http.Request) any
- type FlagFunc
- func Actions(actions ...component.MenuItem) FlagFunc
- func Assets(Assets assets.Assets) FlagFunc
- func Crumbs(crumbs ...component.MenuItem) FlagFunc
- func ReplaceAction(old component.MenuItem, action component.MenuItem) FlagFunc
- func ReplaceCrumb(old component.MenuItem, crumb component.MenuItem) FlagFunc
- func ReplaceTab(old component.MenuItem, tab component.MenuItem) FlagFunc
- func Tabs(actions ...component.MenuItem) FlagFunc
- func Title(title string) FlagFunc
- type Flags
- type FormContext
- type Parsed
- type RuntimeFlags
- type Template
- func (tpl *Template[C]) Context(r *http.Request, c C, funcs ...FlagFunc) (ctx *tContext[C])
- func (tw *Template[C]) HTMLHandler(handling *handling.Handling, worker func(r *http.Request) (C, error)) content.HTMLHandler[any]
- func (tw *Template[C]) HTMLHandlerWithFlags(handling *handling.Handling, ...) content.HTMLHandler[any]
- func (tw *Template[C]) Handler(f func(r *http.Request) (C, error)) func(r *http.Request) (any, error)
- func (tw *Template[C]) HandlerWithFlags(worker func(r *http.Request) (C, []FlagFunc, error)) func(r *http.Request) (any, error)
- func (*Template[C]) LogTemplateError(r *http.Request, err error)
- func (tpl *Template[C]) Template() *template.Template
- type Templating
- func (tpl *Templating) Backup(context *component.StagingContext) error
- func (tpl *Templating) BackupName() string
- func (tpl *Templating) CustomAssetPath(name string) string
- func (tpl *Templating) CustomAssetsPath() string
- func (tpl *Templating) GetCustomizable(dflt *template.Template) *template.Template
- func (tpl *Templating) Menu(r *http.Request) []component.MenuItem
Constants ¶
This section is empty.
Variables ¶
var ParseForm = Parse[FormContext]
ParseForm is like Parse[BaseFormContext]
Functions ¶
func FormTemplateContext ¶
func FormTemplateContext(tw *Template[FormContext]) func(ctx form.FormContext, r *http.Request) any
FormTemplateContext returns a new handler for a form with the given base context
Types ¶
type FlagFunc ¶
FlagFunc updates a flags based on a request. FlagFunc may not be nil.
func ReplaceAction ¶
ReplaceAction replaces a specific action
func ReplaceCrumb ¶
ReplaceCrumb replaces a specific crum
func ReplaceTab ¶
ReplaceTab replaces a specific tab
type Flags ¶
type Flags struct { Title string // Title of the menu assets.Assets // assets are the assets included in the template Crumbs []component.MenuItem // crumbs are the breadcrumbs leading to a specific action Tabs []component.MenuItem // tabs are shown above actions, and act as a menu Actions []component.MenuItem // actions are the actions available to a specific thingy }
Flags represent handle-updatable options for the base template
type FormContext ¶
type FormContext struct { form.FormContext RuntimeFlags }
func NewFormContext ¶
func NewFormContext(context form.FormContext) FormContext
NewFormContext returns a new FormContext from an underlying context
type Parsed ¶
type Parsed[C any] struct { // contains filtered or unexported fields }
Parsed represents a parsed template that takes as argument a context of type C.
type RuntimeFlags ¶
type RuntimeFlags struct { Flags RequestURI string // request uri of the current page Menu []component.MenuItem // menu at the top of the page StartedAt time.Time // time the request started to generate GeneratedAt time.Time // time the underlying data returned CSRF template.HTML // csrf data (if any) }
RuntimeFlags are passed to the template at runtime.
func (RuntimeFlags) Took ¶
func (rf RuntimeFlags) Took() time.Duration
Returns how long this request took to render
func (RuntimeFlags) TookHTML ¶
func (rf RuntimeFlags) TookHTML() template.HTML
type Template ¶
type Template[C any] struct { // contains filtered or unexported fields }
Tempalte represents an executable template.
func (*Template[C]) Context ¶
Context generates the context to pass to an instance of the template returned by Template.
func (*Template[C]) HTMLHandler ¶
func (tw *Template[C]) HTMLHandler(handling *handling.Handling, worker func(r *http.Request) (C, error)) content.HTMLHandler[any]
HTMLHandler creates a new httpx.HTMLHandler that calls tw.Handler(worker) and tw.Template. See also Handler.
func (*Template[C]) HTMLHandlerWithFlags ¶
func (tw *Template[C]) HTMLHandlerWithFlags(handling *handling.Handling, worker func(r *http.Request) (C, []FlagFunc, error)) content.HTMLHandler[any]
HTMLHandlerWithFlags creates a new httpx.HTMLHandler that calls tw.HandlerWithFlags(worker) and tw.Template. See also HandlerWithFlags.
func (*Template[C]) Handler ¶
func (tw *Template[C]) Handler(f func(r *http.Request) (C, error)) func(r *http.Request) (any, error)
HandlerWithFlags returns a function that, given a request, generates context and error to pass to the generated template. The worker implements the actual buisness logic, it takes a request, and returns the content for the main template, and any error. See also HandlerWithFlags.
func (*Template[C]) HandlerWithFlags ¶
func (tw *Template[C]) HandlerWithFlags(worker func(r *http.Request) (C, []FlagFunc, error)) func(r *http.Request) (any, error)
HandlerWithFlags returns a function that, given a request, generates context and error to pass to the generated template. The worker implements the actual buisness logic, it takes a request, and returns the content for the main template, flag functions and error. See also Handler.
func (*Template[C]) LogTemplateError ¶
LogTepmplateError logs a non-nil error into the logger found in the request
type Templating ¶
Templating implements templating customization
func (*Templating) Backup ¶
func (tpl *Templating) Backup(context *component.StagingContext) error
func (*Templating) BackupName ¶
func (tpl *Templating) BackupName() string
func (*Templating) CustomAssetPath ¶
func (tpl *Templating) CustomAssetPath(name string) string
func (*Templating) CustomAssetsPath ¶
func (tpl *Templating) CustomAssetsPath() string
CustomAssetsPath is the path custom assets are stored at
func (*Templating) GetCustomizable ¶
func (tpl *Templating) GetCustomizable(dflt *template.Template) *template.Template
GetCustomizable returns either a clone of dflt, or the overriden template with the same name.