pugtemplate: flamingo.me/pugtemplate/pugjs Index | Files | Directories

package pugjs

import "flamingo.me/pugtemplate/pugjs"

Index

Package Files

engine.go pug_blocks.go pug_parser.go runtime.go tpl.go tpl_exec.go tpl_funcs.go transform_block.go transform_case.go transform_code.go transform_conditional.go transform_doctype.go transform_each.go transform_js_.go transform_mixin.go transform_tag.go transform_text.go transform_while.go types.go

Constants

const (
    // PageKey is used as constant in WithValue function and in module.go
    PageKey key = "page.template"
)

Variables

var AllowDeep = true

AllowDeep bool flag

var SelfClosingTags = map[string]bool{
    "area":    true,
    "base":    true,
    "br":      true,
    "col":     true,
    "command": true,
    "embed":   true,
    "hr":      true,
    "img":     true,
    "input":   true,
    "keygen":  true,
    "link":    true,
    "meta":    true,
    "param":   true,
    "source":  true,
    "track":   true,
    "wbr":     true,
}

SelfClosingTags contains all self closing HTML tags

func FuncToStatements Uses

func FuncToStatements(expr JavaScriptExpression) []ast.Statement

FuncToStatements reads Javascript Statements and evaluates them as the return of a function

func HTMLEscape Uses

func HTMLEscape(w io.Writer, b []byte)

HTMLEscape writes to w the escaped HTML equivalent of the plain text data b.

func HTMLEscapeString Uses

func HTMLEscapeString(s string) string

HTMLEscapeString returns the escaped HTML equivalent of the plain text data s.

func HTMLEscaper Uses

func HTMLEscaper(args ...interface{}) string

HTMLEscaper returns the escaped HTML equivalent of the textual representation of its arguments.

func IsTrue Uses

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 JSEscape Uses

func JSEscape(w io.Writer, b []byte)

JSEscape writes to w the escaped JavaScript equivalent of the plain text data b.

func JSEscapeString Uses

func JSEscapeString(s string) string

JSEscapeString returns the escaped JavaScript equivalent of the plain text data s.

func JSEscaper Uses

func JSEscaper(args ...interface{}) string

JSEscaper returns the escaped JavaScript equivalent of the textual representation of its arguments.

func StrToStatements Uses

func StrToStatements(expr JavaScriptExpression) []ast.Statement

StrToStatements reads Javascript Statements and returns an AST representation

func URLQueryEscaper Uses

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.

type Array Uses

type Array struct {
    // contains filtered or unexported fields
}

Array type

func (*Array) IndexOf Uses

func (a *Array) IndexOf(what interface{}) Object

IndexOf array element

func (*Array) Items Uses

func (a *Array) Items() []Object

Items getter

func (*Array) Join Uses

func (a *Array) Join(sep string) Object

Join array

func (*Array) Length Uses

func (a *Array) Length() Object

Length getter

func (*Array) MarshalJSON Uses

func (a *Array) MarshalJSON() ([]byte, error)

MarshalJSON implementation

func (*Array) Member Uses

func (a *Array) Member(name string) Object

Member getter

func (*Array) Pop Uses

func (a *Array) Pop() Object

Pop from array

func (*Array) Push Uses

func (a *Array) Push(what Object) Object

Push into array

func (*Array) Shift Uses

func (a *Array) Shift() Object

Shift removes an element from the beginning of the array and returns the element

func (*Array) Slice Uses

func (a *Array) Slice(n Number) Object

Slice an array

func (*Array) Sort Uses

func (a *Array) Sort() Object

Sort array

func (*Array) Splice Uses

func (a *Array) Splice(n Number) Object

Splice an array

func (*Array) String Uses

func (a *Array) String() string

String formatter

func (*Array) True Uses

func (a *Array) True() bool

True getter

func (*Array) Unshift Uses

func (a *Array) Unshift(elements ...Object) int

Unshift adds an element to the beginning of the array and returns the new length

type Attr Uses

type Attr struct {
    Name       string
    Val        interface{}
    MustEscape bool
}

Attr is a simple key-value pair

type Attribute Uses

type Attribute struct {
    Name       string
    Val        JavaScriptExpression
    MustEscape bool
    BoolVal    *bool
}

Attribute is a key-value attribute (might have to be escaped)

type AttributedNode Uses

type AttributedNode struct {
    Attrs           []Attribute
    AttributeBlocks []JavaScriptExpression
}

AttributedNode extends a node with attributes

type Block Uses

