Documentation ¶
Index ¶
- type FSTemplateHandler
- func (s FSTemplateHandler) Parse() FSTemplateHandler
- func (s FSTemplateHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (s FSTemplateHandler) WithDebug() FSTemplateHandler
- func (s FSTemplateHandler) WithFuncs(funcs template.FuncMap) FSTemplateHandler
- func (s FSTemplateHandler) WithLog(log *slog.Logger) FSTemplateHandler
- func (s FSTemplateHandler) WithModelGetter(getter TemplateModelGetter) FSTemplateHandler
- func (s FSTemplateHandler) WithModelMap(modelMap map[string]any) FSTemplateHandler
- type TemplateModelGetter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FSTemplateHandler ¶ added in v0.0.18
type FSTemplateHandler struct { fs.FS // Embedding file system interface to access templates. Patterns []string // Selecting templates within the FS. FuncMap template.FuncMap // Custom template functions. GetModel TemplateModelGetter // Function to get the model for a given template. Root *template.Template // Root template object. DebugMode bool // Flag to indicate debug mode. Log *slog.Logger // Logger instance. // contains filtered or unexported fields }
FSTemplateHandler is a struct that handles template rendering from a file system.
func NewFSTemplateHandler ¶ added in v0.0.18
func NewFSTemplateHandler(fs fs.FS, patterns ...string) FSTemplateHandler
NewFSTemplateHandler creates a new instance of FSTemplateHandler with the provided file system and file patterns.
func (FSTemplateHandler) Parse ¶ added in v0.0.18
func (s FSTemplateHandler) Parse() FSTemplateHandler
Parse parses the templates from the file system.
func (FSTemplateHandler) ServeHTTP ¶ added in v0.0.18
func (s FSTemplateHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP handles HTTP requests and renders templates.
func (FSTemplateHandler) WithDebug ¶ added in v0.0.18
func (s FSTemplateHandler) WithDebug() FSTemplateHandler
WithDebug enables debug mode.
func (FSTemplateHandler) WithFuncs ¶ added in v0.0.18
func (s FSTemplateHandler) WithFuncs(funcs template.FuncMap) FSTemplateHandler
WithFuncs sets custom functions to be used in templates.
func (FSTemplateHandler) WithLog ¶ added in v0.0.18
func (s FSTemplateHandler) WithLog(log *slog.Logger) FSTemplateHandler
WithLog sets the logger for the handler.
func (FSTemplateHandler) WithModelGetter ¶ added in v0.0.18
func (s FSTemplateHandler) WithModelGetter(getter TemplateModelGetter) FSTemplateHandler
WithModelGetter sets the function to retrieve models for templates.
func (FSTemplateHandler) WithModelMap ¶ added in v0.0.18
func (s FSTemplateHandler) WithModelMap(modelMap map[string]any) FSTemplateHandler
WithModelMap sets a map of models for templates.
type TemplateModelGetter ¶ added in v0.0.18
TemplateModelGetter is a function type that takes a template name and returns a model (data) for that template.