Beispiel #1
0
func TestTextTemplateRenderer(t *testing.T) {
	a := librenderer.AssetsFunc(func(name string) ([]byte, error) {
		return []byte(`<p>` + name + ` {{ .Name }}</p>`), nil
	})
	r := &TextTemplateRenderer{Assets: a}

	if ret, err := r.Render(`hello`, librenderer.M{`Name`: `<i>nyarla</i>`}); err != nil {
		t.Fatal(err)
	} else {
		if string(ret) != `<p>hello <i>nyarla</i></p>` {
			t.Fatal(`failed to render html template `, string(ret))
		}
	}
}
Beispiel #2
0
func TestDuktapeRenderer(t *testing.T) {
	assets := librenderer.AssetsFunc(func(name string) ([]byte, error) {
		return []byte(`
			function renderString(props) {
				return "hello, " + props.name ;
			}
		`), nil
	})

	r := &DuktapeRenderer{
		Assets:    assets,
		AssetName: ``,
	}

	defer r.Close()

	if ret, err := r.Render(`renderString`, librenderer.M{`name`: `nyarla`}); err != nil {
		t.Fatal(err)
	} else {
		if string(ret) != `hello, nyarla` {
			t.Fatal(`assert failed for renderer result: `, string(ret))
		}
	}
}