templates

package
v0.36.0 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2021 License: BSD-3-Clause Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FormatText     = ast.FormatText
	FormatHTML     = ast.FormatHTML
	FormatCSS      = ast.FormatCSS
	FormatJS       = ast.FormatJS
	FormatJSON     = ast.FormatJSON
	FormatMarkdown = ast.FormatMarkdown
)

Variables

This section is empty.

Functions

This section is empty.

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 CSS

type CSS string // the css type in templates.

Format types.

type CSSEnvStringer

type CSSEnvStringer interface {
	CSS(runtime.Env) CSS
}

CSSEnvStringer is like CSSStringer where the CSS method takes a runtime.Env parameter.

type CSSStringer

type CSSStringer interface {
	CSS() CSS
}

CSSStringer is implemented by values that are not escaped in CSS context.

type CompilerError

type CompilerError interface {
	error
	Position() ast.Position
	Path() string
	Message() string
}

CompilerError represents an error returned by the compiler.

type Converter added in v0.32.0

type Converter func(src []byte, out io.Writer) error

Converter is implemented by format converters.

type Declarations

type Declarations map[string]interface{}

Declarations.

type EnvStringer

type EnvStringer interface {
	String(runtime.Env) string
}

EnvStringer is like fmt.Stringer where the String method takes a runtime.Env parameter.

type Format added in v0.32.0

type Format = ast.Format

A Format represents a content format.

type FormatFS added in v0.33.0

type FormatFS interface {
	fs.FS
	Format(name string) (Format, error)
}

FormatFS is the interface implemented by a file system that can determine the file format from a path name.

type HTML

type HTML string // the html type in templates.

Format types.

func HTMLEscape added in v0.23.0

func HTMLEscape(s string) HTML

HTMLEscape escapes s, replacing the characters <, >, &, " and ' and returns the escaped string as HTML type.

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.

type HTMLEnvStringer

type HTMLEnvStringer interface {
	HTML(runtime.Env) HTML
}

HTMLEnvStringer is like HTMLStringer where the HTML method takes a runtime.Env parameter.

type HTMLStringer

type HTMLStringer interface {
	HTML() HTML
}

HTMLStringer is implemented by values that are not escaped in HTML context.

type JS added in v0.30.0

type JS string // the js type in templates.

Format types.

type JSEnvStringer added in v0.30.0

type JSEnvStringer interface {
	JS(runtime.Env) JS
}

JSEnvStringer is like JSStringer where the JS method takes a runtime.Env parameter.

type JSON added in v0.16.0

type JSON string // the json type in templates.

Format types.

type JSONEnvStringer added in v0.16.0

type JSONEnvStringer interface {
	JSON(runtime.Env) JSON
}

JSONEnvStringer is like JSONStringer where the JSON method takes a runtime.Env parameter.

type JSONStringer added in v0.16.0

type JSONStringer interface {
	JSON() JSON
}

JSONStringer is implemented by values that are not escaped in JSON context.

type JSStringer added in v0.30.0

type JSStringer interface {
	JS() JS
}

JSStringer is implemented by values that are not escaped in JavaScript context.

type MapFS added in v0.33.0

type MapFS map[string]string

MapFS implements a file system that read the files from a map.

func (MapFS) Open added in v0.33.0

func (fsys MapFS) Open(name string) (fs.File, error)

type Markdown added in v0.31.0

type Markdown string // the markdown type in templates.

Format types.

type MarkdownEnvStringer added in v0.31.0

type MarkdownEnvStringer interface {
	Markdown(runtime.Env) Markdown
}

MarkdownEnvStringer is like MarkdownStringer where the Markdown method takes a runtime.Env parameter.

type MarkdownStringer added in v0.31.0

type MarkdownStringer interface {
	Markdown() Markdown
}

MarkdownStringer is implemented by values that are not escaped in Markdown context.

type RunOptions added in v0.31.0

type RunOptions struct {
	Context   context.Context
	PrintFunc runtime.PrintFunc

	// MarkdownConverter converts a Markdown source code to HTML.
	MarkdownConverter Converter
}

type Template

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

func Build added in v0.31.0

func Build(fsys fs.FS, name string, options *BuildOptions) (*Template, error)

Build builds the named template file rooted at the given file system.

If fsys implements FormatFS, the file format is read from its Format method, otherwise it depends on the file name extension

HTML       : .html
CSS        : .css
JavaScript : .js
JSON       : .json
Markdown   : .md .mkd .mkdn .mdown .markdown
Text       : all other extensions

func (*Template) Disassemble

func (t *Template) Disassemble(n int) []byte

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.

func (*Template) Run added in v0.31.0

func (t *Template) Run(out io.Writer, vars map[string]interface{}, options *RunOptions) error

Run runs the template and write the rendered code to out. vars contains the values of the global variables.

func (*Template) UsedVars added in v0.32.0

func (t *Template) UsedVars() []string

UsedVars returns the names of the global variables used in the template.

Jump to

Keyboard shortcuts

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