Documentation
¶
Overview ¶
Package debug provides an optional renderer for debug output.
Index ¶
Constants ¶
const RenderKindDebug partial.RenderKind = "debug"
RenderKindDebug is the renderer kind used for debug fragments.
Variables ¶
This section is empty.
Functions ¶
func Debug ¶
Debug renders a diagnostic value through the active render stage chain.
go-doc:sig func(runtime *github.com/donseba/go-partial.Runtime, value any) html/template.HTML
In a text render (partial.RenderText), such as the subject of an e-mail, it writes the value as plain text, without the HTML box.
func Disabled ¶ added in v0.15.0
Disabled returns a debug helper that renders nothing, for production: templates that call {{ debug . }} or {{ debug runtime . }} keep working and show nothing.
if development {
root.Use(debug.Stage(debug.WithFunc()))
} else {
root.SetFunc(debug.Disabled())
}
func FormatValue ¶
FormatValue formats a debug value for display.
func Stage ¶
func Stage(options ...Option) partial.RenderStage
Stage returns a render stage that handles debug render contexts. With WithFunc, it also gives templates the debug helper.
func StyleHash ¶ added in v0.15.0
func StyleHash() string
StyleHash returns the Content-Security-Policy hash source of the inline <style> element of the debug box, 'sha256-…' with its quotes, for the style-src directive of a policy without 'unsafe-inline', in development, where the debug stage is used:
style-src 'self' 'sha256-…'
Without it, such a policy blocks the box's style and the box shows its value unstyled, in a <pre>. The hash changes only when go-partial changes the box's style.
Types ¶
type Data ¶
type Data struct {
Value any
Output string
PartialID string
Templates []string
Request *http.Request
URL *url.URL
}
Data is the template data used by the debug renderer.
func BuildData ¶
func BuildData(ctx *partial.RenderContext) Data
BuildData converts a render context into debug template data.
type FuncOption ¶ added in v0.15.0
type FuncOption func(*config)
FuncOption configures the debug helper of WithFunc.
func UnlessDefined ¶ added in v0.15.0
func UnlessDefined() FuncOption
UnlessDefined makes WithFunc give templates the debug helper only where the application registered no debug function of its own with SetFunc, which is then called instead, without a warning; Disabled, of this package, does not count as one, so a root can register it for production and use the stage in development:
root.SetFunc(debug.Disabled()).SetFunc(siteFuncs)
if development {
root.Use(debug.Stage(debug.WithFunc(debug.UnlessDefined())))
}
type Option ¶ added in v0.15.0
type Option func(*config)
Option configures the debug stage.
func WithFunc ¶ added in v0.15.0
func WithFunc(opts ...FuncOption) Option
WithFunc makes the stage give templates the debug helper bound to the render, so they call {{ debug . }} without the runtime; {{ debug runtime . }} keeps working. Templates need no FuncMap for it. A debug function the application registers itself is then never called, unless the option UnlessDefined is given.