Documentation
¶
Overview ¶
Package mtr is the monet template registry. 請勿靠近車門. Please stand back from the doors.
Index ¶
- func AddRegistryMiddleware(reg *Registry) func(http.Handler) http.Handler
- func NewSproutRegistry(uid string, fns sprout.FunctionMap) sprout.Registry
- func RenderMarkdown(source string) string
- type Ctx
- type LinkFn
- type Page
- type Paginator
- type Registry
- func (r *Registry) AddAllFS(f fs.FS)
- func (r *Registry) AddBaseFS(name, path string, fs fs.FS)
- func (r *Registry) AddFS(name, path string, fs fs.FS)
- func (r *Registry) AddPathFS(path string, fs fs.FS)
- func (r *Registry) Build() error
- func (r *Registry) Context(ctx context.Context) context.Context
- func (r *Registry) Render(w io.Writer, name string, ctx Ctx) error
- func (r *Registry) RenderWithBase(w io.Writer, base, name string, ctx Ctx) error
- type SproutReg
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddRegistryMiddleware ¶
AddRegistryMiddleware adds reg to the request context
func NewSproutRegistry ¶
func NewSproutRegistry(uid string, fns sprout.FunctionMap) sprout.Registry
func RenderMarkdown ¶
Types ¶
type LinkFn ¶
func SlashLinkFn ¶
SlashLinkFn returns a LinkFn that adds a number element to a base path, eg. SlashLinkFn("/blog/page") returns a LinkFn that generates urls like "/blog/page/3".
type Paginator ¶
type Paginator struct {
// PageSize is the number of elements per page
PageSize int
// Total is the total number of elements
Total int
// NumPages is the number of total pages
NumPages int
// WindowSize is the maximum number of pages to render at once
// If there are more than WindowSize pages, then some pages will
// be omitted during rendering and elipsized, eg:
// <- 1 2 3 ... 14 15 16 ->
WindowSize int
// Ellipsis is inserted between the start and end if the number of
// pages is more than the Windowsize
Ellipsis string
// contains filtered or unexported fields
}
A Paginator assists in pagination by providing HTML rendering for pagination as well as windowing for fetching the correct items.
func NewPaginator ¶
func (*Paginator) WithLinkFn ¶
WithLinkFn sets the paginator's url generating function to fn
type Registry ¶
type Registry struct {
// Handler is a sprout handler.
Handler sprout.Handler
// DefaultCtx is a default template context that can be populated with values
// that should be available to all templates, such as configuration/version
// information.
DefaultCtx Ctx
// contains filtered or unexported fields
}
A Registry manages a set of templates from various apps, providing a way for them to share features with each other.
Create an empty registry with NewRegistry, and then use the Add/AddBase* functions to add named templates to the registry. Once all of the templates have been added, call Registry.Build(), which builds the function map and parses all of the templates.
You can render templates directly with Render, or render them within the context of a base template with RenderWithBase.
func RegistryFromContext ¶
RegistryFromContext returns the registry from the ctx. It should have been added with Registry.Context(ctx).
func (*Registry) Build ¶
Build the registry templates. Caller should not add more templates after Build is called.
func (*Registry) RenderWithBase ¶
RenderWithBase renders the template 'name' with the base template 'base' to the writer, using the provided context. The base template template will receive the child template's content as 'body', which it should incorporate into its structure.
type SproutReg ¶
type SproutReg struct {
// contains filtered or unexported fields
}
func (*SproutReg) RegisterAliases ¶
func (s *SproutReg) RegisterAliases(am sprout.FunctionAliasMap) error
func (*SproutReg) RegisterFunctions ¶
func (s *SproutReg) RegisterFunctions(fm sprout.FunctionMap) error