type Block struct {
    Nodes []Node
}

Block is a list of nodes

func (*Block) Inline Uses

func (b *Block) Inline() bool

Inline check for a block

func (*Block) Render Uses

func (b *Block) Render(s *renderState, wr *bytes.Buffer) error

Render renders a Block, and intends every sub-block if necessary

type BlockComment Uses

type BlockComment struct {
    BlockNode
    CommonComment
}

BlockComment is multi line comment

type BlockNode Uses

type BlockNode struct {
    Block Block
}

BlockNode is a block (which is renderable)

func (*BlockNode) Inline Uses

func (b *BlockNode) Inline() bool

Inline for BlockNodes

type Bool Uses

type Bool bool

Bool type

func (Bool) Member Uses

func (b Bool) Member(string) Object

Member getter

func (Bool) String Uses

func (b Bool) String() string

String formatter

func (Bool) True Uses

func (b Bool) True() bool

True getter

type Case Uses

type Case struct {
    BlockNode
    ExpressionNode
}

Case switch/case construct

func (*Case) Render Uses

func (c *Case) Render(s *renderState, wr *bytes.Buffer) error

Render a case node

type Code Uses

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

func (*Code) Inline Uses

func (c *Code) Inline() bool

Inline for Code

func (*Code) Render Uses

func (c *Code) Render(p *renderState, wr *bytes.Buffer) error

Render renders a code block

type Comment Uses

type Comment struct {
    CommonComment
}

Comment is single line comment

type CommonComment Uses

type CommonComment struct {
    ValueNode
}

CommonComment is the basic value for comments

type CommonTag Uses

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

func (*CommonTag) Inline Uses

func (ct *CommonTag) Inline() bool

Inline for CommonTags

type Conditional Uses

type Conditional struct {
    Test       JavaScriptExpression
    Consequent Node
    Alternate  Node
}

Conditional is equivalent to `if`

func (*Conditional) Inline Uses

func (c *Conditional) Inline() bool

Inline for Conditionals

func (*Conditional) Render Uses

func (c *Conditional) Render(p *renderState, wr *bytes.Buffer) error

Render renders a conditional via `if`

type Doctype Uses

type Doctype struct {
    ValueNode
}

Doctype is a `<!DOCTYPE...` node

func (*Doctype) Render Uses

func (d *Doctype) Render(p *renderState, wr *bytes.Buffer) error

Render renders the doctype

type Each Uses

type Each struct {
    BlockNode

    Obj JavaScriptExpression
    Val JavaScriptIdentifier
    Key JavaScriptIdentifier
}

Each iterates over something

func (*Each) Render Uses

func (e *Each) Render(p *renderState, wr *bytes.Buffer) error

Render renders the loop, with obj or key+obj index

type Engine Uses

type Engine struct {
    *sync.RWMutex
    Basedir       string `inject:"config:pug_template.basedir"`
    Debug         bool   `inject:"config:debug.mode"`
    Trace         bool   `inject:"config:pug_template.trace,optional"`
    Assetrewrites map[string]string

    TemplateCode  map[string]string
    Webpackserver bool
    EventRouter   flamingo.EventRouter `inject:""`
    FuncProvider  templateFuncProvider `inject:""`
    Logger        flamingo.Logger      `inject:""`
    // contains filtered or unexported fields
}

Engine is the one and only javascript template engine for go ;)

func NewEngine Uses

func NewEngine(debugsetup *struct {
    Debug  bool            `inject:"config:debug.mode"`
    Logger flamingo.Logger `inject:""`
}) *Engine

NewEngine constructor

func NewEngineWithOptions Uses

func NewEngineWithOptions(opt ...EngineOption) *Engine

NewEngineWithOptions create a new Engine with options

func (*Engine) GetRateLimit Uses

func (e *Engine) GetRateLimit() int

GetRateLimit returns the rate limit; zero means rate limit is not activated

func (*Engine) Inject Uses

func (e *Engine) Inject(cfg *struct {
    RateLimit float64 `inject:"config:pug_template.ratelimit"`
})

Inject injects dependencies

func (*Engine) LoadTemplates Uses

func (e *Engine) LoadTemplates(filtername string) error

LoadTemplates with an optional filter

func (*Engine) Render Uses

func (e *Engine) Render(ctx context.Context, templateName string, data interface{}) (io.Reader, error)

Render via html/pug_template

func (*Engine) RenderPartials Uses

