Esempio n. 1
0
File: for.go Progetto: get3w/get3w
func ForFactory(p *core.Parser, config *core.Configuration) (core.Tag, error) {
	name := p.ReadName()
	if len(name) == 0 {
		return nil, p.Error("Invalid variable name in for tag")
	}
	if p.SkipSpaces() != 'i' || p.Left() < 3 || p.Data[p.Position+1] != 'n' || !core.IsTokenEnd(p.Data[p.Position+2]) {
		return nil, p.Error("Expecting keyword 'in' after variable name in for tag")
	}
	p.ForwardBy(2)

	value, err := p.ReadValue()
	if err != nil {
		return nil, err
	}

	f := &For{
		Common:    NewCommon(),
		name:      name,
		keyName:   name + "[0]",
		valueName: name + "[1]",
		value:     value,
	}

	for {
		name := p.ReadName()
		if name == "" {
			break
		}
		if name == "limit" {
			if p.SkipUntil(':') != ':' {
				return nil, p.Error("Expecting ':' after limit in for tag")
			}
			p.Forward()
			limit, err := p.ReadValue()
			if err != nil {
				return nil, err
			}
			f.limit = limit
		} else if name == "offset" {
			if p.SkipUntil(':') != ':' {
				return nil, p.Error("Expecting ':' after offset in for tag")
			}
			p.Forward()
			offset, err := p.ReadValue()
			if err != nil {
				return nil, err
			}
			f.offset = offset
		} else if name == "reverse" {
			f.reverse = true
		} else {
			return nil, p.Error(fmt.Sprint("%q is an inknown modifier in for tag", name))
		}
	}
	p.SkipPastTag()
	return f, nil
}
Esempio n. 2
0
File: tag.go Progetto: get3w/get3w
func newTag(p *core.Parser, config *core.Configuration) (core.Tag, error) {
	p.ForwardBy(2) // skip the {%
	name := p.ReadName()
	factory, ok := Tags[name]
	if ok == false {
		return nil, nil
		//return nil, p.Error(fmt.Sprintf("unknown tag %q", name))
	}
	return factory(p, config)
}
Esempio n. 3
0
func newOutput(p *core.Parser) (core.Code, error) {
	p.ForwardBy(2) // skip the {{
	value, err := p.ReadValue()
	if err != nil || value == nil {
		return nil, err
	}

	filters, err := p.ReadFilters()
	if err != nil {
		return nil, err
	}
	p.SkipPastOutput()
	return &Output{value, filters}, nil
}
Esempio n. 4
0
File: raw.go Progetto: get3w/get3w
// Special handling to just quickly skip over it all
func RawFactory(p *core.Parser, config *core.Configuration) (core.Tag, error) {
	p.SkipPastTag()
	start := p.Position
	end := start
	for {
		_, markupType := p.ToMarkup(false)
		if markupType == core.TagMarkup {
			//tentative end is before the start of the endraw tag
			end = p.Position
			p.ForwardBy(2) // skip {%
			if name := p.ReadName(); name == "endraw" {
				p.SkipPastTag()
				break
			}
		} else if markupType == core.OutputMarkup {
			p.ForwardBy(2) // skip it
		} else {
			break
		}
	}
	return &Raw{p.Data[start:end]}, nil
}
Esempio n. 5
0
// Special handling to just quickly skip over it all
func HighlightFactory(p *core.Parser, config *core.Configuration) (core.Tag, error) {
	openTags := 1
	for {
		_, markupType := p.ToMarkup(false)
		if markupType == core.TagMarkup {
			p.ForwardBy(2) // skip {%
			if name := p.ReadName(); name == "highlight" {
				openTags++
			} else if name == "endhighlight" {
				openTags--
				if openTags == 0 {
					p.SkipPastTag()
					break
				}
			}
		} else if markupType == core.OutputMarkup {

			p.SkipPastTag()
		} else {
			break
		}
	}
	return highlight, nil
}