Documentation ¶
Index ¶
- Constants
- Variables
- func Render(data string, context ...interface{}) (string, error)
- func RenderFile(filename string, context ...interface{}) (string, error)
- func RenderFileInLayout(filename string, layoutFile string, context ...interface{}) (string, error)
- func RenderInLayout(data string, layoutData string, context ...interface{}) (string, error)
- func RenderInLayoutPartials(data string, layoutData string, partials PartialProvider, ...) (string, error)
- func RenderPartials(data string, partials PartialProvider, context ...interface{}) (string, error)
- func RenderPartialsRaw(data string, partials PartialProvider, forceRaw bool, context ...interface{}) (string, error)
- func RenderRaw(data string, forceRaw bool, context ...interface{}) (string, error)
- type ErrorCode
- type EscapeFunc
- type FileProvider
- type LambdaFunc
- type ParseError
- type PartialProvider
- type RenderFunc
- type StaticProvider
- type Tag
- type TagType
- type Template
- func ParseFile(filename string) (*Template, error)
- func ParseFilePartials(filename string, partials PartialProvider) (*Template, error)
- func ParseFilePartialsRaw(filename string, forceRaw bool, partials PartialProvider) (*Template, error)
- func ParseString(data string) (*Template, error)
- func ParseStringPartials(data string, partials PartialProvider) (*Template, error)
- func ParseStringPartialsRaw(data string, partials PartialProvider, forceRaw bool) (*Template, error)
- func ParseStringRaw(data string, forceRaw bool) (*Template, error)
- func (tmpl *Template) Escape(fn EscapeFunc)
- func (tmpl *Template) FRender(out io.Writer, context ...interface{}) error
- func (tmpl *Template) FRenderInLayout(out io.Writer, layout *Template, context ...interface{}) error
- func (tmpl *Template) Render(context ...interface{}) (string, error)
- func (tmpl *Template) RenderInLayout(layout *Template, context ...interface{}) (string, error)
- func (tmpl *Template) Tags() []Tag
Constants ¶
const (
SkipWhitespaceTagTypes = "#^/<>=!"
)
Skip all whitespaces apeared after these types of tags until end of line if the line only contains a tag and whitespaces.
Variables ¶
var ( // AllowMissingVariables defines the behavior for a variable "miss." If it // is true (the default), an empty string is emitted. If it is false, an error // is generated instead. AllowMissingVariables = true )
Functions ¶
func Render ¶
Render compiles a mustache template string and uses the the given data source - generally a map or struct - to render the template and return the output.
func RenderFile ¶
RenderFile loads a mustache template string from a file and compiles it, and then uses the the given data source - generally a map or struct - to render the template and return the output.
func RenderFileInLayout ¶
RenderFileInLayout loads a mustache template string and layout "wrapper" template string from files and compiles them, and then uses the the given data source - generally a map or struct - to render the compiled templates and return the output.
func RenderInLayout ¶
RenderInLayout compiles a mustache template string and layout "wrapper" and uses the given data source - generally a map or struct - to render the compiled templates and return the output.
func RenderInLayoutPartials ¶
func RenderInLayoutPartials(data string, layoutData string, partials PartialProvider, context ...interface{}) (string, error)
RenderInLayoutPartials compiles a mustache template string and layout "wrapper" and uses the given data source - generally a map or struct - to render the compiled templates and return the output.
func RenderPartials ¶
func RenderPartials(data string, partials PartialProvider, context ...interface{}) (string, error)
RenderPartials compiles a mustache template string and uses the the given partial provider and data source - generally a map or struct - to render the template and return the output.
func RenderPartialsRaw ¶
func RenderPartialsRaw(data string, partials PartialProvider, forceRaw bool, context ...interface{}) (string, error)
RenderPartialsRaw compiles a mustache template string and uses the the given partial provider and data source - generally a map or struct - to render the template and return the output.
Types ¶
type ErrorCode ¶
type ErrorCode string
ErrorCode is the list of allowed values for the error's code.
const ( ErrUnmatchedOpenTag ErrorCode = "unmatched_open_tag" ErrEmptyTag ErrorCode = "empty_tag" ErrSectionNoClosingTag ErrorCode = "section_no_closing_tag" ErrInterleavedClosingTag ErrorCode = "interleaved_closing_tag" ErrInvalidMetaTag ErrorCode = "invalid_meta_tag" ErrUnmatchedCloseTag ErrorCode = "unmatched_close_tag" )
List of values that ErrorCode can take.
type EscapeFunc ¶
EscapeFunc is used for escaping non-raw values in templates.
type FileProvider ¶
FileProvider implements the PartialProvider interface by providing partials drawn from a filesystem. When a partial named `NAME` is requested, FileProvider searches each listed path for a file named as `NAME` followed by any of the listed extensions. The default for `Paths` is to search the current working directory. The default for `Extensions` is to examine, in order, no extension; then ".mustache"; then ".stache".
type LambdaFunc ¶
type LambdaFunc func(text string, render RenderFunc) (string, error)
LambdaFunc is the signature for lambda functions.
type ParseError ¶
type ParseError struct { // Line contains the line of the error Line int // Code contains the error code of the error Code ErrorCode // Reason contains the name of the element generating the error Reason string }
ParseError represents an error during the parsing
func (ParseError) Error ¶
func (e ParseError) Error() string
type PartialProvider ¶
type PartialProvider interface { // Get accepts the name of a partial and returns the parsed partial, if it could be found; a valid but empty // template, if it could not be found; or nil and error if an error occurred (other than an inability to find // the partial). Get(name string) (string, error) }
PartialProvider comprises the behaviors required of a struct to be able to provide partials to the mustache rendering engine.
type RenderFunc ¶
RenderFunc is provided to lambda functions for rendering.
type StaticProvider ¶
StaticProvider implements the PartialProvider interface by providing partials drawn from a map, which maps partial name to template contents.
type Tag ¶
type Tag interface { // Type returns the type of the tag. Type() TagType // Name returns the name of the tag. Name() string // Tags returns any child tags. It panics for tag types which cannot contain // child tags (i.e. variable tags). Tags() []Tag }
Tag represents the different mustache tag types.
Not all methods apply to all kinds of tags. Restrictions, if any, are noted in the documentation for each method. Use the Type method to find out the type of tag before calling type-specific methods. Calling a method inappropriate to the type of tag causes a run time panic.
type TagType ¶
type TagType uint
A TagType represents the specific type of mustache tag that a Tag represents. The zero TagType is not a valid type.
Defines representing the possible Tag types
type Template ¶
type Template struct {
// contains filtered or unexported fields
}
Template represents a compilde mustache template
func ParseFile ¶
ParseFile loads a mustache template string from a file and compiles it. The resulting output can be used to efficiently render the template multiple times with different data sources.
func ParseFilePartials ¶
func ParseFilePartials(filename string, partials PartialProvider) (*Template, error)
ParseFilePartials loads a mustache template string from a file, retrieving any required partials from the given provider, and compiles it. The resulting output can be used to efficiently render the template multiple times with different data sources.
func ParseFilePartialsRaw ¶
func ParseFilePartialsRaw(filename string, forceRaw bool, partials PartialProvider) (*Template, error)
ParseFilePartialsRaw loads a mustache template string from a file, retrieving any required partials from the given provider, and compiles it. The resulting output can be used to efficiently render the template multiple times with different data sources.
func ParseString ¶
ParseString compiles a mustache template string. The resulting output can be used to efficiently render the template multiple times with different data sources.
func ParseStringPartials ¶
func ParseStringPartials(data string, partials PartialProvider) (*Template, error)
ParseStringPartials compiles a mustache template string, retrieving any required partials from the given provider. The resulting output can be used to efficiently render the template multiple times with different data sources.
func ParseStringPartialsRaw ¶
func ParseStringPartialsRaw(data string, partials PartialProvider, forceRaw bool) (*Template, error)
ParseStringPartialsRaw compiles a mustache template string, retrieving any required partials from the given provider. The resulting output can be used to efficiently render the template multiple times with different data sources.
func ParseStringRaw ¶
ParseStringRaw compiles a mustache template string. The resulting output can be used to efficiently render the template multiple times with different data sources.
func (*Template) Escape ¶
func (tmpl *Template) Escape(fn EscapeFunc)
Escape sets custom escape function. By-default it is HTMLEscape.
func (*Template) FRender ¶
FRender uses the given data source - generally a map or struct - to render the compiled template to an io.Writer.
func (*Template) FRenderInLayout ¶
func (tmpl *Template) FRenderInLayout(out io.Writer, layout *Template, context ...interface{}) error
FRenderInLayout uses the given data source - generally a map or struct - to render the compiled templated a loayout "wrapper" template to an io.Writer.
func (*Template) Render ¶
Render uses the given data source - generally a map or struct - to render the compiled template and return the output.
func (*Template) RenderInLayout ¶
RenderInLayout uses the given data source - generally a map or struct - to render the compiled template and layout "wrapper" template and return the output.