native

package
Version: v0.56.1 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2022 License: BSD-3-Clause Imports: 3 Imported by: 4

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 CombinedImporter added in v0.49.0

type CombinedImporter []Importer

CombinedImporter combines multiple importers into one importer.

func (CombinedImporter) Import added in v0.49.0

func (importers CombinedImporter) Import(path string) (ImportablePackage, error)

Import calls the Import method of each importer and returns as soon as an importer returns a package.

type CombinedPackage

type CombinedPackage []ImportablePackage

CombinedPackage implements an ImportablePackage 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 method 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 the LookupFunc method of each package in order. As soon as f returns StopLookup, LookupFunc returns. If the same declaration name is in multiple packages, f is only called with its first occurrence.

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: an ImportablePackage 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 Env

type Env interface {

	// CallPath returns the path, relative to the root, of the call site of
	// the caller function. If it is not called by the main goroutine, the
	// returned value is not significant.
	CallPath() string

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

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

	// 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{})

	// Stop stops the execution with the given error. Deferred functions are
	// not called and started goroutines are not terminated.
	Stop(err error)

	// 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 ImportablePackage added in v0.49.0

type ImportablePackage 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
}

ImportablePackage represents an importable package.

type Importer added in v0.49.0

type Importer interface {
	Import(path string) (ImportablePackage, error)
}

Importer represents a package importer; Import returns the native package with the given package path.

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

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 ImportablePackage.LookupFunc to read each package declaration. If the function returns an error, ImportablePackage.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 struct {
	// Name of the package.
	Name string
	// Declarations of the package.
	Declarations Declarations
}

Package implements ImportablePackage given its name and declarations.

func (Package) Lookup

func (p Package) Lookup(name string) Declaration

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

func (Package) LookupFunc added in v0.48.0

func (p Package) LookupFunc(f LookupFunc) error

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

func (Package) PackageName added in v0.48.0

func (p Package) PackageName() string

PackageName returns the name of the package.

type Packages

type Packages map[string]ImportablePackage

Packages implements Importer using a map of ImportablePackage.

func (Packages) Import added in v0.49.0

func (pp Packages) Import(path string) (ImportablePackage, error)

Import returns an ImportablePackage.

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