directives

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2021 License: GPL-3.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const ELEMENT_COUNT = "__idx__"

actually not globals, as they are only available inside the template scope

View Source
const ELEMENT_COUNT_FOLDED = "__idxf__"
View Source
const FILE = "__file__"
View Source
const NCHILDREN = "__nchildren__"
View Source
const NSIBLINGS = "__nsiblings__"
View Source
const PARENT_STYLE = "__pstyle__"
View Source
const URL = "__url__"

Variables

View Source
var (
	NO_ALIASING = false
	VERBOSITY   = 0
)
View Source
var IGNORE_UNSET_URLS = false
View Source
var MATH_FONT = "math"
View Source
var MATH_FONT_FAMILY = "math, FreeSerif"
View Source
var MATH_FONT_URL = "math.woff2"
View Source
var RELATIVE = true

Functions

func AddTemplate

func AddTemplate(scope Scope, node Node, tag *tokens.Tag) error

doesnt change the node

func AddVar

func AddVar(scope Scope, node Node, tag *tokens.Tag) error

doesnt change the node

func AppendToBlock

func AppendToBlock(scope Scope, node *TemplateNode, tag *tokens.Tag) error

func AssertValidVar

func AssertValidVar(nameToken *tokens.String) error

func BuildDirective

func BuildDirective(scope Scope, node Node, tag *tokens.Tag) error

func BuildFile

func BuildFile(cache *FileCache, path string, isRoot bool, parameters *tokens.Parens) (*FileScope, *RootNode, error)

also used by NewRoot abs path, so we can use this to cache the import results incoming parameters should be evaluated

func BuildJSON

func BuildJSON(path string, ctx context.Context) (tokens.Token, error)

func BuildJSONFile

func BuildJSONFile(input string, outputPath string) error

func BuildSVG

func BuildSVG(scope Scope, node Node, tag *tokens.Tag) error

func BuildTag

func BuildTag(scope Scope, node Node, tag *tokens.Tag) error

func BuildTemplate

func BuildTemplate(scope Scope, node Node, tag *tokens.Tag) error

func EvalBlock

func EvalBlock(scope Scope, node Node, tag *tokens.Tag) error

func Export

func Export(scope Scope, node Node, tag *tokens.Tag) error

doesnt change the node, but node can be used for elementCount

func FinalizeRoot

func FinalizeRoot(node *RootNode) (*tree.Root, error)

func For

func For(scope Scope, node Node, tag *tokens.Tag) error

func ForceNewViewFileScriptRegistration

func ForceNewViewFileScriptRegistration(cache *FileCache)

in jspp the directives module isn't automatically included, so we need to force (which includes the above lines actually, so this happens twice)

func GetActiveURL

func GetActiveURL(ctx context.Context) (*tokens.String, error)

func GetDefine

func GetDefine(k string) *tokens.String

func HasDefine

func HasDefine(k string) bool

func HasGlobal

func HasGlobal(k string) bool

func IfElse

func IfElse(scope Scope, node Node, tag *tokens.Tag) error

func Import

func Import(scope Scope, node Node, tag *tokens.Tag) error

doesnt change the node, but node can be used for elementCount

func IsDeferringTemplateNode

func IsDeferringTemplateNode(node Node) bool

func IsDirective

func IsDirective(key string) bool

func IsTopLevel

func IsTopLevel(scope Scope) bool

func IsUniqueOpTargetName

func IsUniqueOpTargetName(t string) bool

func Math

func Math(scope Scope, node Node, tag *tokens.Tag) error

func NewRoot

func NewRoot(cache *FileCache, path string) (*tree.Root, error)

func NewUniqueOpTargetName

func NewUniqueOpTargetName() string

func NewViewFileScript

func NewViewFileScript(cache *FileCache, absPath string) (scripts.FileScript, error)

func Print

func Print(scope Scope, node Node, tag *tokens.Tag) error

func RegisterBuildStyle

