Documentation
¶
Index ¶
- Variables
- func ExpressionOf(p parse.Parser[string]) parse.Parser[Expression]
- func StripType[T any](p parse.Parser[T]) parse.Parser[any]
- type Attribute
- type BoolConstantAttribute
- type BoolExpressionAttribute
- type CSSProperty
- type CSSTemplate
- type CallTemplateExpression
- type CaseExpression
- type ChildrenExpression
- type ConditionalAttribute
- type ConstantAttribute
- type ConstantCSSProperty
- type Diagnostic
- type DocType
- type Element
- type ElseIfExpression
- type Expression
- type ExpressionAttribute
- type ExpressionCSSProperty
- type ForExpression
- type GoComment
- type HTMLComment
- type HTMLTemplate
- type IfExpression
- type Node
- type Nodes
- type Package
- type Position
- type Range
- type RawElement
- type ScriptTemplate
- type SourceMap
- type SpreadAttributes
- type StringExpression
- type SwitchExpression
- type TemplElementExpression
- type TemplateFile
- type TemplateFileGoExpression
- type TemplateFileNode
- type TemplateFileParser
- type Text
- type TrailingSpace
- type Whitespace
- type WhitespaceTrailer
Constants ¶
This section is empty.
Variables ¶
var ErrLegacyFileFormat = errors.New("legacy file format - run templ migrate")
var ErrNonSpaceCharacter = errors.New("non space character found")
var ErrTemplateNotFound = errors.New("template not found")
Functions ¶
func ExpressionOf ¶
Types ¶
type BoolConstantAttribute ¶
type BoolConstantAttribute struct {
Name string
}
<hr noshade/>
func (BoolConstantAttribute) String ¶
func (bca BoolConstantAttribute) String() string
type BoolExpressionAttribute ¶
type BoolExpressionAttribute struct {
Name string
Expression Expression
}
noshade={ templ.Bool(...) }
func (BoolExpressionAttribute) String ¶
func (ea BoolExpressionAttribute) String() string
type CSSProperty ¶
CSSProperty is a CSS property and value pair.
type CSSTemplate ¶
type CSSTemplate struct {
Name Expression
Properties []CSSProperty
}
CSS definition.
css Name() {
color: #ffffff;
background-color: { constants.BackgroundColor };
background-image: url('./somewhere.png');
}
func (CSSTemplate) IsTemplateFileNode ¶
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
Diagnostics []Diagnostic
}
case "Something":
type ChildrenExpression ¶
type ChildrenExpression struct{}
ChildrenExpression can be used to rended the children of a templ element. { children ... }
func (ChildrenExpression) IsNode ¶
func (ChildrenExpression) IsNode() bool
type ConditionalAttribute ¶
type ConditionalAttribute struct {
Expression Expression
Then []Attribute
Else []Attribute
}
<a href="test" \
if active {
class="isActive"
}
func (ConditionalAttribute) String ¶
func (ca ConditionalAttribute) String() string
type ConstantAttribute ¶
href=""
func (ConstantAttribute) String ¶
func (ca ConstantAttribute) String() string
type ConstantCSSProperty ¶
color: #ffffff;
func (ConstantCSSProperty) IsCSSProperty ¶
func (c ConstantCSSProperty) IsCSSProperty() bool
func (ConstantCSSProperty) String ¶
func (c ConstantCSSProperty) String(minified bool) string
type Diagnostic ¶
Diagnostic for template file.
type Element ¶
type Element struct {
Name string
Attributes []Attribute
IndentAttrs bool
Children []Node
IndentChildren bool
TrailingSpace TrailingSpace
Diagnostics []Diagnostic
}
<a .../> or <div ...>...</div>
func (Element) IsBlockElement ¶
func (Element) IsVoidElement ¶
https://www.w3.org/TR/2011/WD-html-markup-20110113/syntax.html#void-element
func (Element) Trailing ¶
func (e Element) Trailing() TrailingSpace
type ElseIfExpression ¶
type ElseIfExpression struct {
Expression Expression
Then []Node
Diagnostics []Diagnostic
}
type Expression ¶
Expression containing Go code.
func NewExpression ¶
func NewExpression(value string, from, to parse.Position) Expression
NewExpression creates a Go expression.
type ExpressionAttribute ¶
type ExpressionAttribute struct {
Name string
Expression Expression
}
href={ ... }
func (ExpressionAttribute) String ¶
func (ea ExpressionAttribute) String() string
type ExpressionCSSProperty ¶
type ExpressionCSSProperty struct {
Name string
Value StringExpression
}
background-color: { constants.BackgroundColor };
func (ExpressionCSSProperty) IsCSSProperty ¶
func (c ExpressionCSSProperty) IsCSSProperty() bool
type ForExpression ¶
type ForExpression struct {
Expression Expression
Children []Node
Diagnostics []Diagnostic
}
for i, v := range p.Addresses {
{! Address(v) }
}
func (ForExpression) IsNode ¶
func (fe ForExpression) IsNode() bool
type HTMLComment ¶
type HTMLComment struct {
Contents string
}
HTMLComment.
func (HTMLComment) IsNode ¶
func (c HTMLComment) IsNode() bool
type HTMLTemplate ¶
type HTMLTemplate struct {
Diagnostics []Diagnostic
Expression Expression
Children []Node
}
HTMLTemplate definition.
templ Name(p Parameter) {
if ... {
<Element></Element>
}
}
func (HTMLTemplate) IsTemplateFileNode ¶
func (t HTMLTemplate) IsTemplateFileNode() bool
type IfExpression ¶
type IfExpression struct {
Expression Expression
Then []Node
ElseIfs []ElseIfExpression
Else []Node
Diagnostics []Diagnostic
}
if p.Type == "test" && p.thing { }
func (IfExpression) IsNode ¶
func (n IfExpression) IsNode() bool
type Nodes ¶
type Nodes struct {
Diagnostics []Diagnostic
Nodes []Node
}
type Package ¶
type Package struct {
Expression Expression
}
type Position ¶
Source mapping to map from the source code of the template to the in-memory representation.
func NewPosition ¶
NewPosition initialises a position.
type RawElement ¶
func (RawElement) IsNode ¶
func (e RawElement) IsNode() bool
type ScriptTemplate ¶
type ScriptTemplate struct {
Name Expression
Parameters Expression
Value string
}
ScriptTemplate is a script block.
func (ScriptTemplate) IsTemplateFileNode ¶
func (s ScriptTemplate) IsTemplateFileNode() bool
type SourceMap ¶
type SourceMap struct {
SourceLinesToTarget map[uint32]map[uint32]Position
TargetLinesToSource map[uint32]map[uint32]Position
}
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 ¶
SourcePositionFromTarget looks the source position using the target position.
type SpreadAttributes ¶
type SpreadAttributes struct {
Expression Expression
}
<a { spread... } />
func (SpreadAttributes) String ¶
func (sa SpreadAttributes) String() string
type StringExpression ¶
type StringExpression struct {
Expression Expression
// TrailingSpace lists what happens after the expression.
TrailingSpace TrailingSpace
}
StringExpression is used within HTML elements, and for style values. { ... }
func (StringExpression) IsNode ¶
func (se StringExpression) IsNode() bool
func (StringExpression) IsStyleDeclarationValue ¶
func (se StringExpression) IsStyleDeclarationValue() bool
func (StringExpression) Trailing ¶
func (se StringExpression) Trailing() TrailingSpace
type SwitchExpression ¶
type SwitchExpression struct {
Expression Expression
Cases []CaseExpression
}
switch p.Type {
case "Something":
}
func (SwitchExpression) IsNode ¶
func (se SwitchExpression) IsNode() bool
type TemplElementExpression ¶
type TemplElementExpression struct {
// Expression returns a template to execute.
Expression Expression
// Children returns the elements in a block element.
Children []Node
Diagnostics []Diagnostic
}
TemplElementExpression 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 (TemplElementExpression) IsNode ¶
func (tee TemplElementExpression) IsNode() bool
type TemplateFile ¶
type TemplateFile struct {
// Header contains comments or whitespace at the top of the file.
Header []TemplateFileGoExpression
// Package expression.
Package Package
// Nodes in the file.
Nodes []TemplateFileNode
// Diagnostics contains any errors or warnings.
Diagnostics []Diagnostic
}
func Parse ¶
func Parse(fileName string) (TemplateFile, error)
func ParseString ¶
func ParseString(template string) (TemplateFile, error)
type TemplateFileGoExpression ¶
type TemplateFileGoExpression struct {
Expression Expression
}
TemplateFileGoExpression within a TemplateFile
func (TemplateFileGoExpression) IsTemplateFileNode ¶
func (exp TemplateFileGoExpression) IsTemplateFileNode() bool
type TemplateFileNode ¶
TemplateFileNode can be a Template, CSS, Script or Go.
type TemplateFileParser ¶
type TemplateFileParser struct {
DefaultPackage string
}
func NewTemplateFileParser ¶
func NewTemplateFileParser(pkg string) TemplateFileParser
NewTemplateFileParser creates a new TemplateFileParser.
func (TemplateFileParser) Parse ¶
func (p TemplateFileParser) Parse(pi *parse.Input) (tf TemplateFile, ok bool, err error)
type Text ¶
type Text struct {
// Value is the raw HTML encoded value.
Value string
// TrailingSpace lists what happens after the text.
TrailingSpace TrailingSpace
}
Text node within the document.
func (Text) Trailing ¶
func (t Text) Trailing() TrailingSpace
type TrailingSpace ¶
type TrailingSpace string
TrailingSpace defines the whitespace that may trail behind the close of an element, a text node, or string expression.
const ( SpaceNone TrailingSpace = "" SpaceHorizontal TrailingSpace = " " SpaceVertical TrailingSpace = "\n" )
func NewTrailingSpace ¶
func NewTrailingSpace(s string) (ts TrailingSpace, err error)
type Whitespace ¶
type Whitespace struct {
Value string
}
Whitespace.
func (Whitespace) IsNode ¶
func (ws Whitespace) IsNode() bool
type WhitespaceTrailer ¶
type WhitespaceTrailer interface {
Trailing() TrailingSpace
}
Source Files
¶
- calltemplateparser.go
- childrenparser.go
- conditionalattributeparser.go
- cssparser.go
- doctypeparser.go
- elementparser.go
- expressionparser.go
- forexpressionparser.go
- gocommentparser.go
- htmlcommentparser.go
- ifexpressionparser.go
- packageparser.go
- parser.go
- raw.go
- scripttemplateparser.go
- sourcemap.go
- stringexpressionparser.go
- switchexpressionparser.go
- templatefile.go
- templateparser.go
- templelementparser.go
- textparser.go
- types.go
- whitespaceparser.go