1
0
mirror of https://github.com/danog/liquid.git synced 2024-11-27 13:34:46 +01:00
liquid/chunks/definitions.go

33 lines
901 B
Go
Raw Normal View History

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