pugjs

package
v2.3.3+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 7, 2019 License: OSL-3.0 Imports: 36 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AllowDeep = true
View Source
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

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

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

func HTMLEscapeString

func HTMLEscapeString(s string) string

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 JSEscape

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

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

func JSEscapeString

func JSEscapeString(s string) string

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

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

IndexOf array element

func (*Array) Items

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

func (*Array) Join

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

Join array

func (*Array) Length

func (a *Array) Length() Object

Length getter

func (*Array) MarshalJSON

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

func (*Array) Member

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

Member getter

func (*Array) Pop

func (a *Array) Pop() Object

Pop from array

func (*Array) Push

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

Push into array

func (*Array) Slice

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

Slice an array

func (*Array) Splice

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

Splice an array

func (*Array) String

func (a *Array) String() string

String formatter

func (*Array) True

func (a *Array) True() bool

type Attr

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

Attr is a simple key-value pair

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 Block

type Block struct {
	Nodes []Node
}

Block is a list of nodes

func (*Block) Inline

func (b *Block) Inline() bool

Inline check for a block

func (*Block) Render

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

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

type BlockComment

type BlockComment struct {
	BlockNode
	CommonComment
}

BlockComment is multi line comment

type BlockNode

type BlockNode struct {
	Block Block
}

BlockNode is a block (which is renderable)

func (*BlockNode) Inline

func (b *BlockNode) Inline() bool

Inline for BlockNodes

type Bool

type Bool bool

Bool type

func (Bool) Member

func (b Bool) Member(string) Object

func (Bool) String

func (b Bool) String() string

func (Bool) True

func (b Bool) True() bool

type Case

type Case struct {
	BlockNode
	ExpressionNode
}

Case switch/case construct

func (*Case) Render

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

Render a case node

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

func (*Code) Inline

func (c *Code) Inline() bool

Inline for Code

func (*Code) Render

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

Render renders a code block

type Comment

type Comment struct {
	CommonComment
}

Comment is single line comment

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

func (*CommonTag) Inline

func (ct *CommonTag) Inline() bool

Inline for CommonTags

type Conditional

type Conditional struct {
	Test       JavaScriptExpression
	Consequent Node
	Alternate  Node
}

Conditional is equivalent to `if`

func (*Conditional) Inline

func (c *Conditional) Inline() bool

Inline for Conditionals

func (*Conditional) Render

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

Render renders a conditional via `if`

type Doctype

type Doctype struct {
	ValueNode
}

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

func (*Doctype) Render

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

Render renders the doctype

type Each

Each iterates over something

func (*Each) Render

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

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

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 NewEngine

func NewEngine() *Engine

NewEngine constructor

func (*Engine) LoadTemplates

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

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

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

func (e ExecError) Error() string

type ExpressionNode

type ExpressionNode struct {
	Expr JavaScriptExpression
}

ExpressionNode is a javascript expression

type Fileref

type Fileref struct {
	Type, Path string
	Line       int
}

Fileref is used by include/extends

type Func

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

Func type

func (*Func) MarshalJSON

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

MarshalJSON implementation

func (*Func) Member

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

func (*Func) String

func (f *Func) String() string

func (*Func) True

func (f *Func) True() bool

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

func (*InterpolatedTag) Render

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

Render an interpolated tag

type JavaScriptExpression

type JavaScriptExpression string

JavaScriptExpression is a string

type JavaScriptIdentifier

type JavaScriptIdentifier string

JavaScriptIdentifier is a string

type Map

type Map struct {
	Items map[Object]Object
	// contains filtered or unexported fields
}

Map type

func (*Map) AsStringMap

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

AsStringMap helper

func (*Map) MarshalJSON

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

MarshalJSON implementation

func (*Map) Member

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

Member getter

func (*Map) String

func (m *Map) String() string

String formatter

func (*Map) True

func (m *Map) True() bool

True getter

type Mixin

Mixin can be defined or called

func (*Mixin) Render

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

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

type MixinBlock

type MixinBlock struct {
	PlaceholderNode
}

MixinBlock renders the mixin block

func (*MixinBlock) Render

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

Render MixinBlock call

type MockNode

type MockNode struct {
	mock.Mock
}

MockNode is an autogenerated mock type for the Node type

func (*MockNode) Inline

func (_m *MockNode) Inline() bool

Inline provides a mock function with given fields:

func (*MockNode) Render

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

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

type Nil

type Nil struct{}

Nil type

func (Nil) MarshalJSON

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

func (Nil) Member

func (n Nil) Member(string) Object

func (Nil) String

func (n Nil) String() string

func (Nil) True

func (n Nil) True() bool

type Node

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

Node is something renderable

type Number

type Number float64

Number type

func (Number) Member

func (n Number) Member(string) Object

func (Number) String

func (n Number) String() string

type Object

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

Object describes a pugjs JavaScript object

func Convert

func Convert(in interface{}) Object

Convert an object

type OnRenderHTMLBlockEvent

type OnRenderHTMLBlockEvent struct {
	BlockName string
	Buffer    *bytes.Buffer
}

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 String

type String string

String type

func (String) CharAt

func (s String) CharAt(nPos Number) string

CharAt function

func (String) IndexOf

func (s String) IndexOf(delim string) int

IndexOf Js func

func (String) Length

func (s String) Length() int

Return string length

func (String) Member

func (s String) Member(field string) Object

Member getter

func (String) Replace

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

Replace string values

func (String) Slice

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

Slice a string

func (String) Split

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

Split splitter

func (String) String

func (s String) String() string

String formatter

func (String) ToUpperCase

func (s String) ToUpperCase() string

ToUpperCase converter

type Tag

type Tag struct {
	CommonTag
	Name string
}

Tag is just a tag

func (*Tag) Render

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

Render a tag

type Template

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

func New(name string) *Template

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

func (*Template) AddParseTree

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

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

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

func (t *Template) Execute(ctx context.Context, wr io.Writer, data interface{}) 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

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

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

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

func (t *Template) Name() string

Name returns the name of the template.

func (*Template) New

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

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

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

Templates returns a slice of defined templates associated with e.

type Text

type Text struct {
	ValueNode
}

Text contains raw text

func (*Text) Render

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

Render a text node

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

type ValueNode

type ValueNode struct {
	Val string
}

ValueNode contains a value

func (*ValueNode) Inline

func (v *ValueNode) Inline() bool

Inline for ValueNodes

type When

type When struct {
	BlockNode
	ExpressionNode
}

When is a case in a case-construct

func (*When) Render

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

Render a when node

type While

type While struct {
	BlockNode

	Test JavaScriptExpression
}

While loop

func (*While) Render

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

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

Directories

Path Synopsis
Package parse builds parse trees for templates as defined by text/template and html/template.
Package parse builds parse trees for templates as defined by text/template and html/template.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL