Documentation ¶
Index ¶
- Constants
- func CSSID(name string, css string) string
- func EscapeString(s string) string
- func RenderCSS(ctx context.Context, w io.Writer, classes []CSSClass) (err error)
- type Attribute
- type CSSClass
- type CSSClasses
- type CSSHandler
- type CSSMiddleware
- type CSSProperty
- type CSSTemplate
- type CallTemplateExpression
- type CaseExpression
- type Component
- type ComponentCSSClass
- type ComponentFunc
- type ConstantAttribute
- type ConstantCSSClass
- type ConstantCSSProperty
- type Element
- type Expression
- type ExpressionAttribute
- type ExpressionCSSProperty
- type ForExpression
- type HTMLTemplate
- type IfExpression
- type Import
- type Node
- type Package
- type ParseError
- type Position
- type Range
- type SafeCSS
- type SafeURL
- type SourceExpressionTo
- type SourceMap
- func (sm *SourceMap) Add(src Expression, tgt Range) (updatedFrom Position)
- func (sm *SourceMap) SourcePositionFromTarget(line, col int) (src Position, mapping SourceExpressionTo, ok bool)
- func (sm *SourceMap) TargetPositionFromSource(line, col int) (tgt Position, mapping SourceExpressionTo, ok bool)
- type StringExpression
- type StringSet
- type SwitchExpression
- type TemplateFile
- type TemplateFileNode
- type TemplateFileParser
- type Whitespace
Constants ¶
const FailedSanitizationURL = SafeURL("about:invalid#TemplFailedSanitizationURL")
FailedSanitizationURL is returned if a URL fails sanitization checks.
Variables ¶
This section is empty.
Functions ¶
func EscapeString ¶
EscapeString escapes HTML text within templates.
Types ¶
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 []CSSClass
CSSClasses is a slice of CSS classes.
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 {
Classes []ComponentCSSClass
}
CSSHandler is a HTTP handler that serves CSS.
func NewCSSHandler ¶ added in v0.0.113
func NewCSSHandler(classes ...ComponentCSSClass) 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 ...ComponentCSSClass) 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 CSSProperty ¶ added in v0.0.113
CSSProperty is a CSS property and value pair.
type CSSTemplate ¶ added in v0.0.113
type CSSTemplate struct { Name Expression Properties []CSSProperty }
CSS definition. {% css Name() %}
color: #ffffff; background-color: {%= constants.BackgroundColor %}; background-image: url('./somewhere.png');
{% endcss %}
func (CSSTemplate) IsTemplateFileNode ¶ added in v0.0.113
func (css CSSTemplate) IsTemplateFileNode() bool
type CallTemplateExpression ¶
type CallTemplateExpression struct { // Expression returns a template to execute. Expression Expression }
CallTemplateExpression can be used to create and render a template using data. {%! Other(p.First, p.Last) %} or it can be used to render a template parameter. {%! v %}
func (CallTemplateExpression) IsNode ¶
func (cte CallTemplateExpression) IsNode() bool
type CaseExpression ¶
type CaseExpression struct { Expression Expression Children []Node }
{% case "Something" %} ... {% endcase %}
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 ConstantAttribute ¶
href=""
func (ConstantAttribute) IsAttribute ¶
func (ca ConstantAttribute) IsAttribute() bool
func (ConstantAttribute) String ¶
func (ca ConstantAttribute) String() string
type ConstantCSSClass ¶ added in v0.0.113
type ConstantCSSClass string
ConstantCSSClass is a string constant of a CSS class name.
func (ConstantCSSClass) ClassName ¶ added in v0.0.113
func (css ConstantCSSClass) ClassName() string
ClassName of the CSS class.
type ConstantCSSProperty ¶ added in v0.0.113
color: #ffffff;
func (ConstantCSSProperty) IsCSSProperty ¶ added in v0.0.113
func (c ConstantCSSProperty) IsCSSProperty() bool
type Element ¶
<a .../> or <div ...>...</div>
func (Element) IsVoidElement ¶ added in v0.0.99
https://www.w3.org/TR/2011/WD-html-markup-20110113/syntax.html#void-element
type Expression ¶
Expression containing Go code.
func NewExpression ¶
func NewExpression(value string, from, to Position) Expression
NewExpression creates a Go expression.
type ExpressionAttribute ¶
type ExpressionAttribute struct { Name string Expression Expression }
href={%= ... }
func (ExpressionAttribute) IsAttribute ¶
func (ea ExpressionAttribute) IsAttribute() bool
func (ExpressionAttribute) String ¶
func (ea ExpressionAttribute) String() string
type ExpressionCSSProperty ¶ added in v0.0.113
type ExpressionCSSProperty struct { Name string Value StringExpression }
background-color: {%= constants.BackgroundColor %};
func (ExpressionCSSProperty) IsCSSProperty ¶ added in v0.0.113
func (c ExpressionCSSProperty) IsCSSProperty() bool
type ForExpression ¶
type ForExpression struct { Expression Expression Children []Node }
{% for i, v := range p.Addresses %}
{% call Address(v) %}
{% endfor %}
func (ForExpression) IsNode ¶
func (fe ForExpression) IsNode() bool
type HTMLTemplate ¶ added in v0.0.113
type HTMLTemplate struct { Name Expression Parameters Expression Children []Node }
HTMLTemplate definition. {% templ Name(p Parameter) %}
{% if ... %} <Element></Element>
{% endtempl %}
func (HTMLTemplate) IsTemplateFileNode ¶ added in v0.0.113
func (t HTMLTemplate) IsTemplateFileNode() bool
type IfExpression ¶
type IfExpression struct { Expression Expression Then []Node Else []Node }
{% if p.Type == "test" && p.thing %} {% endif %}
func (IfExpression) IsNode ¶
func (n IfExpression) IsNode() bool
type Import ¶
type Import struct {
Expression Expression
}
{% import "strings" %} {% import strs "strings" %}
type ParseError ¶ added in v0.0.89
ParseError details where the error occurred in the file.
func (ParseError) Error ¶ added in v0.0.89
func (pe ParseError) Error() string
type Position ¶
Source mapping to map from the source code of the template to the in-memory representation.
func NewPositionFromInput ¶
NewPositionFromInput creates a position from a parse input.
func NewPositionFromValues ¶
NewPositionFromValues initialises a position.
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.
type SourceExpressionTo ¶
type SourceExpressionTo struct { Source Expression Target Range }
SourceExpressionTo is a record of an expression, along with its start and end positions.
type SourceMap ¶
type SourceMap struct {
Items []SourceExpressionTo
}
func NewSourceMap ¶
func NewSourceMap() *SourceMap
NewSourceMap creates a new lookup to map templ source code to items in the parsed template.
func (*SourceMap) Add ¶
func (sm *SourceMap) Add(src Expression, tgt Range) (updatedFrom Position)
Add an item to the lookup.
func (*SourceMap) SourcePositionFromTarget ¶
func (sm *SourceMap) SourcePositionFromTarget(line, col int) (src Position, mapping SourceExpressionTo, ok bool)
SourcePositionFromTarget looks the source position using the target position.
func (*SourceMap) TargetPositionFromSource ¶
func (sm *SourceMap) TargetPositionFromSource(line, col int) (tgt Position, mapping SourceExpressionTo, ok bool)
TargetPositionFromSource looks up the target position using the source position.
type StringExpression ¶
type StringExpression struct {
Expression Expression
}
StringExpression is used within HTML elements, and for style values. {%= ... %}
func (StringExpression) IsNode ¶
func (se StringExpression) IsNode() bool
func (StringExpression) IsStyleDeclarationValue ¶ added in v0.0.113
func (se StringExpression) IsStyleDeclarationValue() bool
type StringSet ¶ added in v0.0.113
type StringSet struct {
// contains filtered or unexported fields
}
StringSet is a set of strings.
func RenderedCSSClassesFromContext ¶ added in v0.0.113
RenderedCSSClassesFromContext returns a set of the CSS classes that have already been rendered to the response.
type SwitchExpression ¶
type SwitchExpression struct { Expression Expression Cases []CaseExpression Default []Node }
{% switch p.Type %}
{% case "Something" %} {% endcase %}
{% endswitch %}
func (SwitchExpression) IsNode ¶
func (se SwitchExpression) IsNode() bool
type TemplateFile ¶
type TemplateFile struct { Package Package Imports []Import Nodes []TemplateFileNode }
func Parse ¶
func Parse(fileName string) (TemplateFile, error)
func ParseString ¶
func ParseString(template string) (TemplateFile, error)
type TemplateFileNode ¶ added in v0.0.113
TemplateFileNode can be a Template or a CSS.
type TemplateFileParser ¶
type TemplateFileParser struct { }
func NewTemplateFileParser ¶
func NewTemplateFileParser() TemplateFileParser
NewTemplateFileParser creates a new TemplateFileParser.
type Whitespace ¶
type Whitespace struct {
Value string
}
Whitespace.
func (Whitespace) IsNode ¶
func (ws Whitespace) IsNode() bool
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
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
|
|
testdependents
module
|