Documentation ¶
Index ¶
- Variables
- func FuncToStatements(expr JavaScriptExpression) []ast.Statement
- func HTMLEscape(w io.Writer, b []byte)
- func HTMLEscapeString(s string) string
- func HTMLEscaper(args ...interface{}) string
- func IsTrue(val interface{}) (truth, ok bool)
- func JSEscape(w io.Writer, b []byte)
- func JSEscapeString(s string) string
- func JSEscaper(args ...interface{}) string
- func StrToStatements(expr JavaScriptExpression) []ast.Statement
- func URLQueryEscaper(args ...interface{}) string
- type Array
- func (a *Array) IndexOf(what interface{}) Object
- func (a *Array) Items() []Object
- func (a *Array) Join(sep string) Object
- func (a *Array) Length() Object
- func (a *Array) MarshalJSON() ([]byte, error)
- func (a *Array) Member(name string) Object
- func (a *Array) Pop() Object
- func (a *Array) Push(what Object) Object
- func (a *Array) Slice(n Number) Object
- func (a *Array) Splice(n Number) Object
- func (a *Array) String() string
- func (a *Array) True() bool
- type Attr
- type Attribute
- type AttributedNode
- type Block
- type BlockComment
- type BlockNode
- type Bool
- type Case
- type Code
- type Comment
- type CommonComment
- type CommonTag
- type Conditional
- type Doctype
- type Each
- type Engine
- type EventSubscriber
- type ExecError
- type ExpressionNode
- type Fileref
- type Func
- type FuncMap
- type InterpolatedTag
- type JavaScriptExpression
- type JavaScriptIdentifier
- type Map
- type Mixin
- type MixinBlock
- type MockNode
- type Nil
- type Node
- type Number
- type Object
- type OnRenderHTMLBlockEvent
- type PlaceholderNode
- type String
- func (s String) CharAt(nPos Number) string
- func (s String) IndexOf(delim string) int
- func (s String) Length() int
- func (s String) Member(field string) Object
- func (s String) Replace(what, with String) String
- func (s String) Slice(nfrom Number, toList ...Number) string
- func (s String) Split(delim string) []string
- func (s String) String() string
- func (s String) ToUpperCase() string
- type Tag
- type Template
- func (t *Template) AddParseTree(name string, tree *parse.Tree) (*Template, error)
- func (t *Template) Clone() (*Template, error)
- func (t *Template) Delims(left, right string) *Template
- func (t *Template) Execute(ctx context.Context, wr io.Writer, data interface{}) error
- func (t *Template) ExecuteTemplate(ctx context.Context, wr io.Writer, name string, data interface{}) error
- func (t *Template) Funcs(funcMap FuncMap) *Template
- func (t *Template) Lookup(name string) *Template
- func (t *Template) Name() string
- func (t *Template) New(name string) *Template
- func (t *Template) Parse(text string) (*Template, error)
- func (t *Template) Templates() []*Template
- type Text
- type Token
- type ValueNode
- type When
- type While
Constants ¶
This section is empty.
Variables ¶
var AllowDeep = true
var UseGoObject = false
Functions ¶
func FuncToStatements ¶
func FuncToStatements(expr JavaScriptExpression) []ast.Statement
FuncToStatements reads Javascript Statements and evaluates them as the return of a function
func HTMLEscape ¶
HTMLEscape writes to w the escaped HTML equivalent of the plain text data b.
func HTMLEscapeString ¶
HTMLEscapeString returns the escaped HTML equivalent of the plain text data s.
func HTMLEscaper ¶
func HTMLEscaper(args ...interface{}) string
HTMLEscaper returns the escaped HTML equivalent of the textual representation of its arguments.
func IsTrue ¶
func IsTrue(val interface{}) (truth, ok bool)
IsTrue reports whether the value is 'true', in the sense of not the zero of its type, and whether the value has a meaningful truth value. This is the definition of truth used by if and other such actions.
func JSEscapeString ¶
JSEscapeString returns the escaped JavaScript equivalent of the plain text data s.
func JSEscaper ¶
func JSEscaper(args ...interface{}) string
JSEscaper returns the escaped JavaScript equivalent of the textual representation of its arguments.
func StrToStatements ¶
func StrToStatements(expr JavaScriptExpression) []ast.Statement
StrToStatements reads Javascript Statements and returns an AST representation
func URLQueryEscaper ¶
func URLQueryEscaper(args ...interface{}) string
URLQueryEscaper returns the escaped value of the textual representation of its arguments in a form suitable for embedding in a URL query.
Types ¶
type Array ¶
type Array struct {
// contains filtered or unexported fields
}
Array type
func (*Array) MarshalJSON ¶
type Attribute ¶
type Attribute struct { Name string Val JavaScriptExpression MustEscape bool BoolVal *bool }
Attribute is a key-value attribute (might have to be escaped)
type AttributedNode ¶
type AttributedNode struct { Attrs []Attribute AttributeBlocks []JavaScriptExpression }
AttributedNode extends a node with attributes
type BlockComment ¶
type BlockComment struct { BlockNode CommonComment }
BlockComment is multi line comment
type Code ¶
type Code struct { BlockNode ValueNode Buffer bool // Buffer if the value of the piece of code is buffered in the template MustEscape bool // MustEscape if the value must be HTML-escaped before being buffered IsInline *bool // IsInline whether the node is the result of a string interpolation }
Code is a code block
type CommonComment ¶
type CommonComment struct {
ValueNode
}
CommonComment is the basic value for comments
type CommonTag ¶
type CommonTag struct { AttributedNode BlockNode SelfClosing bool // SelfClosing if the tag is explicitly stated as self-closing IsInline *bool // IsInline if the tag is defined as an inline tag as opposed to a block-level tag }
CommonTag is the base structure for tags
type Conditional ¶
type Conditional struct { Test JavaScriptExpression Consequent Node Alternate Node }
Conditional is equivalent to `if`
type Each ¶
type Each struct { BlockNode Obj JavaScriptExpression Val JavaScriptIdentifier Key JavaScriptIdentifier }
Each iterates over something
type Engine ¶
type Engine struct { *sync.RWMutex Basedir string `inject:"config:pug_template.basedir"` Debug bool `inject:"config:debug.mode"` Assetrewrites map[string]string TemplateCode map[string]string Webpackserver bool EventRouter event.Router `inject:""` FuncProvider template.FuncProvider `inject:""` CtxFuncProvider template.CtxFuncProvider `inject:""` Logger flamingo.Logger `inject:""` // contains filtered or unexported fields }
Engine is the one and only javascript template engine for go ;)
func (*Engine) LoadTemplates ¶
LoadTemplates with an optional filter
func (*Engine) Render ¶
func (e *Engine) Render(ctx context.Context, templateName string, data interface{}) (io.Reader, error)
Render via html/pug_template
func (*Engine) RenderPartials ¶
func (e *Engine) RenderPartials(ctx context.Context, templateName string, data interface{}, partials []string) (map[string]string, error)
RenderPartials is used for progressive enhancements / rendering of partial template areas usually this is requested via the appropriate javascript headers and taken care of in the framework renderer
type EventSubscriber ¶
type EventSubscriber struct {
// contains filtered or unexported fields
}
EventSubscriber is the event subscriber for Engine
func (*EventSubscriber) Inject ¶
func (e *EventSubscriber) Inject(engine *Engine, logger flamingo.Logger)
Inject injects the EventSubscibers dependencies
func (*EventSubscriber) Notify ¶
func (e *EventSubscriber) Notify(event event.Event)
Notify the event subscriper
type ExecError ¶
ExecError is the custom error type returned when Execute has an error evaluating its template. (If a write error occurs, the actual error is returned; it will not be of type ExecError.)
type ExpressionNode ¶
type ExpressionNode struct {
Expr JavaScriptExpression
}
ExpressionNode is a javascript expression
type FuncMap ¶
type FuncMap map[string]interface{}
FuncMap is the type of the map defining the mapping from names to functions. Each function must have either a single return value, or two return values of which the second has type error. In that case, if the second (error) return value evaluates to non-nil during execution, execution terminates and Execute returns that error.
When template execution invokes a function with an argument list, that list must be assignable to the function's parameter types. Functions meant to apply to arguments of arbitrary type can use parameters of type interface{} or of type reflect.Value. Similarly, functions meant to return a result of arbitrary type can return interface{} or reflect.Value.
type InterpolatedTag ¶
type InterpolatedTag struct { CommonTag ExpressionNode }
InterpolatedTag a tag which is created on the fly
type Mixin ¶
type Mixin struct { AttributedNode BlockNode Name JavaScriptIdentifier Call bool Args JavaScriptExpression }
Mixin can be defined or called
type MockNode ¶
MockNode is an autogenerated mock type for the Node type
type Object ¶
type Object interface { Member(name string) Object String() string // contains filtered or unexported methods }
Object describes a pugjs JavaScript object
type OnRenderHTMLBlockEvent ¶
OnRenderHTMLBlockEvent is an event which is called when a new block is going to be rendered
type PlaceholderNode ¶
type PlaceholderNode struct{}
PlaceholderNode does nothing
func (*PlaceholderNode) Inline ¶
func (p *PlaceholderNode) Inline() bool
Inline for PlaceholderNodes
type Template ¶
Template is the representation of a parsed template. The *parse.Tree field is exported only for use by html/template and should be treated as unexported by all other clients.
func (*Template) AddParseTree ¶
AddParseTree adds parse tree for template with given name and associates it with e. If the template does not already exist, it will create a new one. If the template does exist, it will be replaced.
func (*Template) Clone ¶
Clone returns a duplicate of the template, including all associated templates. The actual representation is not copied, but the name space of associated templates is, so further calls to Parse in the copy will add templates to the copy but not to the original. Clone can be used to prepare common templates and use them with variant definitions for other templates by adding the variants after the clone is made.
func (*Template) Delims ¶
Delims sets the action delimiters to the specified strings, to be used in subsequent calls to Parse, ParseFiles, or ParseGlob. Nested template definitions will inherit the settings. An empty delimiter stands for the corresponding default: {{ or }}. The return value is the template, so calls can be chained.
func (*Template) Execute ¶
Execute applies a parsed template to the specified data object, and writes the output to wr. If an error occurs executing the template or writing its output, execution stops, but partial results may already have been written to the output writer. A template may be executed safely in parallel.
If data is a reflect.Value, the template applies to the concrete value that the reflect.Value holds, as in fmt.Print.
func (*Template) ExecuteTemplate ¶
func (t *Template) ExecuteTemplate(ctx context.Context, wr io.Writer, name string, data interface{}) error
ExecuteTemplate applies the template associated with e that has the given name to the specified data object and writes the output to wr. If an error occurs executing the template or writing its output, execution stops, but partial results may already have been written to the output writer. A template may be executed safely in parallel.
func (*Template) Funcs ¶
Funcs adds the elements of the argument map to the template's function map. It panics if a value in the map is not a function with appropriate return type or if the name cannot be used syntactically as a function in a template. It is legal to overwrite elements of the map. The return value is the template, so calls can be chained.
func (*Template) Lookup ¶
Lookup returns the template with the given name that is associated with e. It returns nil if there is no such template or the template has no definition.
func (*Template) New ¶
New allocates a new, undefined template associated with the given one and with the same delimiters. The association, which is transitive, allows one template to invoke another with a {{template}} action.
func (*Template) Parse ¶
Parse parses text as a template body for e. Named template definitions ({{define ...}} or {{block ...}} statements) in text define additional templates associated with e and are removed from the definition of e itself.
Templates can be redefined in successive calls to Parse. A template definition with a body containing only white space and comments is considered empty and will not replace an existing template's body. This allows using Parse to add new named template definitions without overwriting the main template body.
type Token ¶
type Token struct { // default Type, Name string Mode, Val string Line int // subblock Block *Token // subblock childs Nodes []*Token // specific information AttributeBlocks []*Token Attrs []*Attr MustEscape bool File *Fileref Filename string SelfClosing bool IsInline *bool Obj string Key string // mixin Call bool // mixin call? Args string // call args // if Test string // if Consequent, Alternate *Token // if result // Interpolated Expr string }
Token defines the basic token read by the tokenizer Tokens form a tree, where the beginning root node starts the document