Skip to content

Commit

Permalink
feat: MustMemo
Browse files Browse the repository at this point in the history
  • Loading branch information
stanistan committed Jan 23, 2024
1 parent 36be1a3 commit bd88894
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
12 changes: 12 additions & 0 deletions memo.go
Original file line number Diff line number Diff line change
@@ -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)
}
29 changes: 29 additions & 0 deletions memo_test.go
Original file line number Diff line number Diff line change
@@ -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(`<div>memo</div>`), view)

html, err := veun.Render(context.Background(), view)
assert.NoError(t, err)
assert.Equal(t, template.HTML(`<div>memo</div>`), html)

html, err = veun.Render(context.Background(), in)
assert.NoError(t, err)
assert.Equal(t, template.HTML(`<div>memo</div>`), html)
}

0 comments on commit bd88894

Please sign in to comment.