func RegisterBuildStyle(fn BuildStyleFunc) bool

func RegisterDefine

func RegisterDefine(k, v string)

func RegisterURL

func RegisterURL(path string, url string)

path is src path

func ReplaceBlockChildren

func ReplaceBlockChildren(scope Scope, node *TemplateNode, tag *tokens.Tag) error

func Script

func Script(scope Scope, node Node, tag *tokens.Tag) error

scripts are usefull for internet explorer fallback

func SetActiveURL

func SetActiveURL(url string)

func SetFile

func SetFile(scope Scope, path string, ctx context.Context)

func Style

func Style(scope Scope, node Node, tag *tokens.Tag) error

func Switch

func Switch(scope Scope, node Node, tag *tokens.Tag) error

func TOC

func TOC(scope Scope, node Node, tag *tokens.Tag) error

func UnsetActiveURL

func UnsetActiveURL()

func WriteJSONToFile

func WriteJSONToFile(token tokens.Token, path string) error

Types

type AppendOp

type AppendOp struct {
	OperationData
	// contains filtered or unexported fields
}

func NewAppendToDefaultOp

func NewAppendToDefaultOp(scope Scope, tags []*tokens.Tag) (*AppendOp, error)

func (*AppendOp) Apply

func (op *AppendOp) Apply(origScope Scope, node Node, childTokens []*tokens.Tag) error

func (*AppendOp) Context

func (op *AppendOp) Context() context.Context

func (*AppendOp) Merge

func (op *AppendOp) Merge(other_ Operation) (Operation, error)

type BranchScope

type BranchScope struct {
	ScopeData
}

BranchScope sends to exports to filescope (regular scopedata gives error)

func (*BranchScope) SetTemplate

func (s *BranchScope) SetTemplate(key string, d Template) error

func (*BranchScope) SetVar

func (s *BranchScope) SetVar(key string, v functions.Var) error

type BuildStyleFunc

type BuildStyleFunc func(d *tokens.StringDict, node Node) (string, error)
var BuildStyle BuildStyleFunc = nil

type CachedScope

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

type Directive

type Directive func(scope Scope, node Node, tag *tokens.Tag) error

type FileCache

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

func NewFileCache

func NewFileCache() *FileCache

func (*FileCache) Clear

func (c *FileCache) Clear()

func (*FileCache) Get

func (c *FileCache) Get(path string, parameters *tokens.Parens) (*FileScope, *RootNode)

func (*FileCache) IsCached

func (c *FileCache) IsCached(path string, parameters *tokens.Parens) bool

func (*FileCache) List added in v0.6.0

func (c *FileCache) List() []string

func (*FileCache) Remove added in v0.6.0

func (c *FileCache) Remove(paths []string)

func (*FileCache) Set

func (c *FileCache) Set(path string, parameters *tokens.Parens, scope *FileScope, node *RootNode)

type FileScope

type FileScope struct {
	ScopeData
	// contains filtered or unexported fields
}

func NewFileScope

func NewFileScope(permissive bool, cache *FileCache) *FileScope

func (*FileScope) GetCache

func (s *FileScope) GetCache() *FileCache

func (*FileScope) NotifyRelativeURL added in v0.6.0

func (s *FileScope) NotifyRelativeURL(path string)

func (*FileScope) PagesWithRelURLs added in v0.6.0

func (s *FileScope) PagesWithRelURLs() []string

func (*FileScope) Permissive

func (s *FileScope) Permissive() bool

type MathNode

type MathNode struct {
	NodeData
}

func NewMathNode

func NewMathNode(parentTag tree.Tag, parentNode Node) *MathNode

func (*MathNode) BuildMathPath

func (n *MathNode) BuildMathPath(d string, ctx context.Context) error

func (*MathNode) BuildMathText

func (n *MathNode) BuildMathText(x float64, y float64, fontSize float64, value string,
	ctx context.Context) error