func (e *Engine) RenderPartials(ctx context.Context, templateName string, data interface{}, partials []string) (map[string]io.Reader, 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 EngineOption Uses

type EngineOption func(e *Engine)

EngineOption options to configure the Engine

func WithRateLimit Uses

func WithRateLimit(rateLimit int) EngineOption

WithRateLimit configures the rate limit. A value of zero, disables the rate limit.

type EventSubscriber Uses

type EventSubscriber struct {
    // contains filtered or unexported fields
}

EventSubscriber is the event subscriber for Engine

func (*EventSubscriber) Inject Uses

func (e *EventSubscriber) Inject(engine *Engine, logger flamingo.Logger)

Inject injects the EventSubscibers dependencies

func (*EventSubscriber) Notify Uses

func (e *EventSubscriber) Notify(_ context.Context, event flamingo.Event)

Notify the event subscriper

type ExecError Uses

type ExecError struct {
    Name string // Name of template.
    Err  error  // Pre-formatted error.
}

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.)

func (ExecError) Error Uses

func (e ExecError) Error() string

type ExpressionNode Uses

type ExpressionNode struct {
    Expr JavaScriptExpression
}

ExpressionNode is a javascript expression

type Fileref Uses

type Fileref struct {
    Type, Path string
    Line       int
}

Fileref is used by include/extends

type Func Uses

type Func struct {
    // contains filtered or unexported fields
}

Func type

func (*Func) MarshalJSON Uses

func (f *Func) MarshalJSON() ([]byte, error)

MarshalJSON implementation

func (*Func) Member Uses

func (f *Func) Member(name string) Object

Member getter

func (*Func) String Uses

func (f *Func) String() string

String formatter

func (*Func) True Uses

func (f *Func) True() bool

True getter

type FuncMap Uses

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 Uses

type InterpolatedTag struct {
    CommonTag
    ExpressionNode
}

InterpolatedTag a tag which is created on the fly

func (*InterpolatedTag) Render Uses

func (it *InterpolatedTag) Render(p *renderState, wr *bytes.Buffer) error

Render an interpolated tag

type JavaScriptExpression Uses

type JavaScriptExpression string

JavaScriptExpression is a string

type JavaScriptIdentifier Uses

type JavaScriptIdentifier string

JavaScriptIdentifier is a string

type Map Uses

type Map struct {
    // contains filtered or unexported fields
}

Map type

func (*Map) AsStringIfaceMap Uses

func (m *Map) AsStringIfaceMap() map[string]interface{}

AsStringIfaceMap helper

func (*Map) AsStringMap Uses

func (m *Map) AsStringMap() map[string]string

AsStringMap helper

func (*Map) Assign Uses

func (m *Map) Assign(key string, field Object)

Assign a new item to the key

func (*Map) HasMember Uses

func (m *Map) HasMember(field string) bool

HasMember checks if a member exists

func (*Map) Keys Uses

func (m *Map) Keys() []string

Keys returns all map keys

func (*Map) MarshalJSON Uses

func (m *Map) MarshalJSON() ([]byte, error)

MarshalJSON implementation

func (*Map) Member Uses

func (m *Map) Member(field string) Object

Member getter

func (*Map) String Uses

func (m *Map) String() string

String formatter

func (*Map) True Uses

func (m *Map) True() bool

True getter

func (*Map) ValueOf Uses

func (m *Map) ValueOf() reflect.Value

ValueOf returns a new Value initialized to the concrete value stored in the m.items

type Mixin Uses

type Mixin struct {
    AttributedNode
    BlockNode

    Name JavaScriptIdentifier
    Call bool
    Args JavaScriptExpression
}

Mixin can be defined or called

func (*Mixin) Render Uses

func (m *Mixin) Render(p *renderState, wr *bytes.Buffer) error

Render renders the mixin, either it's call or it's definition

type MixinBlock Uses

type MixinBlock struct {
    PlaceholderNode
}

MixinBlock renders the mixin block

func (*MixinBlock) Render Uses

func (m *MixinBlock) Render(p *renderState, wr *bytes.Buffer) error

Render MixinBlock call

type MockNode Uses

type MockNode struct {
    mock.Mock
}

MockNode is an autogenerated mock type for the Node type

func (*MockNode) Inline Uses

func (_m *MockNode) Inline() bool

Inline provides a mock function with given fields:

func (*MockNode) Render Uses

func (_m *MockNode) Render(r *renderState, wr *bytes.Buffer) error

Render provides a mock function with given fields: r, wr

type Nil Uses

type Nil struct{}

Nil type

func (Nil) MarshalJSON Uses

