templating

package
v0.0.0-...-b197db6 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2024 License: AGPL-3.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

type FlagFunc func(flags Flags, r *http.Request) Flags

FlagFunc updates a flags based on a request. FlagFunc may not be nil.

func Actions

func Actions(actions ...component.MenuItem) FlagFunc

Actions sets the actions

func Assets

func Assets(Assets assets.Assets) FlagFunc

Assets sets the given assets for the given flags

func Crumbs

func Crumbs(crumbs ...component.MenuItem) FlagFunc

Crumbs sets the crumbs

func ReplaceAction

func ReplaceAction(old component.MenuItem, action component.MenuItem) FlagFunc

ReplaceAction replaces a specific action

func ReplaceCrumb

func ReplaceCrumb(old component.MenuItem, crumb component.MenuItem) FlagFunc

ReplaceCrumb replaces a specific crum

func ReplaceTab

func ReplaceTab(old component.MenuItem, tab component.MenuItem) FlagFunc

ReplaceTab replaces a specific tab

func Tabs

func Tabs(actions ...component.MenuItem) FlagFunc

Tabs sets the tabs

func Title

func Title(title string) FlagFunc

Title sets the title of this template

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

func (Flags) Apply

func (flags Flags) Apply(r *http.Request, funcs ...FlagFunc) Flags

Apply applies a set of functions to this flags

func (Flags) Clone

func (flags Flags) Clone() Flags

Clone clones this flags

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.

func Parse

func Parse[C any](name string, source []byte, base *template.Template, funcs ...FlagFunc) Parsed[C]

Parse parses a template with the given name and source. If base is not nil, every template associated with the base template is copied into the given template. Functions will be applied on creation time to represent the context for the given template.

func (*Parsed[C]) Prepare

func (p *Parsed[C]) Prepare(templating *Templating, funcs ...FlagFunc) *Template[C]

Prepare prepares this template to be used with the given templating.

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

func (tpl *Template[C]) Context(r *http.Request, c C, funcs ...FlagFunc) (ctx *tContext[C])

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

func (*Template[C]) LogTemplateError(r *http.Request, err error)

LogTepmplateError logs a non-nil error into the logger found in the request

func (*Template[C]) Template

func (tpl *Template[C]) Template() *template.Template

Template returns a template that, if executed together with the context by the Context method, produces the desired result.

type Templating

type Templating struct {
	component.Base
	// contains filtered or unexported fields
}

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.

func (*Templating) Menu

func (tpl *Templating) Menu(r *http.Request) []component.MenuItem

Menu returns a list of menu items provided by routeables

Jump to

Keyboard shortcuts

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