func (*MathNode) NewSubScope

func (n *MathNode) NewSubScope() math.SubScope

func (*MathNode) Transform

func (n *MathNode) Transform(x, y, sx, sy float64)

type Node

type Node interface {
	Parent() Node
	Name() string
	Type() NodeType

	AppendChild(tree.Tag) error

	PopOp(id string) (Operation, error)      // for application
	GetBlockTarget(block *tokens.Tag) string // empty if not found
	SetBlockTarget(block *tokens.Tag, target string)

	SearchStyle(scope tokens.Scope, key *tokens.String, ctx context.Context) (tokens.Token, error)
	// register style sheet, which can be used by
	RegisterStyleSheet(sheet StyleSheet) // the wraps of registered style sheets must be
	// contains filtered or unexported methods
}

styleTree and elementCount fit the node tree better than the scope tree

type NodeData

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

func NewNode

func NewNode(tag tree.Tag, parent Node) *NodeData

func (*NodeData) AppendChild

func (n *NodeData) AppendChild(child tree.Tag) error

func (*NodeData) Context

func (n *NodeData) Context() context.Context

func (*NodeData) GetBlockTarget

func (n *NodeData) GetBlockTarget(block *tokens.Tag) string

func (*NodeData) Name

func (n *NodeData) Name() string

func (*NodeData) Parent

func (n *NodeData) Parent() Node

func (*NodeData) PopOp

func (n *NodeData) PopOp(id string) (Operation, error)

func (*NodeData) RegisterStyleSheet

func (n *NodeData) RegisterStyleSheet(sheet StyleSheet)

func (*NodeData) SearchStyle

func (n *NodeData) SearchStyle(scope tokens.Scope, key *tokens.String, ctx context.Context) (tokens.Token, error)

func (*NodeData) SetBlockTarget

func (n *NodeData) SetBlockTarget(block *tokens.Tag, target string)

func (*NodeData) Type

func (n *NodeData) Type() NodeType

type NodeType

type NodeType int
const (
	HTML NodeType = iota
	SVG
)

type Operation

type Operation interface {
	Target() string
	SetTarget(t string)
	Merge(other Operation) (Operation, error)
	Context() context.Context
	Apply(origScope Scope, newNode Node, childTokens []*tokens.Tag) error
	Popped() bool
	SetPopped()
}

type OperationData

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

func (*OperationData) Popped

func (op *OperationData) Popped() bool

func (*OperationData) SetPopped

func (op *OperationData) SetPopped()

func (*OperationData) SetTarget

func (op *OperationData) SetTarget(t string)

func (*OperationData) Target

func (op *OperationData) Target() string

type PStyle

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

implements tokens.Token interface

func (*PStyle) Context

func (t *PStyle) Context() context.Context

func (*PStyle) Dump

func (t *PStyle) Dump(indent string) string

func (*PStyle) Eval

func (t *PStyle) Eval(scope tokens.Scope) (tokens.Token, error)

func (*PStyle) EvalLazy

func (t *PStyle) EvalLazy(tag tokens.FinalTag) (tokens.Token, error)

func (*PStyle) Get

func (t *PStyle) Get(scope tokens.Scope, idx_ tokens.Token, ctx context.Context) (tokens.Token, error)

func (*PStyle) IsSame

func (t *PStyle) IsSame(other_ tokens.Token) bool

type ReplaceChildrenOp

type ReplaceChildrenOp struct {
	OperationData
	// contains filtered or unexported fields
}

func (*ReplaceChildrenOp) Apply

func (op *ReplaceChildrenOp) Apply(origScope Scope, node Node, childTokens []*tokens.Tag) error

func (*ReplaceChildrenOp) Context

func (op *ReplaceChildrenOp) Context() context.Context

func (*ReplaceChildrenOp) Merge

func (op *ReplaceChildrenOp) Merge(other_ Operation) (Operation, error)

type RootNode

