Documentation
¶
Index ¶
- Variables
- type Config
- type Data
- type GlobalData
- type InMemoryFS
- type InMemoryFile
- type InMemoryFileInfo
- type Layout
- func (l *Layout) AddData(key string, value any) *Layout
- func (l *Layout) FS(fs fs.FS) *Layout
- func (l *Layout) MergeFuncMap(funcMap template.FuncMap)
- func (l *Layout) RenderWithRequest(ctx context.Context, r *http.Request) (template.HTML, error)
- func (l *Layout) Set(p *Partial) *Layout
- func (l *Layout) SetData(data map[string]any) *Layout
- func (l *Layout) Wrap(p *Partial) *Layout
- func (l *Layout) WriteWithRequest(ctx context.Context, w http.ResponseWriter, r *http.Request) error
- type Logger
- type Node
- type Partial
- func (p *Partial) AddData(key string, value any) *Partial
- func (p *Partial) AddFunc(name string, fn interface{}) *Partial
- func (p *Partial) AddTemplate(template string) *Partial
- func (p *Partial) GetRequest() *http.Request
- func (p *Partial) GetRequestedAction() string
- func (p *Partial) GetRequestedPartial() string
- func (p *Partial) GetRequestedSelect() string
- func (p *Partial) GetResponseHeaders() map[string]string
- func (p *Partial) ID(id string) *Partial
- func (p *Partial) MergeData(data map[string]any, override bool) *Partial
- func (p *Partial) MergeFuncMap(funcMap template.FuncMap)
- func (p *Partial) Render(ctx context.Context) (template.HTML, error)
- func (p *Partial) RenderWithRequest(ctx context.Context, r *http.Request) (template.HTML, error)
- func (p *Partial) Reset() *Partial
- func (p *Partial) SetConnector(connector connector.Connector) *Partial
- func (p *Partial) SetData(data map[string]any) *Partial
- func (p *Partial) SetFileSystem(fs fs.FS) *Partial
- func (p *Partial) SetGlobalData(data map[string]any) *Partial
- func (p *Partial) SetLayoutData(data map[string]any) *Partial
- func (p *Partial) SetLogger(logger Logger) *Partial
- func (p *Partial) SetParent(parent *Partial) *Partial
- func (p *Partial) SetResponseHeaders(headers map[string]string) *Partial
- func (p *Partial) Templates(templates ...string) *Partial
- func (p *Partial) UseCache(useCache bool) *Partial
- func (p *Partial) With(child *Partial) *Partial
- func (p *Partial) WithAction(action func(ctx context.Context, p *Partial, data *Data) (*Partial, error)) *Partial
- func (p *Partial) WithOOB(child *Partial) *Partial
- func (p *Partial) WithSelectMap(defaultKey string, partialsMap map[string]*Partial) *Partial
- func (p *Partial) WithTemplateAction(...) *Partial
- func (p *Partial) WriteWithRequest(ctx context.Context, w http.ResponseWriter, r *http.Request) error
- type Selection
- type Service
Constants ¶
This section is empty.
Variables ¶
var DefaultTemplateFuncMap = template.FuncMap{ "safeHTML": safeHTML, "upper": strings.ToUpper, "lower": strings.ToLower, "trimSpace": strings.TrimSpace, "trim": strings.Trim, "trimSuffix": strings.TrimSuffix, "trimPrefix": strings.TrimPrefix, "contains": strings.Contains, "containsAny": strings.ContainsAny, "hasPrefix": strings.HasPrefix, "hasSuffix": strings.HasSuffix, "repeat": strings.Repeat, "replace": strings.Replace, "split": strings.Split, "join": strings.Join, "stringSlice": stringSlice, "title": title, "substr": substr, "ucfirst": ucfirst, "compare": strings.Compare, "equalFold": strings.EqualFold, "urlencode": url.QueryEscape, "urldecode": url.QueryUnescape, "now": time.Now, "formatDate": formatDate, "parseDate": parseDate, "first": first, "last": last, "hasKey": hasKey, "keys": keys, "debug": debug, }
Functions ¶
This section is empty.
Types ¶
type Data ¶
type Data struct {
// Ctx is the context of the request
Ctx context.Context
// URL is the URL of the request
URL *url.URL
// Request contains the http.Request
Request *http.Request
// Data contains the data specific to this partial
Data map[string]any
// Service contains global data available to all partials
Service map[string]any
// LayoutData contains data specific to the service
Layout map[string]any
}
Data represents the data available to the partial.
type GlobalData ¶
GlobalData represents the global data available to all partials.
type InMemoryFS ¶
func (*InMemoryFS) AddFile ¶
func (f *InMemoryFS) AddFile(name, content string)
type InMemoryFile ¶
func (*InMemoryFile) Close ¶
func (f *InMemoryFile) Close() error
type InMemoryFileInfo ¶
type InMemoryFileInfo struct {
// contains filtered or unexported fields
}
func (*InMemoryFileInfo) IsDir ¶
func (fi *InMemoryFileInfo) IsDir() bool
func (*InMemoryFileInfo) ModTime ¶
func (fi *InMemoryFileInfo) ModTime() time.Time
func (*InMemoryFileInfo) Mode ¶
func (fi *InMemoryFileInfo) Mode() fs.FileMode
func (*InMemoryFileInfo) Name ¶
func (fi *InMemoryFileInfo) Name() string
func (*InMemoryFileInfo) Size ¶
func (fi *InMemoryFileInfo) Size() int64
func (*InMemoryFileInfo) Sys ¶
func (fi *InMemoryFileInfo) Sys() interface{}
type Layout ¶ added in v0.2.0
type Layout struct {
// contains filtered or unexported fields
}
func (*Layout) MergeFuncMap ¶ added in v0.2.0
MergeFuncMap merges the given FuncMap with the existing FuncMap in the Layout.
func (*Layout) RenderWithRequest ¶ added in v0.2.0
RenderWithRequest renders the partial with the given http.Request.
func (*Layout) WriteWithRequest ¶ added in v0.2.0
func (l *Layout) WriteWithRequest(ctx context.Context, w http.ResponseWriter, r *http.Request) error
WriteWithRequest writes the layout to the response writer.
type Partial ¶
type Partial struct {
// contains filtered or unexported fields
}
Partial represents a renderable component with optional children and data.
func (*Partial) AddTemplate ¶
AddTemplate adds a template to the partial.
func (*Partial) GetRequest ¶ added in v0.8.0
func (*Partial) GetRequestedAction ¶ added in v0.5.0
func (*Partial) GetRequestedPartial ¶ added in v0.8.0
func (*Partial) GetRequestedSelect ¶ added in v0.8.0
func (*Partial) GetResponseHeaders ¶ added in v0.8.0
func (*Partial) MergeFuncMap ¶ added in v0.2.0
MergeFuncMap merges the given FuncMap with the existing FuncMap in the Partial.
func (*Partial) Render ¶ added in v0.2.0
Render renders the partial without requiring an http.Request. It can be used when you don't need access to the request data.
func (*Partial) RenderWithRequest ¶
RenderWithRequest renders the partial with the given http.Request.
func (*Partial) SetConnector ¶ added in v0.8.0
SetConnector sets the connector for the partial.
func (*Partial) SetFileSystem ¶ added in v0.2.0
SetFileSystem sets the file system for the partial.
func (*Partial) SetGlobalData ¶
SetGlobalData sets the global data for the partial.
func (*Partial) SetLayoutData ¶ added in v0.2.0
SetLayoutData sets the layout data for the partial.
func (*Partial) SetResponseHeaders ¶ added in v0.8.0
func (*Partial) WithAction ¶ added in v0.4.0
func (p *Partial) WithAction(action func(ctx context.Context, p *Partial, data *Data) (*Partial, error)) *Partial
WithAction adds callback action to the partial, which can do some logic and return a partial to render.
func (*Partial) WithSelectMap ¶ added in v0.4.0
WithSelectMap adds a selection partial to the partial.
func (*Partial) WithTemplateAction ¶ added in v0.4.0
func (*Partial) WriteWithRequest ¶ added in v0.2.0
func (p *Partial) WriteWithRequest(ctx context.Context, w http.ResponseWriter, r *http.Request) error
WriteWithRequest writes the partial to the http.ResponseWriter.
type Service ¶ added in v0.2.0
type Service struct {
// contains filtered or unexported fields
}
func NewService ¶ added in v0.2.0
NewService returns a new partial service.
func (*Service) MergeFuncMap ¶ added in v0.2.0
MergeFuncMap merges the given FuncMap with the existing FuncMap.