1
0
mirror of https://github.com/danog/liquid.git synced 2024-12-12 17:47:24 +01:00
liquid/chunks/definitions.go
2017-06-27 07:43:42 -04:00

33 lines
764 B
Go

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
}
var tagDefinitions = map[string]TagDefinition{
"assign": assignTagDef,
}
func DefineTag(name string, td TagDefinition) {
tagDefinitions[name] = td
}
func FindTagDefinition(name string) (TagDefinition, bool) {
td, ok := tagDefinitions[name]
return td, ok
}