Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Errorf ¶
Errorf formats according to a format specifier, and returns the string as a value that satisfies error.
Unlike the function fmt.Errorf, Errorf does not recognize the %w verb in format.
func HTMLEscape ¶ added in v0.47.0
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.
Types ¶
type BuildError ¶ added in v0.47.0
type BuildError struct {
// contains filtered or unexported fields
}
BuildError represents an error occurred building a program or template.
func (*BuildError) Error ¶ added in v0.47.0
func (err *BuildError) Error() string
Error returns a string representation of the error.
func (*BuildError) Message ¶ added in v0.47.0
func (err *BuildError) Message() string
Message returns the error message.
func (*BuildError) Path ¶ added in v0.47.0
func (err *BuildError) Path() string
Path returns the path of the file where the error occurred.
func (*BuildError) Position ¶ added in v0.47.0
func (err *BuildError) Position() Position
Position returns the position in the file where the error occurred.
type BuildOptions ¶ added in v0.31.0
type BuildOptions struct { // AllowGoStmt, when true, allows the use of the go statement. AllowGoStmt bool // Packages is a package loader that makes native packages available // in programs and templates through the import statement. // // For templates, an import statement refers to a native package read from // Packages if its path has no extension. For example // // import a template file: {% import "my/file.html" %} // import a native package: {% import "my/package" %} // Packages native.PackageLoader // TreeTransformer is a function that transforms a tree. If it is not nil, // it is called before the type checking. // // Used for templates only. TreeTransformer func(tree *ast.Tree) error // NoParseShortShowStmt, when true, don't parse the short show statements. // // Used for templates only. NoParseShortShowStmt bool // MarkdownConverter converts a Markdown source code to HTML. // // Used for templates only. MarkdownConverter Converter // Globals declares constants, types, variables, functions and packages // that are accessible from the code in the template. // // Used for templates only. Globals native.Declarations // DollarIdentifier, when true, keeps the backward compatibility by // supporting the dollar identifier. // // NOTE: the dollar identifier is deprecated and will be removed in a // future version of Scriggo. // // Used for templates only. DollarIdentifier bool }
BuildOptions contains options for building programs and templates.
type ExitError ¶ added in v0.47.0
type ExitError int
ExitError represents an exit from an execution with a non-zero code. It is returned by a Run method when the Exit method of native.Env is called with a non-zero value.
type FormatFS ¶ added in v0.47.0
FormatFS is the interface implemented by a file system that can determine the file format from a path name.
type PanicError ¶ added in v0.47.0
type PanicError struct {
// contains filtered or unexported fields
}
PanicError represents the error that occurs when an executed program or template calls the panic built-in or the Panic method of native.Env is called and the panic is not recovered.
func (*PanicError) Error ¶ added in v0.47.0
func (p *PanicError) Error() string
Error returns all currently active panics as a string.
To print only the message, use the String method instead.
func (*PanicError) Message ¶ added in v0.47.0
func (p *PanicError) Message() interface{}
Message returns the panic message.
func (*PanicError) Next ¶ added in v0.47.0
func (p *PanicError) Next() *PanicError
Next returns the next panic in the chain.
func (*PanicError) Path ¶ added in v0.47.0
func (p *PanicError) Path() string
Path returns the path of the file that panicked.
func (*PanicError) Position ¶ added in v0.47.0
func (p *PanicError) Position() Position
Position returns the position in file where the panic occurred.
func (*PanicError) Recovered ¶ added in v0.47.0
func (p *PanicError) Recovered() bool
Recovered reports whether it has been recovered.
func (*PanicError) String ¶ added in v0.47.0
func (p *PanicError) String() string
String returns the panic message as a string.
type Position ¶ added in v0.47.0
type Position struct { Line int // line starting from 1 Column int // column in characters starting from 1 Start int // index of the first byte End int // index of the last byte }
Position is a position in a file.
type PrintFunc ¶
type PrintFunc func(interface{})
PrintFunc represents a function that prints the arguments of the print and println builtins.
type Program ¶
type Program struct {
// contains filtered or unexported fields
}
Program is a program compiled with the Build function.
func Build ¶ added in v0.31.0
func Build(fsys fs.FS, options *BuildOptions) (*Program, error)
Build builds a program from the package in the root of fsys with the given options.
Current limitation: fsys can contain only one Go file in its root.
If a build error occurs, it returns a *BuildError.
func (*Program) Disassemble ¶
Disassemble disassembles the package with the given path and returns its assembly code. Native packages can not be disassembled.
func (*Program) MustRun ¶
func (p *Program) MustRun(options *RunOptions)
MustRun is like Run but panics with the returned error if the run fails.
func (*Program) Run ¶
func (p *Program) Run(options *RunOptions) error
Run starts the program and waits for it to complete.
If the executed program panics or the Panic method of native.Env is called, and the panic is not recovered, Run returns a *PanicError.
If the Exit method of native.Env is called with a non-zero code, Run returns a *ExitError with the exit code.
If the Fatal method of native.Env is called with argument v, Run panics with the value v.
type RunOptions ¶
type RunOptions struct { // Context is a context that can be read by native functions and methods // via the Context method of native.Env. Context context.Context // Print is called by the print and println builtins to print values. // If it is nil, the print and println builtins format their arguments as // expected and write the result to standard error. Print PrintFunc }
RunOptions are the run options.
type Template ¶ added in v0.47.0
type Template struct {
// contains filtered or unexported fields
}
Template is a template compiled with the BuildTemplate function.
func BuildTemplate ¶ added in v0.47.0
BuildTemplate builds the named template file rooted at the given file system. Imported, rendered and extended files are read from fsys.
If fsys implements FormatFS, file formats are read with 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
If the named file does not exist, BuildTemplate returns an error satisfying errors.Is(err, fs.ErrNotExist).
If a build error occurs, it returns a *BuildError.
func (*Template) Disassemble ¶ added in v0.47.0
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.47.0
func (t *Template) MustRun(out io.Writer, vars map[string]interface{}, options *RunOptions)
MustRun is like Run but panics with the returned error if the run fails.
func (*Template) Run ¶ added in v0.47.0
Run runs the template and write the rendered code to out. vars contains the values of the global variables.
If the executed template panics or the Panic method of native.Env is called, and the panic is not recovered, Run returns a *PanicError.
If the Exit method of native.Env is called with a non-zero code, Run returns a *ExitError with the exit code.
If the Fatal method of native.Env is called with argument v, Run panics with the value v.
Directories
¶
Path | Synopsis |
---|---|
Package ast declares the types used to define program and template trees.
|
Package ast declares the types used to define program and template trees. |
astutil
Package astutil implements methods to walk and dump a tree.
|
Package astutil implements methods to walk and dump a tree. |
Package builtin provides simple functions, types and constants that can be used as globals in a Scriggo template.
|
Package builtin provides simple functions, types and constants that can be used as globals in a Scriggo template. |
internal
|
|
compiler
Package compiler implements parsing, type checking and emitting of sources.
|
Package compiler implements parsing, type checking and emitting of sources. |
compiler/types
package types implements functions and types to represent and work with Scriggo types.
|
package types implements functions and types to represent and work with Scriggo types. |
Package native provides types to implement native variables, constants, functions, types and packages that can be imported or used as builtins in programs and templates.
|
Package native provides types to implement native variables, constants, functions, types and packages that can be imported or used as builtins in programs and templates. |
Package scripts allows the Go code to be executed as a script.
|
Package scripts allows the Go code to be executed as a script. |
test
module
|