1
0
mirror of https://github.com/danog/liquid.git synced 2024-11-27 11:34:45 +01:00
liquid/chunks/definitions.go
Oliver Steele c4bd99bc2c Lint
2017-06-27 13:36:38 -04:00

33 lines
901 B
Go

package chunks
import (
"io"
)
// TagDefinition is a function that parses the tag arguments, and returns a renderer.
// TODO instead of using the bare function definition, use a structure that defines how to parse
type TagDefinition func(expr string) (func(io.Writer, Context) error, error)
// TODO parse during definition stage, not rendering stage
func assignTagDef(source string) (func(io.Writer, Context) error, error) {
return func(w io.Writer, ctx Context) error {
_, err := ctx.evaluateStatement("assign", source)
return err
}, nil
}
var tagDefinitions = map[string]TagDefinition{
"assign": assignTagDef,
}
// DefineTag creates a tag definition.
func DefineTag(name string, td TagDefinition) {
tagDefinitions[name] = td
}
// FindTagDefinition looks up a tag definition.
func FindTagDefinition(name string) (TagDefinition, bool) {
td, ok := tagDefinitions[name]
return td, ok
}