Beispiel #1
0
// Creates an include tag
func IncludeFactory(p *core.Parser, config *core.Configuration) (core.Tag, error) {
	value, err := p.ReadValue()
	if err != nil {
		return nil, err
	}
	if value == nil {
		return nil, p.Error("Invalid include value")
	}
	p.SkipPastTag()
	return &Include{value, config.GetIncludeHandler()}, nil
}
Beispiel #2
0
func extractTokens(parser *core.Parser, container core.Tag, config *core.Configuration) error {
	stack := []core.Tag{container}
	preserveWhiteSpace := config.GetPreserveWhitespace()
	for parser.HasMore() {
		pre, markupType := parser.ToMarkup(preserveWhiteSpace)
		if len(pre) > 0 {
			container.AddCode(newLiteral(pre))
		}
		if markupType == core.OutputMarkup {
			code, err := newOutput(parser)
			if err != nil {
				return err
			}
			if code != nil {
				container.AddCode(code)
			}
		} else if markupType == core.TagMarkup {
			tag, err := newTag(parser, config)
			if err != nil {
				return err
			}
			switch tag.Type() {
			case core.ContainerTag, core.LoopTag:
				container.AddCode(tag)
				container = tag
				stack = append(stack, container)
			case core.EndTag:
				l := len(stack) - 1
				container = stack[l]
				if tag.Name() != container.Name() {
					return parser.Error(fmt.Sprintf("end tag \"end%s\" cannot terminate %q", tag.Name(), container.Name()))
				}
				stack = stack[0:l]
				container = stack[l-1]
				parser.SkipPastTag()
			case core.SiblingTag:
				if err := stack[len(stack)-1].AddSibling(tag); err != nil {
					return err
				}
				container = tag
			case core.StandaloneTag:
				container.AddCode(tag)
			}
		} else {
			break
		}
	}
	return nil
}
Beispiel #3
0
// Parse the bytes into a Liquid template
func Parse(data []byte, config *core.Configuration) (*Template, error) {
	if config == nil {
		config = defaultConfig
	}
	cache := config.GetCache()
	if cache == nil {
		return buildTemplate(data, config)
	}
	hasher := sha1.New()
	hasher.Write(data)
	key := fmt.Sprintf("%x", hasher.Sum(nil))

	template := cache.Get(key)
	if template == nil {
		var err error
		template, err = buildTemplate(data, config)
		if err != nil {
			return nil, err
		}
		cache.Set(key, template)
	}
	return template.(*Template), nil
}
Beispiel #4
0
// Entry into the fluent-configuration
func Configure() *core.Configuration {
	c := new(core.Configuration)
	return c.SetInternalBuffer(512, 4096).Cache(TemplateCache)
}
Beispiel #5
0
// Entry into the fluent-configuration
func Configure() *core.Configuration {
	c := new(core.Configuration)
	return c.Cache(TemplateCache)
}