type RootNode struct {
	NodeData
	// contains filtered or unexported fields
}

func NewRootNode

func NewRootNode(tag tree.Tag, t NodeType) *RootNode

func (*RootNode) GetBlockTarget

func (n *RootNode) GetBlockTarget(block *tokens.Tag) string

func (*RootNode) PopOp

func (n *RootNode) PopOp(id string) (Operation, error)

func (*RootNode) RegisterStyleSheet

func (n *RootNode) RegisterStyleSheet(sheet StyleSheet)

func (*RootNode) SearchStyle

func (n *RootNode) SearchStyle(scope tokens.Scope, key *tokens.String, ctx context.Context) (tokens.Token, error)

func (*RootNode) SetBlockTarget

func (n *RootNode) SetBlockTarget(block *tokens.Tag, target string)

func (*RootNode) Type

func (n *RootNode) Type() NodeType

type SVGNode

type SVGNode struct {
	NodeData
}

func NewSVGNode

func NewSVGNode(tag tree.Tag, parent Node) *SVGNode

func (*SVGNode) Type

func (n *SVGNode) Type() NodeType

type Scope

type Scope interface {
	Parent() Scope
	Permissive() bool
	NotifyRelativeURL(path string)

	HasVar(key string) bool
	GetVar(key string) functions.Var
	SetVar(key string, v functions.Var) error

	HasTemplate(key string) bool
	GetTemplate(key string) Template
	SetTemplate(key string, d Template) error

	ListValidVarNames() []string

	// implements tokens.Scope
	Eval(key string, args *tokens.Parens, ctx context.Context) (tokens.Token, error)

	GetCache() *FileCache
}

func NewBranchScope

func NewBranchScope(parent Scope) Scope

func NewSubScope

func NewSubScope(parent Scope) Scope

type ScopeData

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

func (*ScopeData) Eval

func (scope *ScopeData) Eval(key string, args *tokens.Parens,
	ctx context.Context) (tokens.Token, error)

func (*ScopeData) GetCache

func (scope *ScopeData) GetCache() *FileCache

func (*ScopeData) GetTemplate

func (scope *ScopeData) GetTemplate(key string) Template

func (*ScopeData) GetVar

func (scope *ScopeData) GetVar(key string) functions.Var

func (*ScopeData) HasTemplate

func (scope *ScopeData) HasTemplate(key string) bool

func (*ScopeData) HasVar

func (scope *ScopeData) HasVar(key string) bool

func (*ScopeData) ListValidVarNames

func (scope *ScopeData) ListValidVarNames() []string

including builtin functions

func (*ScopeData) NotifyRelativeURL added in v0.6.0

func (s *ScopeData) NotifyRelativeURL(path string)

func (*ScopeData) Parent

func (scope *ScopeData) Parent() Scope

func (*ScopeData) Permissive

func (s *ScopeData) Permissive() bool

func (*ScopeData) SetTemplate

func (scope *ScopeData) SetTemplate(key string, d Template) error

func (*ScopeData) SetVar

func (scope *ScopeData) SetVar(key string, v functions.Var) error

func (*ScopeData) Sync

func (scope *ScopeData) Sync(dst Scope, keepAutoVars, keepImports, asImports bool, prefix string) error

func (*ScopeData) SyncFiltered

func (scope *ScopeData) SyncFiltered(dst Scope, keepAutoVars, keepImports, asImports bool, prefix string, names *tokens.StringDict) error

func (*ScopeData) SyncPackage

func (scope *ScopeData) SyncPackage(dst Scope, keepAutoVars, keepImports, asImports bool, prefix string) error

type StyleSheet

type StyleSheet interface {
	ApplyExtensions(root *tree.Root) (*tree.Root, error)
}

type Template

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

type TemplateNode

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

func GetTemplateNode

func GetTemplateNode(node Node) *TemplateNode

func NewTemplateNode

func NewTemplateNode(parent Node, ctx context.Context) *TemplateNode

