Documentation
¶
Index ¶
- func HandleReload(e fsnotify.Event, err error)
- func HandleReloadError(e fsnotify.Event, err error)
- func LoadTemplates() error
- func NewBaseTemplate[T any](baseData T) *core.BaseTemplates[T]
- func NewHeaders() handlers.HeaderSetter
- func NewTemplate[T, U any](br *core.BaseTemplates[T], pattern string, data U) *core.Templ[T, U]
- func RunLiveReload(handlePattern string, handleReload func(fsnotify.Event, error), ...) (http.HandlerFunc, context.CancelFunc, error)
- type BaseConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HandleReload ¶ added in v0.3.0
A basic helper function for LiveReload to perform logging when a reload occurs
func HandleReloadError ¶ added in v0.3.0
A basic helper function for LiveReload to perform logging if a reload error occurs
func LoadTemplates ¶ added in v0.3.0
func LoadTemplates() error
Loads and validates all the created templates. It is expected to be called after all the templates and settings have been created
func NewBaseTemplate ¶ added in v0.3.0
func NewBaseTemplate[T any](baseData T) *core.BaseTemplates[T]
Creates a new base template with the provided baseData.
All NewTemplate calls will use BaseTemplates as their starting point.
The baseData is used to define the data type passed in to the template for the base data for all child templates.
func NewHeaders ¶ added in v0.3.0
func NewHeaders() handlers.HeaderSetter
Shorthand to make it easier to create middleware to set headers and does not depend on loadr.LoadTemplates()
Use Set(key, value), to append key values to the header ResponseWriter followed by Middleware() to return a handler middleware
func NewTemplate ¶ added in v0.3.0
Lazily prepares the templates for loading by pattern both file names as well as the template names can be provided. If no template name is provided, the template name will be the first name of the SetTemplates() pattern
The expected data structure should also be provided as it is used for the loading and validation when loadr.LoadTemplates() is called.
No templates get parsed until loadr.Validate() is run
func RunLiveReload ¶ added in v0.3.0
func RunLiveReload(handlePattern string, handleReload func(fsnotify.Event, error), pathsToWatch ...string) (http.HandlerFunc, context.CancelFunc, error)
Watches the specified local pathsToWatch for file changes and notifies connected clients and handleChange if provided.
Live reload can only be started once.
The handlePattern is the URL path that the live server will handle and must match the registered pattern in the HTTP server. If no handlePatern is provided, the live server will serve on /live-server
Types ¶
type BaseConfig ¶ added in v0.3.0
type BaseConfig = core.BaseConfig
Used to set the configuration for the base templates