From bd8889447ae933e967c599e60c54b8a9296de8d0 Mon Sep 17 00:00:00 2001 From: Stan Rozenraukh Date: Tue, 23 Jan 2024 11:37:07 -0500 Subject: [PATCH] feat: MustMemo --- memo.go | 12 ++++++++++++ memo_test.go | 29 +++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 memo.go create mode 100644 memo_test.go diff --git a/memo.go b/memo.go new file mode 100644 index 0000000..9ba13ba --- /dev/null +++ b/memo.go @@ -0,0 +1,12 @@ +package veun + +import "context" + +func MustMemo(v AsView) Raw { + out, err := Render(context.Background(), v) + if err != nil { + panic(err) + } + + return Raw(out) +} diff --git a/memo_test.go b/memo_test.go new file mode 100644 index 0000000..e755745 --- /dev/null +++ b/memo_test.go @@ -0,0 +1,29 @@ +package veun_test + +import ( + "context" + "html/template" + "testing" + + "github.com/alecthomas/assert/v2" + + "github.com/stanistan/veun" + "github.com/stanistan/veun/el" +) + +func TestMemo(t *testing.T) { + var ( + in = el.Div().InnerText("memo") + view = veun.MustMemo(in) + ) + + assert.Equal(t, veun.Raw(`
memo
`), view) + + html, err := veun.Render(context.Background(), view) + assert.NoError(t, err) + assert.Equal(t, template.HTML(`
memo
`), html) + + html, err = veun.Render(context.Background(), in) + assert.NoError(t, err) + assert.Equal(t, template.HTML(`
memo
`), html) +}