Documentation ¶
Index ¶
- Constants
- Variables
- func Bool(value bool) bool
- func CSSID(name string, css string) string
- func ClearChildren(ctx context.Context) context.Context
- func EscapeString(s string) string
- func GetBuffer() *bytes.Buffer
- func InitializeContext(ctx context.Context) context.Context
- func JoinStringErrs(s string, errs ...error) (string, error)
- func ReleaseBuffer(b *bytes.Buffer)
- func RenderAttributes(ctx context.Context, w io.Writer, attributes Attributes) (err error)
- func RenderCSSItems(ctx context.Context, w io.Writer, classes ...any) (err error)
- func RenderScriptItems(ctx context.Context, w io.Writer, scripts ...ComponentScript) (err error)
- func SafeScript(functionName string, params ...any) string
- func SafeScriptInline(functionName string, params ...any) string
- func ToGoHTML(ctx context.Context, c Component) (s template.HTML, err error)
- func Version() string
- func WithChildren(ctx context.Context, children Component) context.Context
- func WithContentType(contentType string) func(*ComponentHandler)
- func WithErrorHandler(eh func(r *http.Request, err error) http.Handler) func(*ComponentHandler)
- func WithStatus(status int) func(*ComponentHandler)
- func WriteWatchModeString(w *bytes.Buffer, lineNum int) error
- type Attributes
- type CSSClass
- type CSSClasses
- type CSSHandler
- type CSSMiddleware
- type Component
- type ComponentCSSClass
- type ComponentFunc
- type ComponentHandler
- type ComponentScript
- type ConstantCSSClass
- type Error
- type KeyValue
- type SafeCSS
- type SafeURL
Constants ¶
const FailedSanitizationURL = SafeURL("about:invalid#TemplFailedSanitizationURL")
FailedSanitizationURL is returned if a URL fails sanitization checks.
Variables ¶
var NopComponent = ComponentFunc(func(ctx context.Context, w io.Writer) error { return nil })
NopComponent is a component that doesn't render anything.
Functions ¶
func EscapeString ¶
EscapeString escapes HTML text within templates.
func InitializeContext ¶ added in v0.2.184
InitializeContext initializes context used to store internal state used during rendering.
func JoinStringErrs ¶ added in v0.2.501
JoinStringErrs joins an optional list of errors.
func ReleaseBuffer ¶ added in v0.2.194
func RenderAttributes ¶ added in v0.2.501
func RenderCSSItems ¶ added in v0.2.184
RenderCSSItems renders the CSS to the writer, if the items haven't already been rendered.
func RenderScriptItems ¶ added in v0.2.184
RenderScriptItems renders a <script> element, if the script has not already been rendered.
func SafeScript ¶ added in v0.0.139
SafeScript encodes unknown parameters for safety for inside HTML attributes.
func SafeScriptInline ¶ added in v0.2.476
SafeScript encodes unknown parameters for safety for inline scripts.
func ToGoHTML ¶ added in v0.2.501
ToGoHTML renders the component to a Go html/template template.HTML string.
func WithChildren ¶ added in v0.2.184
func WithContentType ¶ added in v0.0.148
func WithContentType(contentType string) func(*ComponentHandler)
WithConentType sets the Content-Type header returned by the ComponentHandler.
func WithErrorHandler ¶ added in v0.0.139
WithErrorHandler sets the error handler used if rendering fails.
func WithStatus ¶ added in v0.0.139
func WithStatus(status int) func(*ComponentHandler)
WithStatus sets the HTTP status code returned by the ComponentHandler.
func WriteWatchModeString ¶ added in v0.2.542
WriteWatchModeString is used when rendering templates in development mode. the generator would have written non-go code to the _templ.txt file, which is then read by this function and written to the output.
Types ¶
type Attributes ¶ added in v0.2.501
Attributes is an alias to map[string]any made for spread attributes.
type CSSClass ¶ added in v0.0.113
type CSSClass interface {
ClassName() string
}
CSSClass provides a class name.
type CSSClasses ¶ added in v0.0.113
type CSSClasses []any
CSSClasses is a slice of CSS classes.
func Classes ¶ added in v0.0.113
func Classes(classes ...any) CSSClasses
Classes for CSS. Supported types are string, ConstantCSSClass, ComponentCSSClass, map[string]bool.
func (CSSClasses) String ¶ added in v0.0.113
func (classes CSSClasses) String() string
String returns the names of all CSS classes.
type CSSHandler ¶ added in v0.0.113
type CSSHandler struct { Logger func(err error) Classes []ComponentCSSClass }
CSSHandler is a HTTP handler that serves CSS.
func NewCSSHandler ¶ added in v0.0.113
func NewCSSHandler(classes ...CSSClass) CSSHandler
NewCSSHandler creates a handler that serves a stylesheet containing the CSS of the classes passed in. This is used by the CSSMiddleware to provide global stylesheets for templ components.
func (CSSHandler) ServeHTTP ¶ added in v0.0.113
func (cssh CSSHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
type CSSMiddleware ¶ added in v0.0.113
type CSSMiddleware struct { Path string CSSHandler CSSHandler Next http.Handler }
CSSMiddleware renders a global stylesheet.
func NewCSSMiddleware ¶ added in v0.0.113
func NewCSSMiddleware(next http.Handler, classes ...CSSClass) CSSMiddleware
NewCSSMiddleware creates HTTP middleware that renders a global stylesheet of ComponentCSSClass CSS if the request path matches, or updates the HTTP context to ensure that any handlers that use templ.Components skip rendering <style> elements for classes that are included in the global stylesheet. By default, the stylesheet path is /styles/templ.css
func (CSSMiddleware) ServeHTTP ¶ added in v0.0.113
func (cssm CSSMiddleware) ServeHTTP(w http.ResponseWriter, r *http.Request)
type Component ¶
Component is the interface that all templates implement.
func FromGoHTML ¶ added in v0.2.501
FromGoHTML creates a templ Component from a Go html/template template.
func GetChildren ¶ added in v0.2.184
GetChildren from the context.
type ComponentCSSClass ¶ added in v0.0.113
type ComponentCSSClass struct { // ID of the class, will be autogenerated. ID string // Definition of the CSS. Class SafeCSS }
ComponentCSSClass is a templ.CSS
func (ComponentCSSClass) ClassName ¶ added in v0.0.113
func (css ComponentCSSClass) ClassName() string
ClassName of the CSS class.
type ComponentFunc ¶
ComponentFunc converts a function that matches the Component interface's Render method into a Component.
type ComponentHandler ¶ added in v0.0.139
type ComponentHandler struct { Component Component Status int ContentType string ErrorHandler func(r *http.Request, err error) http.Handler }
ComponentHandler is a http.Handler that renders components.
func Handler ¶ added in v0.0.139
func Handler(c Component, options ...func(*ComponentHandler)) *ComponentHandler
Handler creates a http.Handler that renders the template.
func (ComponentHandler) ServeHTTP ¶ added in v0.0.139
func (ch ComponentHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP implements the http.Handler interface.
type ComponentScript ¶ added in v0.0.139
type ComponentScript struct { // Name of the script, e.g. print. Name string // Function to render. Function string // Call of the function in JavaScript syntax, including parameters, and // ensures parameters are HTML escaped; useful for injecting into HTML // attributes like onclick, onhover, etc. // // Given: // functionName("some string",12345) // It would render: // __templ_functionName_sha("some string",12345)) // // This is can be injected into HTML attributes: // <button onClick="__templ_functionName_sha("some string",12345))">Click Me</button> Call string // Call of the function in JavaScript syntax, including parameters. It // does not HTML escape parameters; useful for directly calling in script // elements. // // Given: // functionName("some string",12345) // It would render: // __templ_functionName_sha("some string",12345)) // // This is can be used to call the function inside a script tag: // <script>__templ_functionName_sha("some string",12345))</script> CallInline string }
ComponentScript is a templ Script template.
type ConstantCSSClass ¶ added in v0.0.113
type ConstantCSSClass string
ConstantCSSClass is a string constant of a CSS class name. Deprecated: use a string instead.
func (ConstantCSSClass) ClassName ¶ added in v0.0.113
func (css ConstantCSSClass) ClassName() string
ClassName of the CSS class.
type Error ¶ added in v0.2.501
type Error struct { Err error // FileName of the template file. FileName string // Line index of the error. Line int // Col index of the error. Col int }
Error returned during template rendering.
type KeyValue ¶ added in v0.2.282
type KeyValue[TKey comparable, TValue any] struct { Key TKey `json:"name"` Value TValue `json:"value"` }
KeyValue is a key and value pair.
func KV ¶ added in v0.2.282
func KV[TKey comparable, TValue any](key TKey, value TValue) KeyValue[TKey, TValue]
KV creates a new key/value pair from the input key and value.
type SafeCSS ¶ added in v0.0.113
type SafeCSS string
SafeCSS is CSS that has been sanitized.
func SanitizeCSS ¶ added in v0.0.113
SanitizeCSS sanitizes CSS properties to ensure that they are safe.
Directories ¶
Path | Synopsis |
---|---|
benchmarks
|
|
cmd
|
|
examples
|
|
counter
Module
|
|
counter-basic
Module
|
|
external-libraries
Module
|
|
integration-chi
Module
|
|
integration-echo
Module
|
|
integration-gin
Module
|
|
integration-go-echarts
Module
|
|
integration-gofiber
Module
|
|
integration-react
Module
|
|
internationalization
Module
|
|
static-generator
Module
|
|
typescript
Module
|
|
parser
|
|
testdependents
module
|
|