Documentation ¶
Index ¶
- Constants
- func JSONEscape(dest io.Writer, data string) error
- type Compiler
- type EscapeMode
- type FileProvider
- type PartialProvider
- type RenderFn
- type StaticProvider
- type Tag
- type TagType
- type Template
- func (tmpl *Template) FRenderInLayout(out io.Writer, layout *Template, context ...interface{}) error
- func (tmpl *Template) Frender(out io.Writer, 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 ¶
This section is empty.
Functions ¶
Types ¶
type Compiler ¶
type Compiler struct {
// contains filtered or unexported fields
}
func (*Compiler) CompileFile ¶
CompileFile compiles a Mustache template from a file.
func (*Compiler) CompileString ¶
CompileString compiles a Mustache template from a string.
func (*Compiler) WithErrors ¶
WithErrors enables errors when there is a missing data object referred to by the template, a missing partial, or a missing partial provider to handle a partial. Otherwise, errors are ignored and result in empty strings in the output.
func (*Compiler) WithEscapeMode ¶
func (r *Compiler) WithEscapeMode(m EscapeMode) *Compiler
WithEscapeMode sets the output mode to either HTML, JSON or raw (plain text). The default is HTML.
func (*Compiler) WithPartials ¶
func (r *Compiler) WithPartials(pp PartialProvider) *Compiler
WithPartials adds a partial provider and enables support for partials.
type EscapeMode ¶
type EscapeMode int
EscapeMode indicates what sort of escaping to perform in template output. EscapeHTML is the default, and assumes the template is producing HTML. EscapeJSON switches to JSON escaping, for use cases such as generating Slack messages. Raw turns off escaping, for situations where you are absolutely sure you want plain text.
const ( EscapeHTML EscapeMode = iota // Escape output as HTML (default) EscapeJSON // Escape output as JSON Raw // Do not escape output (plain text mode) )
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". If Unsafe is set, partial names are allowed to begin with '.' or '..' after cleaning, meaning they can potentially refer to files outside any of the listed directory paths.
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 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 compiled mustache template which can be used to render data.
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) Frender ¶
Frender uses the given data source - generally a map or struct - to render the compiled 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.