예제 #1
0
// DefaultParser sets up and assigns the default parser to be used by Xslate.
func DefaultParser(tx *Xslate, args Args) error {
	syntax, ok := args.Get("Syntax")
	if !ok {
		syntax = "TTerse"
	}

	switch syntax {
	case "TTerse":
		tx.Parser = tterse.New()
	case "Kolon", "Kolonish":
		tx.Parser = kolonish.New()
	default:
		return errors.New("sytanx '" + syntax.(string) + "' is not available")
	}
	return nil
}
예제 #2
0
파일: xslate.go 프로젝트: shawnps/go-xslate
// DefaultParser sets up and assigns the default parser to be used by Xslate.
func DefaultParser(tx *Xslate, args Args) error {
	syntax, ok := args.Get("Syntax")
	if !ok {
		syntax = "TTerse"
	}

	switch syntax {
	case "TTerse":
		tx.Parser = tterse.New()
	case "Kolon", "Kolonish":
		tx.Parser = kolonish.New()
	default:
		return fmt.Errorf("error: Syntax '%s' not available", syntax)
	}
	return nil
}
예제 #3
0
func compile(t *testing.T, tmpl string) *vm.ByteCode {
	p := tterse.New()
	ast, err := p.ParseString(tmpl, tmpl)
	if err != nil {
		t.Fatalf("Failed to parse template: %s", err)
	}

	c := New()
	bc, err := c.Compile(ast)
	if err != nil {
		t.Fatalf("Failed to compile ast: %s", err)
	}

	t.Logf("-> %+v", bc)

	return bc
}
예제 #4
0
func TestCompile_Wrapper(t *testing.T) {
	c := test.NewCtx(t)
	defer c.Cleanup()

	index := c.File("index.tx")
	index.WriteString(`[% WRAPPER "wrapper.tx" %]Hello[% END %]`)
	c.File("wrapper.tx").WriteString(`Hello, [% content %], Hello`)

	p := tterse.New()
	ast, err := p.Parse("index.tx", index.Read())
	if err != nil {
		t.Fatalf("Failed to parse template: %s", err)
	}

	comp := New()
	bc, err := comp.Compile(ast)
	if err != nil {
		t.Fatalf("Failed to compile ast: %s", err)
	}

	t.Logf("-> %+v", bc)
}