Skip to content

Commit

Permalink
add HtmlGetterFunc
Browse files Browse the repository at this point in the history
  • Loading branch information
linkdata committed Nov 29, 2024
1 parent 0abbefb commit 4705842
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
16 changes: 16 additions & 0 deletions htmlgetterfunc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package jaws

import "html/template"

type htmlGetterFunc struct {
fn func(*Element) template.HTML
}

func (g htmlGetterFunc) JawsGetHtml(e *Element) template.HTML {
return g.fn(e)
}

// HtmlGetterFunc wraps a function and returns a HtmlGetter.
func HtmlGetterFunc(fn func(*Element) template.HTML) HtmlGetter {
return htmlGetterFunc{fn: fn}
}
15 changes: 15 additions & 0 deletions htmlgetterfunc_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package jaws

import (
"html/template"
"testing"
)

func TestHtmlGetterFunc(t *testing.T) {
hg := HtmlGetterFunc(func(e *Element) template.HTML {
return "foo"
})
if s := hg.JawsGetHtml(nil); s != "foo" {
t.Error(s)
}
}

0 comments on commit 4705842

Please sign in to comment.