Documentation ¶
Overview ¶
Package template contains functions for rendering templates.
Index ¶
- func RenderAll(templatePath string, excludedPaths []string, outputPath string, values Scope) error
- type ErrPathEmpty
- type ErrRenderFail
- type ErrScopeMergeConflict
- type Scope
- func (scope Scope) AssocAt(path string, value interface{}, force bool) error
- func (scope Scope) Flat() Scope
- func (scope Scope) GetScopeAt(path string) (Scope, error)
- func (scope Scope) Merge(other Scope) Scope
- func (scope Scope) Replace(other Scope)
- func (scope Scope) UpdateScopeAt(path string, f func(Scope) Scope, force bool) error
- type Template
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ErrPathEmpty ¶ added in v0.0.11
type ErrPathEmpty struct{}
func (ErrPathEmpty) Error ¶ added in v0.0.11
func (e ErrPathEmpty) Error() string
type ErrRenderFail ¶ added in v0.0.9
type ErrRenderFail struct { }
func (ErrRenderFail) Error ¶ added in v0.0.9
func (e ErrRenderFail) Error() string
type ErrScopeMergeConflict ¶
type ErrScopeMergeConflict struct {
Path string
}
ErrScopeMergeConflict indicates that a conflict occurred when merging two scopes at the specified path.
func (ErrScopeMergeConflict) Error ¶
func (e ErrScopeMergeConflict) Error() string
type Scope ¶
type Scope map[interface{}]interface{}
Scope represents a single lexical value scope. Scopes can be nested.
func (Scope) AssocAt ¶ added in v0.0.11
AssocAt modifies scope by setting value at the provided path. It will create scopes along the way if they don't exist. In case the value pointed by the path already exists and cannot be interpreted as a Scope (see ParseScope), the function signals ErrScopeMergeConflict unless force is true. If that's the case, the value is overridden.
func (Scope) Flat ¶
Example ¶
package main import ( "fmt" "github.com/tooploox/oya/pkg/template" ) func main() { scope := template.Scope{ "foo": map[interface{}]interface{}{ "bar": "baz", "qux": []interface{}{ "1", "2", 3, }, "abc": map[string]interface{}{ "123": true, }, }, } flattened := scope.Flat() fmt.Println("foo.bar:", flattened["foo.bar"]) _, ok := flattened["foo"] fmt.Println("foo exists?", ok) fmt.Println("foo.qux.0:", flattened["foo.qux.0"]) fmt.Println("foo.qux.1:", flattened["foo.qux.1"]) fmt.Println("foo.qux.2:", flattened["foo.qux.2"]) fmt.Println("foo.abc.123:", flattened["foo.abc.123"]) }
Output: foo.bar: baz foo exists? false foo.qux.0: 1 foo.qux.1: 2 foo.qux.2: 3 foo.abc.123: true
func (Scope) GetScopeAt ¶
GetScopeAt returns scope at the specified path. If path doesn't exist or points to a value that cannot be interpreted as a Scope (see ParseScope), the function signals an error.
func (Scope) Merge ¶
Merge combines two scopes together. If a key appears in both scopes, the other scope wins.
func (Scope) Replace ¶
Replace replaces contents of this scope with keys and values of the other one.
func (Scope) UpdateScopeAt ¶
UpdateScopeAt transforms a scope pointed to by the path (e.g. "foo.bar.baz"). It will create scopes along the way if they don't exist. In case the value pointed by the path already exists and cannot be interpreted as a Scope (see ParseScope), the function signals ErrScopeMergeConflict unless force is true. If that's the case, the value is overridden.