1
0
mirror of https://github.com/danog/liquid.git synced 2025-01-23 05:11:30 +01:00
liquid/chunks/definitions.go

33 lines
901 B
Go
Raw Normal View History

2017-06-26 15:36:05 -04:00
package chunks
import (
"io"
)
2017-06-27 13:36:38 -04:00
// TagDefinition is a function that parses the tag arguments, and returns a renderer.
2017-06-26 15:36:05 -04:00
// 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)
2017-06-27 13:36:38 -04:00
return err
2017-06-26 15:36:05 -04:00
}, nil
}
2017-06-27 07:43:42 -04:00
var tagDefinitions = map[string]TagDefinition{
"assign": assignTagDef,
}
2017-06-27 13:36:38 -04:00
// DefineTag creates a tag definition.
2017-06-27 07:43:42 -04:00
func DefineTag(name string, td TagDefinition) {
tagDefinitions[name] = td
}
2017-06-27 13:36:38 -04:00
// FindTagDefinition looks up a tag definition.
2017-06-26 15:36:05 -04:00
func FindTagDefinition(name string) (TagDefinition, bool) {
2017-06-27 07:43:42 -04:00
td, ok := tagDefinitions[name]
return td, ok
2017-06-26 15:36:05 -04:00
}