native

package
v0.48.0 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2021 License: BSD-3-Clause Imports: 3 Imported by: 13

Documentation

Overview

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.

Index

Constants

This section is empty.

Variables

View Source
var StopLookup = errors.New("stop lookup")

StopLookup is used as return value from a LookupFunc function to indicate that the lookup should be stopped.

Functions

This section is empty.

Types

type CSS

type CSS string

CSS is the css type in templates.

type CSSEnvStringer

type CSSEnvStringer interface {
	CSS(Env) CSS
}

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

type CSSStringer

type CSSStringer interface {
	CSS() CSS
}

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

type CombinedLoader

type CombinedLoader []PackageLoader

CombinedLoader combines multiple loaders into one loader.

func (CombinedLoader) Load

func (loaders CombinedLoader) Load(path string) (Package, error)

Load calls each loader's Load methods and returns as soon as a loader returns a package.

type CombinedPackage

type CombinedPackage []Package

CombinedPackage implements a Package by combining multiple packages into one package with name the name of the first package and as declarations the declarations of all packages.

The Lookup method calls the Lookup methods of each package in order and returns as soon as a package returns a not nil value.

func (CombinedPackage) Lookup

func (packages CombinedPackage) Lookup(name string) Declaration

Lookup calls the Lookup methods of each package in order and returns as soon as a combined package returns a declaration.

func (CombinedPackage) LookupFunc added in v0.48.0

func (packages CombinedPackage) LookupFunc(f LookupFunc) error

LookupFunc calls f for each package declaration stopping if f returns an error. Lookup order is undefined.

func (CombinedPackage) PackageName added in v0.48.0

func (packages CombinedPackage) PackageName() string

PackageName returns the package name of the first combined package.

type Declaration added in v0.48.0

type Declaration interface{}

Declaration represents a declaration.

for a variable: a pointer to the value of the variable
for a function: the function
for a type: its reflect.Type value
for a typed constant: its value as a string, boolean or numeric value
for an untyped constant: an UntypedStringConst, UntypedBooleanConst or UntypedNumericConst value
for a package: a Package value (used only for template globals)

type Declarations

type Declarations map[string]Declaration

Declarations represents a set of variables, constants, functions, types and packages declarations and can be used for template globals and package declarations.

The key is the declaration's name and the element is its value.

type DeclarationsPackage

type DeclarationsPackage struct {
	// Name of the package.
	Name string
	// Declarations of the package.
	Declarations Declarations
}

DeclarationsPackage implements Package given its name and declarations.

func (DeclarationsPackage) Lookup

func (p DeclarationsPackage) Lookup(name string) Declaration

Lookup returns the declaration named name in the package or nil if no such declaration exists.

func (DeclarationsPackage) LookupFunc added in v0.48.0

func (p DeclarationsPackage) LookupFunc(f LookupFunc) error

LookupFunc calls f for each package declaration stopping if f returns an error. Lookup order is undefined.

func (DeclarationsPackage) PackageName added in v0.48.0

func (p DeclarationsPackage) PackageName() string

PackageName returns the name of the package.

type Env

type Env interface {

	// Context returns the context of the execution.
	// It is the context passed as an option for execution.
	Context() context.Context

	// Exit exits the execution with the given status code. If the code is not
	// zero, the execution returns a scriggo.ExitError error with this code.
	// Deferred functions are not called and started goroutines are not
	// terminated.
	Exit(code int)

	// Fatal exits the execution and then panics with value v. Deferred
	// functions are not called and started goroutines are not terminated.
	Fatal(v interface{})

	// FilePath returns the path, relative to the root, of the current
	// executed file. If it is not called by the main goroutine, the
	// returned value is not significant.
	FilePath() string

	// Print calls the print built-in function with args as argument.
	Print(args ...interface{})

	// Println calls the println built-in function with args as argument.
	Println(args ...interface{})

	// TypeOf is like reflect.TypeOf but if v has a Scriggo type it returns
	// its Scriggo reflect type instead of the reflect type of the proxy.
	TypeOf(v reflect.Value) reflect.Type
}

Env represents an execution environment.

Each execution creates an Env value. This value is passed as the first argument to calls to native functions and methods that have Env as the type of the first parameter.

type EnvStringer

type EnvStringer interface {
	String(Env) string
}

EnvStringer is like fmt.Stringer where the String method takes an native.Env parameter.

type HTML

type HTML string

HTML is the html type in templates.

type HTMLEnvStringer

type HTMLEnvStringer interface {
	HTML(Env) HTML
}

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

type HTMLStringer

type HTMLStringer interface {
	HTML() HTML
}

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

type JS

type JS string

JS is the js type in templates.

type JSEnvStringer

type JSEnvStringer interface {
	JS(Env) JS
}

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

type JSON

type JSON string

JSON is the json type in templates.

type JSONEnvStringer

type JSONEnvStringer interface {
	JSON(Env) JSON
}

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

type JSONStringer

type JSONStringer interface {
	JSON() JSON
}

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

type JSStringer

type JSStringer interface {
	JS() JS
}

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

type LookupFunc added in v0.48.0

type LookupFunc func(name string, decl Declaration) error

LookupFunc is the type of the function called by Package.LookupFunc to read each package declaration. If the function returns an error, Package.LookupFunc stops and returns the error or nil if the error is StopLookup.

type Markdown

type Markdown string

Markdown is the markdown type in templates.

type MarkdownEnvStringer

type MarkdownEnvStringer interface {
	Markdown(Env) Markdown
}

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

type MarkdownStringer

type MarkdownStringer interface {
	Markdown() Markdown
}

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

type Package

type Package interface {

	// PackageName returns the name of the package.
	// It is a Go identifier but not the empty identifier.
	PackageName() string

	// Lookup searches for an exported declaration, named name, in the
	// package. If the declaration does not exist, it returns nil.
	Lookup(name string) Declaration

	// LookupFunc calls f for each package declaration stopping if f returns
	// an error. Lookup order is undefined.
	LookupFunc(f LookupFunc) error
}

Package represents a native package.

type PackageLoader

type PackageLoader interface {
	Load(path string) (Package, error)
}

PackageLoader represents a package loader; Load returns the native package with the given path.

If an error occurs it returns the error, if the package does not exist it returns a nil package.

type Packages

type Packages map[string]Package

Packages implements PackageLoader using a map of Package.

func (Packages) Load

func (pp Packages) Load(path string) (Package, error)

Load returns a Package.

type UntypedBooleanConst

type UntypedBooleanConst bool

UntypedBooleanConst represents an untyped boolean constant.

type UntypedNumericConst

type UntypedNumericConst string

UntypedNumericConst represents an untyped numeric constant.

type UntypedStringConst

type UntypedStringConst string

UntypedStringConst represents an untyped string constant.

Jump to

Keyboard shortcuts

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