Documentation
¶
Index ¶
- Variables
- func HTMLEscape(s string) string
- func ValidDirReaderPath(path string) bool
- type BuildOptions
- type CSS
- type CSSEnvStringer
- type CSSStringer
- type CompilerError
- type Converter
- type Declarations
- type DirLimitedReader
- type DirReader
- type EnvStringer
- type FileReader
- type Format
- type HTML
- type HTMLEnvStringer
- type HTMLStringer
- type JS
- type JSEnvStringer
- type JSON
- type JSONEnvStringer
- type JSONStringer
- type JSStringer
- type MapReader
- type Markdown
- type MarkdownEnvStringer
- type MarkdownStringer
- type RunOptions
- type Template
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidPath is returned from the Build function and a FileReader when // the path argument is not valid. ErrInvalidPath = errors.New("scriggo: invalid path") // ErrNotExist is returned from the Build function when the path does not // exist. ErrNotExist = errors.New("scriggo: path does not exist") // ErrReadTooLarge is returned from the Build function when a limit is // exceeded reading a path. ErrReadTooLarge = errors.New("scriggo: read too large") )
Functions ¶
func HTMLEscape ¶ added in v0.23.0
HTMLEscape escapes s, replacing the characters <, >, &, " and ' and returns the escaped string.
Use HTMLEscape to put a trusted or untrusted string into an HTML element content or in a quoted attribute value. But don't use it with complex attributes like href, src, style, or any of the event handlers like onmouseover.
func ValidDirReaderPath ¶
ValidDirReaderPath reports whether path is valid as name for DirReader and DirLimitedReader.
Types ¶
type BuildOptions ¶ added in v0.31.0
type BuildOptions struct {
DisallowGoStmt bool
TreeTransformer func(*ast.Tree) error // if not nil transforms tree after parsing.
// Globals declares constants, types, variables and functions that are
// accessible from the code in the template.
Globals Declarations
// Packages is a PackageLoader that makes precompiled packages available
// in the template through the 'import' statement.
//
// Note that an import statement refers to a precompiled package read from
// Packages if its path has no extension.
//
// {% import "my/package" %} Import a precompiled package.
// {% import "my/file.html %} Import a template file.
//
Packages scriggo.PackageLoader
}
type CSSEnvStringer ¶
CSSEnvStringer is like CSSStringer where the CSS method takes a runtime.Env parameter.
type CSSStringer ¶
type CSSStringer interface {
CSS() string
}
CSSStringer is implemented by values that are not escaped in CSS context.
type CompilerError ¶
CompilerError represents an error returned by the compiler.
type DirLimitedReader ¶
type DirLimitedReader struct {
// contains filtered or unexported fields
}
DirLimitedReader implements a FileReader that reads a source from files in a directory limiting the maximum file size and the total bytes read from all reads.
Use DirLimitedReader, instead of DirReader, when you do not have control of file sizes. As a Parser reads a file with a specific context only once, DirLimitedReader can be passed to a Parser to prevent it from allocating too much memory.
func NewDirLimitedReader ¶
func NewDirLimitedReader(dir string, maxFile, maxTotal int) *DirLimitedReader
NewDirLimitedReader returns a DirLimitedReader that reads the file from directory dir limiting the file size to maxFile bytes and the total bytes read from all files to maxTotal. It panics if maxFile or maxTotal are negative.
type DirReader ¶
type DirReader string
DirReader implements a FileReader that reads the files in a directory.
To limit the size of read files, use DirLimitedReader instead.
type EnvStringer ¶
EnvStringer is like fmt.Stringer where the String method takes a runtime.Env parameter.
type FileReader ¶
FileReader is implemented by values that can read files of a template. name, if not absolute, is relative to the root of the template. If the file with the given name does not exist, it returns nil and an os not found error.
type HTMLEnvStringer ¶
HTMLEnvStringer is like HTMLStringer where the HTML method takes a runtime.Env parameter.
type HTMLStringer ¶
type HTMLStringer interface {
HTML() string
}
HTMLStringer is implemented by values that are not escaped in HTML context.
type JSEnvStringer ¶ added in v0.30.0
JSEnvStringer is like JSStringer where the JS method takes a runtime.Env parameter.
type JSONEnvStringer ¶ added in v0.16.0
JSONEnvStringer is like JSONStringer where the JSON method takes a runtime.Env parameter.
type JSONStringer ¶ added in v0.16.0
type JSONStringer interface {
JSON() string
}
JSONStringer is implemented by values that are not escaped in JSON context.
type JSStringer ¶ added in v0.30.0
type JSStringer interface {
JS() string
}
JSStringer is implemented by values that are not escaped in JavaScript context.
type MapReader ¶
MapReader implements a FileReader where sources are read from a map. Map keys are the file names. If a name is present both relative and absolute, the file of the absolute one is returned.
type Markdown ¶ added in v0.31.0
type Markdown string
Markdown implements the MarkdownStringer interface.
type MarkdownEnvStringer ¶ added in v0.31.0
MarkdownEnvStringer is like MarkdownStringer where the Markdown method takes a runtime.Env parameter.
type MarkdownStringer ¶ added in v0.31.0
type MarkdownStringer interface {
Markdown() string
}
MarkdownStringer is implemented by values that are not escaped in Markdown context.
type RunOptions ¶ added in v0.31.0
type Template ¶
type Template struct {
// contains filtered or unexported fields
}
func Build ¶ added in v0.31.0
func Build(name string, files FileReader, options *BuildOptions) (*Template, error)
Build builds a template given its file name. Build calls the method ReadFile of files to read the files of the template.
The format of the file depends on the extension of name or, if files has the method 'Format(string) (Format, error)', Build gets the format from this method. If this method returns an error, this error is returned.
func (*Template) Disassemble ¶
Disassemble disassembles a template and returns its assembly code.
n determines the maximum length, in runes, of a disassembled text:
n > 0: at most n runes; leading and trailing white space are removed n == 0: no text n < 0: all text
func (*Template) MustRun ¶ added in v0.31.0
func (t *Template) MustRun(out io.Writer, vars map[string]interface{}, options *RunOptions)
MustRun is like Run but panics if the execution fails.