func (n Nil) MarshalJSON() ([]byte, error)

MarshalJSON of Nil

func (Nil) Member Uses

func (n Nil) Member(string) Object

Member is always nil

func (Nil) String Uses

func (n Nil) String() string

String is always empty

func (Nil) True Uses

func (n Nil) True() bool

True is always false

type Node Uses

type Node interface {
    Render(r *renderState, wr *bytes.Buffer) error
    Inline() bool
}

Node is something renderable

type Number Uses

type Number float64

Number type

func (Number) Member Uses

func (n Number) Member(string) Object

Member getter

func (Number) String Uses

func (n Number) String() string

String formatter

type Object Uses

type Object interface {
    Member(name string) Object
    String() string
    // contains filtered or unexported methods
}

Object describes a pugjs JavaScript object

func Convert Uses

func Convert(in interface{}) Object

Convert an object

type PlaceholderNode Uses

type PlaceholderNode struct{}

PlaceholderNode does nothing

func (*PlaceholderNode) Inline Uses

func (p *PlaceholderNode) Inline() bool

Inline for PlaceholderNodes

type String Uses

type String string

String type

func (String) CharAt Uses

func (s String) CharAt(nPos Number) string

CharAt function

func (String) IndexOf Uses

func (s String) IndexOf(delim string) int

IndexOf Js func

func (String) Length Uses

func (s String) Length() int

Length of string

func (String) Member Uses

func (s String) Member(field string) Object

Member getter

func (String) Replace Uses

func (s String) Replace(what, with String) String

Replace string values

func (String) Slice Uses

func (s String) Slice(nfrom Number, toList ...Number) string

Slice a string

func (String) Split Uses

func (s String) Split(delim string) []string

Split splitter

func (String) String Uses

func (s String) String() string

String formatter

func (String) ToLowerCase Uses

func (s String) ToLowerCase() string

ToLowerCase converter

func (String) ToUpperCase Uses

func (s String) ToUpperCase() string

ToUpperCase converter

type Tag Uses

type Tag struct {
    CommonTag
    Name string
}

Tag is just a tag

func (*Tag) Render Uses

func (t *Tag) Render(p *renderState, wr *bytes.Buffer) error

Render a tag

type Template Uses

type Template struct {
    *parse.Tree
    // contains filtered or unexported fields
}

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 New Uses

func New(name string) *Template

New allocates a new, undefined template with the given name.

func (*Template) AddParseTree Uses

func (t *Template) AddParseTree(name string, tree *parse.Tree) (*Template, error)

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 Uses

func (t *Template) Clone() (*Template, error)

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 Uses

func (t *Template) Delims(left, right string) *Template

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 Uses

func (t *Template) Execute(ctx context.Context, wr io.Writer, data interface{}, trace bool) error

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 Uses

func (t *Template) ExecuteTemplate(ctx context.Context, wr io.Writer, name string, data interface{}, trace bool) 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 Uses

func (t *Template) Funcs(funcMap FuncMap) *Template

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 Uses

func (t *Template) Lookup(name string) *Template

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) Name Uses

func (t *Template) Name() string

Name returns the name of the template.

func (*Template) New Uses

func (t *Template) New(name string) *Template

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 Uses

func (t *Template) Parse(text string) (*Template, error)

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.

func (*Template) Templates Uses

func (t *Template) Templates() []*Template

Templates returns a slice of defined templates associated with e.

type Text Uses

type Text struct {
    ValueNode
}

Text contains raw text

func (*Text) Render Uses

func (t *Text) Render(p *renderState, wr *bytes.Buffer) error

Render a text node

type Token Uses

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

type ValueNode Uses

type ValueNode struct {
    Val string
}

ValueNode contains a value

func (*ValueNode) Inline Uses

func (v *ValueNode) Inline() bool

Inline for ValueNodes

type When Uses

type When struct {
    BlockNode
    ExpressionNode
}

When is a case in a case-construct

func (*When) Render Uses

func (w *When) Render(s *renderState, wr *bytes.Buffer) error

Render a when node

type While Uses

type While struct {
    BlockNode

    Test JavaScriptExpression
}

While loop

func (*While) Render Uses

func (w *While) Render(p *renderState, wr *bytes.Buffer) error

Render renders the loop, with obj or key+obj index

Directories

PathSynopsis
parsePackage parse builds parse trees for templates as defined by text/template and html/template.

Package pugjs imports 34 packages (graph) and is imported by 6 packages. Updated 2020-02-20. Refresh now. Tools for package owners.