func (*TemplateNode) AppendChild

func (n *TemplateNode) AppendChild(child tree.Tag) error

func (*TemplateNode) AppendToDefault

func (n *TemplateNode) AppendToDefault(scope Scope, tag *tokens.Tag) error

func (*TemplateNode) AssertAllOperationsDone

func (n *TemplateNode) AssertAllOperationsDone(ctx context.Context) error

func (*TemplateNode) GetBlockTarget

func (n *TemplateNode) GetBlockTarget(block *tokens.Tag) string

func (*TemplateNode) Name

func (n *TemplateNode) Name() string

func (*TemplateNode) Parent

func (n *TemplateNode) Parent() Node

func (*TemplateNode) PopOp

func (n *TemplateNode) PopOp(target string) (Operation, error)

func (*TemplateNode) PushOp

func (n *TemplateNode) PushOp(op Operation) error

func (*TemplateNode) RegisterStyleSheet

func (n *TemplateNode) RegisterStyleSheet(sheet StyleSheet)

func (*TemplateNode) SearchStyle

func (n *TemplateNode) SearchStyle(scope tokens.Scope, key *tokens.String, ctx context.Context) (tokens.Token, error)

func (*TemplateNode) SetBlockTarget

func (n *TemplateNode) SetBlockTarget(block *tokens.Tag, target string)

func (*TemplateNode) StartDeferral

func (n *TemplateNode) StartDeferral()

func (*TemplateNode) StopDeferral

func (n *TemplateNode) StopDeferral()

func (*TemplateNode) Type

func (n *TemplateNode) Type() NodeType

type URINode

type URINode struct {
	NodeData
	// contains filtered or unexported fields
}

func NewURINode

func NewURINode() *URINode

a URINode doesnt have a parent

func (*URINode) AppendChild

func (n *URINode) AppendChild(tag tree.Tag) error

func (*URINode) GetBlockTarget

func (n *URINode) GetBlockTarget(block *tokens.Tag) string

func (*URINode) PopOp

func (n *URINode) PopOp(id string) (Operation, error)

func (*URINode) SetBlockTarget

func (n *URINode) SetBlockTarget(block *tokens.Tag, target string)

func (*URINode) Type

func (n *URINode) Type() NodeType

type ViewArray

type ViewArray struct {
	ViewVariableData
	// contains filtered or unexported fields
}

func (*ViewArray) Dump

func (v *ViewArray) Dump(indent string) string

func (*ViewArray) GetValue

func (v *ViewArray) GetValue() values.Value

func (*ViewArray) Write

func (v *ViewArray) Write() string

type ViewBool

type ViewBool struct {
	ViewVariableData
	// contains filtered or unexported fields
}

func (*ViewBool) Dump

func (v *ViewBool) Dump(indent string) string

func (*ViewBool) GetValue

func (v *ViewBool) GetValue() values.Value

func (*ViewBool) Write

func (v *ViewBool) Write() string

type ViewColor

type ViewColor struct {
	ViewVariableData
	// contains filtered or unexported fields
}

func (*ViewColor) Dump

func (v *ViewColor) Dump(indent string) string

func (*ViewColor) GetValue

func (v *ViewColor) GetValue() values.Value

func (*ViewColor) Write

func (v *ViewColor) Write() string

type ViewFileScript

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

func (*ViewFileScript) Dependencies

func (s *ViewFileScript) Dependencies() []files.PathLang

func (*ViewFileScript) EvalTypes

func (s *ViewFileScript) EvalTypes() error

func (*ViewFileScript) Hide

func (s *ViewFileScript) Hide()

func (*ViewFileScript) Module

func (s *ViewFileScript) Module() js.Module

func (*ViewFileScript) Path

func (s *ViewFileScript) Path() string

func (*ViewFileScript) ResolveActivity

func (s *ViewFileScript) ResolveActivity(usage js.Usage) error

func (*ViewFileScript) ResolveNames

