native

package
v0.47.0 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2021 License: BSD-3-Clause Imports: 2 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

This section is empty.

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) DeclarationNames

func (packages CombinedPackage) DeclarationNames() []string

DeclarationNames returns all declaration names in all packages.

func (CombinedPackage) Lookup

func (packages CombinedPackage) Lookup(declName string) interface{}

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

func (CombinedPackage) Name

func (packages CombinedPackage) Name() string

Name returns the name of the first combined package.

type Declarations

type Declarations map[string]interface{}

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

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 DeclarationsPackage

type DeclarationsPackage struct {
	// Package name.
	PkgName string
	// Package declarations.
	Declarations Declarations
}

DeclarationsPackage implements Package given its name and Declarations.

func (*DeclarationsPackage) DeclarationNames

func (p *DeclarationsPackage) DeclarationNames() []string

DeclarationNames returns all package declaration names.

func (*DeclarationsPackage) Lookup

func (p *DeclarationsPackage) Lookup(declName string) interface{}

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

func (*DeclarationsPackage) Name

func (p *DeclarationsPackage) Name() string

Name returns the package name.

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 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 {

	// Name returns the package's name.
	Name() string

	// Lookup searches for an exported declaration, named declName, in the
	// package. If the declaration does not exist, it returns nil.
	//
	// For a variable returns a pointer to the variable, for a function
	// returns the function, for a type returns its reflect.Type value, for a
	// typed constant returns its value and for an untyped constant returns a
	// UntypedStringConst, UntypedBooleanConst or UntypedNumericConst value.
	Lookup(declName string) interface{}

	// DeclarationNames returns the exported declaration names in the package.
	DeclarationNames() []string
}

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