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

33 lines
764 B
Go
Raw Normal View History

2017-06-26 21:36:05 +02:00
package chunks
import (
"io"
)
// 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)
if err != nil {
return err
}
return nil
}, nil
}
2017-06-27 13:43:42 +02:00
var tagDefinitions = map[string]TagDefinition{
"assign": assignTagDef,
}
func DefineTag(name string, td TagDefinition) {
tagDefinitions[name] = td
}
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
}