func (s *ViewFileScript) ResolveNames(scope js.GlobalScope) error

no need to add to the scope

func (*ViewFileScript) UniqueEntryPointNames

func (s *ViewFileScript) UniqueEntryPointNames(ns js.Namespace) error

func (*ViewFileScript) UniqueNames

func (s *ViewFileScript) UniqueNames(ns js.Namespace) error

func (*ViewFileScript) UniversalNames

func (s *ViewFileScript) UniversalNames(ns js.Namespace) error

func (*ViewFileScript) Walk

func (s *ViewFileScript) Walk(fn func(p string, obj interface{}) error) error

func (*ViewFileScript) Write

func (s *ViewFileScript) Write() (string, error)

type ViewInt

type ViewInt struct {
	ViewVariableData
	// contains filtered or unexported fields
}

func (*ViewInt) Dump

func (v *ViewInt) Dump(indent string) string

func (*ViewInt) GetValue

func (v *ViewInt) GetValue() values.Value

func (*ViewInt) Write

func (v *ViewInt) Write() string

type ViewModule

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

use this to import ui variables into script files

func (*ViewModule) Context

func (m *ViewModule) Context() context.Context

func (*ViewModule) GetExportedVariable

func (m *ViewModule) GetExportedVariable(gs js.GlobalScope, name string,
	ctx context.Context) (js.Variable, error)

func (*ViewModule) MinimalDependencies

func (m *ViewModule) MinimalDependencies(allModules map[string]js.Module) []string

func (*ViewModule) SymbolDependencies

func (m *ViewModule) SymbolDependencies(allModules map[string]js.Module, name string) []string

type ViewNull

type ViewNull struct {
	ViewVariableData
}

used as fallback when js.TARGET != "browser"

func (*ViewNull) Dump

func (v *ViewNull) Dump(indent string) string

func (*ViewNull) GetValue

func (v *ViewNull) GetValue() values.Value

func (*ViewNull) Write

func (v *ViewNull) Write() string

type ViewNumber

type ViewNumber struct {
	ViewVariableData
	// contains filtered or unexported fields
}

func (*ViewNumber) Dump

func (v *ViewNumber) Dump(indent string) string

func (*ViewNumber) GetValue

func (v *ViewNumber) GetValue() values.Value

func (*ViewNumber) Write

func (v *ViewNumber) Write() string

type ViewObject

type ViewObject struct {
	ViewVariableData
	// contains filtered or unexported fields
}

func (*ViewObject) Dump

func (v *ViewObject) Dump(indent string) string

func (*ViewObject) GetValue

func (v *ViewObject) GetValue() values.Value

func (*ViewObject) Write

func (v *ViewObject) Write() string

type ViewString

type ViewString struct {
	ViewVariableData
	// contains filtered or unexported fields
}

func (*ViewString) Dump

func (v *ViewString) Dump(indent string) string

func (*ViewString) GetValue

func (v *ViewString) GetValue() values.Value

func (*ViewString) Write

func (v *ViewString) Write() string

type ViewVariable

type ViewVariable interface {
	js.Variable
	Write() string
}

type ViewVariableData

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

func (*ViewVariableData) Constant

func (v *ViewVariableData) Constant() bool

func (*ViewVariableData) Context

func (v *ViewVariableData) Context() context.Context

func (*ViewVariableData) GetObject

func (v *ViewVariableData) GetObject() interface{}

func (*ViewVariableData) Name

func (v *ViewVariableData) Name() string

func (*ViewVariableData) Rename

func (v *ViewVariableData) Rename(newName string)

func (*ViewVariableData) SetConstant

func (v *ViewVariableData) SetConstant()

func (*ViewVariableData) SetObject

func (v *ViewVariableData) SetObject(interface{})

func (*ViewVariableData) SetValue

func (v *ViewVariableData) SetValue(_ values.Value)

Jump to

Keyboard shortcuts

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