From 9871e55a967d28499d40bc68f40c35c457769095 Mon Sep 17 00:00:00 2001 From: Johan Lindh Date: Tue, 17 Dec 2024 08:43:00 +0100 Subject: [PATCH 1/2] rename Html to HTML --- README.md | 8 ++++---- element.go | 4 ++-- element_test.go | 6 +++--- htmler.go | 7 +++---- htmler_test.go | 4 ++-- htmlgetter.go | 4 ++-- htmlgetterfunc.go | 6 +++--- htmlgetterfunc_test.go | 6 +++--- jaws.go | 4 ++-- jaws_test.go | 6 +++--- jsfunc_test.go | 8 ++++---- jsvar_test.go | 4 ++-- makehtmlgetter.go | 18 +++++++++--------- makehtmlgetter_test.go | 18 +++++++++--------- namedbool.go | 8 ++++---- namedbool_test.go | 4 ++-- namedboolarray_test.go | 10 +++++----- request_test.go | 2 +- testjaws_test.go | 2 +- testsetter_test.go | 2 +- tohtml.go | 6 +++--- tohtml_test.go | 2 +- ui_test.go | 2 +- uia.go | 12 ++++++------ uia_test.go | 20 ++++++++++---------- uibutton.go | 12 ++++++------ uicontainer.go | 12 ++++++------ uicontainer_test.go | 12 ++++++------ uidiv.go | 12 ++++++------ uihtmlinner.go | 14 +++++++------- uihtmlinner_test.go | 8 ++++---- uiimg.go | 2 +- uiimg_test.go | 6 +++--- uiinputbool.go | 2 +- uiinputdate.go | 2 +- uiinputfloat.go | 2 +- uiinputtext.go | 2 +- uilabel.go | 12 ++++++------ uili.go | 12 ++++++------ uioption.go | 2 +- uioption_test.go | 6 +++--- uiradiogroup_test.go | 16 ++++++++-------- uiselect_test.go | 6 +++--- uispan.go | 12 ++++++------ uitd.go | 12 ++++++------ uitemplate_test.go | 2 +- uitextarea.go | 2 +- uitr.go | 12 ++++++------ writehtml.go | 20 ++++++++++---------- writehtml_test.go | 36 ++++++++++++++++++------------------ 50 files changed, 204 insertions(+), 205 deletions(-) diff --git a/README.md b/README.md index 9dd6bd1..19cbdf5 100644 --- a/README.md +++ b/README.md @@ -156,11 +156,11 @@ router.GET("/jaws/*", func(c echo.Context) error { ### HTML rendering -HTML output elements (e.g. `jaws.RequestWriter.Div()`) require a `jaws.HtmlGetter` or something that can -be made into one using `jaws.MakeHtmlGetter()`. +HTML output elements (e.g. `jaws.RequestWriter.Div()`) require a `jaws.HTMLGetter` or something that can +be made into one using `jaws.MakeHTMLGetter()`. In order of precedence, this can be: -* `jaws.HtmlGetter`: `JawsGetHtml(*Element) template.HTML` to be used as-is. +* `jaws.HTMLGetter`: `JawsGetHTML(*Element) template.HTML` to be used as-is. * `jaws.Getter[template.HTML]`: `JawsGet(*Element) template.HTML` to be used as-is. * `jaws.StringGetter`: `JawsGetString(*Element) string` that will be escaped using `html.EscapeString`. * `jaws.Getter[string]`: `JawsGet(*Element) string` that will be escaped using `html.EscapeString`. @@ -176,7 +176,7 @@ The first argument to these is usually a `Setter[T]` where `T` is one of `string also be a `Getter[T]`, in which case the HTML element should be made read-only. You can also use a `Binder[T]` that combines a (RW)Locker and a pointer to the value, and allows you to add chained setters, -getters and on-success handlers. It can be used as a `jaws.HtmlGetter`. +getters and on-success handlers. It can be used as a `jaws.HTMLGetter`. ### Session handling diff --git a/element.go b/element.go index a61586f..bec2e66 100644 --- a/element.go +++ b/element.go @@ -145,8 +145,8 @@ func (e *Element) RemoveClass(cls string) { // to the browser for the Element. // // Call this only during JawsRender() or JawsUpdate() processing. -func (e *Element) SetInner(innerHtml template.HTML) { - e.queue(what.Inner, string(innerHtml)) +func (e *Element) SetInner(innerHTML template.HTML) { + e.queue(what.Inner, string(innerHTML)) } // SetValue queues sending a new current input value in textual form diff --git a/element_test.go b/element_test.go index 65a6395..de36ccf 100644 --- a/element_test.go +++ b/element_test.go @@ -101,8 +101,8 @@ func TestElement_Queued(t *testing.T) { e.Append("
") e.Remove("some-id") e.Order([]jid.Jid{1, 2}) - replaceHtml := template.HTML(fmt.Sprintf("
", e.Jid().String())) - e.Replace(replaceHtml) + replaceHTML := template.HTML(fmt.Sprintf("
", e.Jid().String())) + e.Replace(replaceHTML) e.JsCall("\"test\\n1\"") th.Equal(rq.wsQueue, []wsMsg{ { @@ -151,7 +151,7 @@ func TestElement_Queued(t *testing.T) { What: what.Order, }, { - Data: string(replaceHtml), + Data: string(replaceHTML), Jid: e.jid, What: what.Replace, }, diff --git a/htmler.go b/htmler.go index b52ddff..39828fe 100644 --- a/htmler.go +++ b/htmler.go @@ -13,8 +13,7 @@ type htmler struct { args []any } -// JawsGetHtml implements HtmlGetter. -func (h htmler) JawsGetHtml(e *Element) template.HTML { +func (h htmler) JawsGetHTML(e *Element) template.HTML { if rl, ok := h.l.(RWLocker); ok { rl.RLock() defer rl.RUnlock() @@ -45,11 +44,11 @@ func (h htmler) JawsGetTag(*Request) any { return tags } -// HTMLer return a lock protected jaws.HtmlGetter using the given formatting +// HTMLer return a lock protected jaws.HTMLGetter using the given formatting // and arguments. Arguments of type string or fmt.Stringer will be escaped // using html.EscapeString(). // // Returns all fmt.Stringer arguments as UI tags. -func HTMLer(l sync.Locker, formatting string, args ...any) HtmlGetter { +func HTMLer(l sync.Locker, formatting string, args ...any) HTMLGetter { return htmler{l, formatting, args} } diff --git a/htmler_test.go b/htmler_test.go index 18cd662..231005f 100644 --- a/htmler_test.go +++ b/htmler_test.go @@ -12,7 +12,7 @@ func TestHTMLer(t *testing.T) { txt := "" htmler := HTMLer(&mu, "

%s

", Fmt(&txt)) - if s := htmler.JawsGetHtml(nil); s != "

<text>

" { + if s := htmler.JawsGetHTML(nil); s != "

<text>

" { t.Error(s) } tags, err := TagExpand(nil, htmler) @@ -25,7 +25,7 @@ func TestHTMLer(t *testing.T) { num := 123 htmler = HTMLer(&mu2, "

%s%s%s

", Fmt(&txt), "", Fmt(&num)) - if s := htmler.JawsGetHtml(nil); s != "

<text><!>123

" { + if s := htmler.JawsGetHTML(nil); s != "

<text><!>123

" { t.Error(s) } tags, err = TagExpand(nil, htmler) diff --git a/htmlgetter.go b/htmlgetter.go index ab82f46..62d66d7 100644 --- a/htmlgetter.go +++ b/htmlgetter.go @@ -4,6 +4,6 @@ import ( "html/template" ) -type HtmlGetter interface { - JawsGetHtml(e *Element) template.HTML +type HTMLGetter interface { + JawsGetHTML(e *Element) template.HTML } diff --git a/htmlgetterfunc.go b/htmlgetterfunc.go index 22496e7..afafe98 100644 --- a/htmlgetterfunc.go +++ b/htmlgetterfunc.go @@ -9,7 +9,7 @@ type htmlGetterFunc struct { var _ TagGetter = &htmlGetterFunc{} -func (g *htmlGetterFunc) JawsGetHtml(e *Element) template.HTML { +func (g *htmlGetterFunc) JawsGetHTML(e *Element) template.HTML { return g.fn(e) } @@ -17,7 +17,7 @@ func (g *htmlGetterFunc) JawsGetTag(e *Request) any { return g.tags } -// HtmlGetterFunc wraps a function and returns a HtmlGetter. -func HtmlGetterFunc(fn func(*Element) template.HTML, tags ...any) HtmlGetter { +// HTMLGetterFunc wraps a function and returns a HTMLGetter. +func HTMLGetterFunc(fn func(*Element) template.HTML, tags ...any) HTMLGetter { return &htmlGetterFunc{fn: fn, tags: tags} } diff --git a/htmlgetterfunc_test.go b/htmlgetterfunc_test.go index 8947309..9bcb58b 100644 --- a/htmlgetterfunc_test.go +++ b/htmlgetterfunc_test.go @@ -6,12 +6,12 @@ import ( "testing" ) -func TestHtmlGetterFunc(t *testing.T) { +func TestHTMLGetterFunc(t *testing.T) { tt := &testSelfTagger{} - hg := HtmlGetterFunc(func(e *Element) template.HTML { + hg := HTMLGetterFunc(func(e *Element) template.HTML { return "foo" }, tt) - if s := hg.JawsGetHtml(nil); s != "foo" { + if s := hg.JawsGetHTML(nil); s != "foo" { t.Error(s) } if tags := MustTagExpand(nil, hg); !reflect.DeepEqual(tags, []any{tt}) { diff --git a/jaws.go b/jaws.go index 6908e2f..64e8639 100644 --- a/jaws.go +++ b/jaws.go @@ -638,11 +638,11 @@ func maybePanic(err error) { // SetInner sends a request to replace the inner HTML of // all HTML elements matching target. -func (jw *Jaws) SetInner(target any, innerHtml template.HTML) { +func (jw *Jaws) SetInner(target any, innerHTML template.HTML) { jw.Broadcast(Message{ Dest: target, What: what.Inner, - Data: string(innerHtml), + Data: string(innerHTML), }) } diff --git a/jaws_test.go b/jaws_test.go index 66468e8..ca81697 100644 --- a/jaws_test.go +++ b/jaws_test.go @@ -299,7 +299,7 @@ func TestJaws_CleansUpUnconnected(t *testing.T) { for i := 0; i < numReqs; i++ { rq := jw.NewRequest(hr) if (i % (numReqs / 5)) == 0 { - rq.NewElement(NewUiDiv(MakeHtmlGetter("meh"))) + rq.NewElement(NewUiDiv(MakeHTMLGetter("meh"))) } err := context.Cause(rq.ctx) if err == nil && rq.lastWrite.Before(deadline) { @@ -443,8 +443,8 @@ func TestJaws_BroadcastsCallable(t *testing.T) { jw.Redirect("foo") jw.Alert("info", "bar") someTags := []any{Tag("tag1"), Tag("tag2")} - jw.SetInner("regularHtmlId", template.HTML("")) - jw.SetValue("regularHtmlId", "value") + jw.SetInner("regularHTMLId", template.HTML("")) + jw.SetValue("regularHTMLId", "value") jw.SetAttr(someTags, "attribute", "value") jw.RemoveAttr(someTags, "attribute") jw.SetClass(someTags, "classname") diff --git a/jsfunc_test.go b/jsfunc_test.go index e59b425..db56c28 100644 --- a/jsfunc_test.go +++ b/jsfunc_test.go @@ -44,7 +44,7 @@ func TestJsFunc_JawsRender(t *testing.T) { t.Error(err) } - got := string(rq.BodyHtml()) + got := string(rq.BodyHTML()) want := `` if got != want { t.Errorf("\n got: %q\nwant: %q\n", got, want) @@ -87,9 +87,9 @@ func TestJsFunc_JawsEvent(t *testing.T) { if err := dot.JawsRender(elem, &sb, []any{"fnname"}); err != nil { t.Fatal(err) } - wantHtml := "" - if gotHtml := sb.String(); gotHtml != wantHtml { - t.Errorf("\n got %q\nwant %q\n", gotHtml, wantHtml) + wantHTML := "" + if gotHTML := sb.String(); gotHTML != wantHTML { + t.Errorf("\n got %q\nwant %q\n", gotHTML, wantHTML) } th.Equal(retvval, "") diff --git a/jsvar_test.go b/jsvar_test.go index 3ab44d7..a847b14 100644 --- a/jsvar_test.go +++ b/jsvar_test.go @@ -59,7 +59,7 @@ func Test_JsVar_JawsRender(t *testing.T) { t.Error(err) } - got := string(rq.BodyHtml()) + got := string(rq.BodyHTML()) want := `` if got != want { t.Errorf("\n got: %q\nwant: %q\n", got, want) @@ -78,7 +78,7 @@ func Test_JsVar_VarMaker(t *testing.T) { if err := rq.JsVar(varname, dot); err != nil { t.Error(err) } - got := string(rq.BodyHtml()) + got := string(rq.BodyHTML()) want := `` if got != want { t.Errorf("\n got: %q\nwant: %q\n", got, want) diff --git a/makehtmlgetter.go b/makehtmlgetter.go index 5accfdc..7db9c06 100644 --- a/makehtmlgetter.go +++ b/makehtmlgetter.go @@ -8,7 +8,7 @@ import ( type htmlGetter struct{ v template.HTML } -func (g htmlGetter) JawsGetHtml(e *Element) template.HTML { +func (g htmlGetter) JawsGetHTML(e *Element) template.HTML { return g.v } @@ -18,7 +18,7 @@ func (g htmlGetter) JawsGetTag(rq *Request) any { type htmlGetterStringGetter struct{ sg StringGetter } -func (g htmlGetterStringGetter) JawsGetHtml(e *Element) template.HTML { +func (g htmlGetterStringGetter) JawsGetHTML(e *Element) template.HTML { return template.HTML(html.EscapeString(g.sg.JawsGetString(e))) // #nosec G203 } @@ -28,7 +28,7 @@ func (g htmlGetterStringGetter) JawsGetTag(rq *Request) any { type htmlGetterHTML struct{ sg Getter[template.HTML] } -func (g htmlGetterHTML) JawsGetHtml(e *Element) template.HTML { +func (g htmlGetterHTML) JawsGetHTML(e *Element) template.HTML { return g.sg.JawsGet(e) } @@ -38,7 +38,7 @@ func (g htmlGetterHTML) JawsGetTag(rq *Request) any { type htmlGetterString struct{ sg Getter[string] } -func (g htmlGetterString) JawsGetHtml(e *Element) template.HTML { +func (g htmlGetterString) JawsGetHTML(e *Element) template.HTML { return template.HTML(html.EscapeString(g.sg.JawsGet(e))) // #nosec G203 } @@ -48,7 +48,7 @@ func (g htmlGetterString) JawsGetTag(rq *Request) any { type htmlGetterAny struct{ ag AnyGetter } -func (g htmlGetterAny) JawsGetHtml(e *Element) template.HTML { +func (g htmlGetterAny) JawsGetHTML(e *Element) template.HTML { s := fmt.Sprint(g.ag.JawsGetAny(e)) return template.HTML(html.EscapeString(s)) // #nosec G203 } @@ -57,11 +57,11 @@ func (g htmlGetterAny) JawsGetTag(rq *Request) any { return g.ag } -// MakeHtmlGetter returns a HtmlGetter for v. +// MakeHTMLGetter returns a HTMLGetter for v. // // Depending on the type of v, we return: // -// - jaws.HtmlGetter: `JawsGetHtml(e *Element) template.HTML` to be used as-is. +// - jaws.HTMLGetter: `JawsGetHTML(e *Element) template.HTML` to be used as-is. // - jaws.Getter[template.HTML]: `JawsGet(elem *Element) template.HTML` to be used as-is. // - jaws.StringGetter: `JawsGetString(e *Element) string` that will be escaped using `html.EscapeString`. // - jaws.Getter[string]: `JawsGet(elem *Element) string` that will be escaped using `html.EscapeString`. @@ -69,9 +69,9 @@ func (g htmlGetterAny) JawsGetTag(rq *Request) any { // - fmt.Stringer: `String() string` that will be escaped using `html.EscapeString`. // - a static `template.HTML` or `string` to be used as-is with no HTML escaping. // - everything else is rendered using `fmt.Sprint()` and escaped using `html.EscapeString`. -func MakeHtmlGetter(v any) HtmlGetter { +func MakeHTMLGetter(v any) HTMLGetter { switch v := v.(type) { - case HtmlGetter: + case HTMLGetter: return v case Getter[template.HTML]: return htmlGetterHTML{v} diff --git a/makehtmlgetter_test.go b/makehtmlgetter_test.go index 7a308ec..cf91a86 100644 --- a/makehtmlgetter_test.go +++ b/makehtmlgetter_test.go @@ -9,7 +9,7 @@ import ( "testing" ) -var _ HtmlGetter = (*testSetter[template.HTML])(nil) +var _ HTMLGetter = (*testSetter[template.HTML])(nil) type testAnySetter struct { Value any @@ -24,7 +24,7 @@ func (ag *testAnySetter) JawsSetAny(e *Element, v any) error { return nil } -func Test_MakeHtmlGetter(t *testing.T) { +func Test_MakeHTMLGetter(t *testing.T) { untypedText := "" typedText := template.HTML(untypedText) escapedTypedText := template.HTML(html.EscapeString(untypedText)) @@ -41,12 +41,12 @@ func Test_MakeHtmlGetter(t *testing.T) { tests := []struct { name string v any - want HtmlGetter + want HTMLGetter out template.HTML tag any }{ { - name: "HtmlGetter", + name: "HTMLGetter", v: htmlGetter{typedText}, want: htmlGetter{typedText}, out: typedText, @@ -111,15 +111,15 @@ func Test_MakeHtmlGetter(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - got := MakeHtmlGetter(tt.v) + got := MakeHTMLGetter(tt.v) if !reflect.DeepEqual(got, tt.want) { - t.Errorf("MakeHtmlGetter()\n got %#v\n want %#v", got, tt.want) + t.Errorf("MakeHTMLGetter()\n got %#v\n want %#v", got, tt.want) } - if txt := got.JawsGetHtml(nil); txt != tt.out { - t.Errorf("MakeHtmlGetter().JawsGetHtml() = %v, want %v", txt, tt.out) + if txt := got.JawsGetHTML(nil); txt != tt.out { + t.Errorf("MakeHTMLGetter().JawsGetHTML() = %v, want %v", txt, tt.out) } if tag := got.(TagGetter).JawsGetTag(nil); tag != tt.tag { - t.Errorf("MakeHtmlGetter().JawsGetTag() = %v, want %v", tag, tt.tag) + t.Errorf("MakeHTMLGetter().JawsGetTag() = %v, want %v", tag, tt.tag) } }) } diff --git a/namedbool.go b/namedbool.go index 868608e..b872b35 100644 --- a/namedbool.go +++ b/namedbool.go @@ -34,7 +34,7 @@ func (nb *NamedBool) Name() (s string) { return } -func (nb *NamedBool) Html() (h template.HTML) { +func (nb *NamedBool) HTML() (h template.HTML) { h = nb.html return } @@ -43,8 +43,8 @@ func (nb *NamedBool) JawsGetString(*Element) (name string) { return nb.Name() } -func (nb *NamedBool) JawsGetHtml(*Element) (h template.HTML) { - return nb.Html() +func (nb *NamedBool) JawsGetHTML(*Element) (h template.HTML) { + return nb.HTML() } func (nb *NamedBool) JawsGet(*Element) (v bool) { @@ -93,5 +93,5 @@ func (nb *NamedBool) Set(checked bool) (changed bool) { // String returns a string representation of the NamedBool suitable for debugging. func (nb *NamedBool) String() string { - return fmt.Sprintf("&{%q,%q,%v}", nb.Name(), nb.Html(), nb.Checked()) + return fmt.Sprintf("&{%q,%q,%v}", nb.Name(), nb.HTML(), nb.Checked()) } diff --git a/namedbool_test.go b/namedbool_test.go index 69efac8..08c4f08 100644 --- a/namedbool_test.go +++ b/namedbool_test.go @@ -18,10 +18,10 @@ func TestNamedBool(t *testing.T) { is.Equal(nba, nb.Array()) is.Equal("1", nb.Name()) - is.Equal(template.HTML("one"), nb.Html()) + is.Equal(template.HTML("one"), nb.HTML()) is.Equal(nb.Name(), nb.JawsGetString(nil)) - is.Equal(nb.Html(), nb.JawsGetHtml(nil)) + is.Equal(nb.HTML(), nb.JawsGetHTML(nil)) is.NoErr(nb.JawsSet(e, true)) is.True(nb.Checked()) diff --git a/namedboolarray_test.go b/namedboolarray_test.go index 2b391b0..af690e6 100644 --- a/namedboolarray_test.go +++ b/namedboolarray_test.go @@ -14,7 +14,7 @@ func Test_NamedBoolArray(t *testing.T) { nba.Add("1", "one") is.Equal(len(nba.data), 1) is.Equal((nba.data)[0].Name(), "1") - is.Equal((nba.data)[0].Html(), template.HTML("one")) + is.Equal((nba.data)[0].HTML(), template.HTML("one")) is.Equal((nba.data)[0].Checked(), false) is.Equal(nba.String(), `&NamedBoolArray{[&{"1","one",false}]}`) is.Equal(nba.Get(), "") @@ -23,7 +23,7 @@ func Test_NamedBoolArray(t *testing.T) { nba.Set("1", true) is.Equal((nba.data)[0].Name(), "1") - is.Equal((nba.data)[0].Html(), template.HTML("one")) + is.Equal((nba.data)[0].HTML(), template.HTML("one")) is.Equal((nba.data)[0].Checked(), true) is.Equal(nba.Get(), "1") is.Equal(nba.IsChecked("1"), true) @@ -33,13 +33,13 @@ func Test_NamedBoolArray(t *testing.T) { nba.Add("2", "also two") is.Equal(len(nba.data), 3) is.Equal((nba.data)[0].Name(), "1") - is.Equal((nba.data)[0].Html(), template.HTML("one")) + is.Equal((nba.data)[0].HTML(), template.HTML("one")) is.Equal((nba.data)[0].Checked(), true) is.Equal((nba.data)[1].Name(), "2") - is.Equal((nba.data)[1].Html(), template.HTML("two")) + is.Equal((nba.data)[1].HTML(), template.HTML("two")) is.Equal((nba.data)[1].Checked(), false) is.Equal((nba.data)[2].Name(), "2") - is.Equal((nba.data)[2].Html(), template.HTML("also two")) + is.Equal((nba.data)[2].HTML(), template.HTML("also two")) is.Equal((nba.data)[2].Checked(), false) is.Equal(nba.String(), `&NamedBoolArray{[&{"1","one",true},&{"2","two",false},&{"2","also two",false}]}`) diff --git a/request_test.go b/request_test.go index 87658ea..5d224fb 100644 --- a/request_test.go +++ b/request_test.go @@ -489,7 +489,7 @@ func TestRequest_DeleteByTag(t *testing.T) { } } -func TestRequest_HtmlIdBroadcast(t *testing.T) { +func TestRequest_HTMLIdBroadcast(t *testing.T) { th := newTestHelper(t) tj := newTestJaws() defer tj.Close() diff --git a/testjaws_test.go b/testjaws_test.go index cec50a6..677e9d5 100644 --- a/testjaws_test.go +++ b/testjaws_test.go @@ -102,7 +102,7 @@ func (tr *testRequest) BodyString() string { return tr.rr.Body.String() } -func (tr *testRequest) BodyHtml() template.HTML { +func (tr *testRequest) BodyHTML() template.HTML { return template.HTML(tr.BodyString()) } diff --git a/testsetter_test.go b/testsetter_test.go index a1f4c97..f598af9 100644 --- a/testsetter_test.go +++ b/testsetter_test.go @@ -114,7 +114,7 @@ func (ts *testSetter[any]) JawsSetAny(e *Element, val any) (err error) { return } -func (ts *testSetter[T]) JawsGetHtml(e *Element) (val T) { +func (ts *testSetter[T]) JawsGetHTML(e *Element) (val T) { ts.mu.Lock() defer ts.mu.Unlock() ts.getCount++ diff --git a/tohtml.go b/tohtml.go index fd17cca..a5df558 100644 --- a/tohtml.go +++ b/tohtml.go @@ -11,7 +11,7 @@ type formathtml struct { f string } -func (fh formathtml) JawsGetHtml(*Element) template.HTML { +func (fh formathtml) JawsGetHTML(*Element) template.HTML { s := html.EscapeString(fh.s.String()) if fh.f != "" { s = fmt.Sprintf(fh.f, s) @@ -23,12 +23,12 @@ func (fh formathtml) JawsGetTag(*Request) any { return fh.s } -// ToHTML return a jaws.HtmlGetter using the given stringer with +// ToHTML return a jaws.HTMLGetter using the given stringer with // the string returned from the stringer escaped using html.EscapeString. // // If formatting is provided the escaped result is passed to fmt.Sprintf(formatting, escapedstring). // Make sure any provided formatting produces correct HTML. -func ToHTML(stringer fmt.Stringer, formatting ...string) HtmlGetter { +func ToHTML(stringer fmt.Stringer, formatting ...string) HTMLGetter { var f string if len(formatting) > 0 { f = formatting[0] diff --git a/tohtml_test.go b/tohtml_test.go index 2dbc3b3..401a105 100644 --- a/tohtml_test.go +++ b/tohtml_test.go @@ -11,7 +11,7 @@ func TestToHTML(t *testing.T) { txt := "

text

" htmler := ToHTML(Stringer(&mu, &txt), "
%s
") - if s := htmler.JawsGetHtml(nil); s != "
<p>text</p>
" { + if s := htmler.JawsGetHTML(nil); s != "
<p>text</p>
" { t.Error(s) } if tags := MustTagExpand(nil, htmler); !reflect.DeepEqual(tags, []any{&txt}) { diff --git a/ui_test.go b/ui_test.go index c0b1266..984ec70 100644 --- a/ui_test.go +++ b/ui_test.go @@ -15,7 +15,7 @@ func TestRequest_NewElement_DebugPanicsIfNotComparable(t *testing.T) { *UiSpan x map[int]int }{ - UiSpan: NewUiSpan(testHtmlGetter("foo")), + UiSpan: NewUiSpan(testHTMLGetter("foo")), x: map[int]int{}, } diff --git a/uia.go b/uia.go index 847264d..4b5f7d2 100644 --- a/uia.go +++ b/uia.go @@ -5,21 +5,21 @@ import ( ) type UiA struct { - UiHtmlInner + UiHTMLInner } func (ui *UiA) JawsRender(e *Element, w io.Writer, params []any) error { return ui.renderInner(e, w, "a", "", params) } -func NewUiA(innerHtml HtmlGetter) *UiA { +func NewUiA(innerHTML HTMLGetter) *UiA { return &UiA{ - UiHtmlInner{ - HtmlGetter: innerHtml, + UiHTMLInner{ + HTMLGetter: innerHTML, }, } } -func (rq RequestWriter) A(innerHtml any, params ...any) error { - return rq.UI(NewUiA(MakeHtmlGetter(innerHtml)), params...) +func (rq RequestWriter) A(innerHTML any, params ...any) error { + return rq.UI(NewUiA(MakeHTMLGetter(innerHTML)), params...) } diff --git a/uia_test.go b/uia_test.go index f837913..801d2ba 100644 --- a/uia_test.go +++ b/uia_test.go @@ -6,17 +6,17 @@ import ( "testing" ) -type testHtmlGetter string +type testHTMLGetter string -func (g testHtmlGetter) JawsGetHtml(e *Element) template.HTML { +func (g testHTMLGetter) JawsGetHTML(e *Element) template.HTML { return template.HTML(g) } -var _ HtmlGetter = testHtmlGetter("foo") +var _ HTMLGetter = testHTMLGetter("foo") func TestRequest_A(t *testing.T) { type args struct { - innerHtml any + innerHTML any params []any } tests := []struct { @@ -27,7 +27,7 @@ func TestRequest_A(t *testing.T) { { name: "string", args: args{ - innerHtml: "string", + innerHTML: "string", params: []any{}, }, want: `string`, @@ -35,15 +35,15 @@ func TestRequest_A(t *testing.T) { { name: "template.HTML", args: args{ - innerHtml: template.HTML("
"), + innerHTML: template.HTML("
"), params: []any{`href="#"`}, }, want: `
`, }, { - name: "HtmlGetter", + name: "HTMLGetter", args: args{ - innerHtml: testHtmlGetter("
"), + innerHTML: testHTMLGetter("
"), params: []any{}, }, want: `
`, @@ -54,8 +54,8 @@ func TestRequest_A(t *testing.T) { nextJid = 0 rq := newTestRequest() defer rq.Close() - rq.A(tt.args.innerHtml, tt.args.params...) - if got := rq.BodyHtml(); !reflect.DeepEqual(got, tt.want) { + rq.A(tt.args.innerHTML, tt.args.params...) + if got := rq.BodyHTML(); !reflect.DeepEqual(got, tt.want) { t.Errorf("Request.A() = %v, want %v", got, tt.want) } }) diff --git a/uibutton.go b/uibutton.go index 30489fe..ce2b2c0 100644 --- a/uibutton.go +++ b/uibutton.go @@ -5,21 +5,21 @@ import ( ) type UiButton struct { - UiHtmlInner + UiHTMLInner } func (ui *UiButton) JawsRender(e *Element, w io.Writer, params []any) error { return ui.renderInner(e, w, "button", "button", params) } -func NewUiButton(innerHtml HtmlGetter) *UiButton { +func NewUiButton(innerHTML HTMLGetter) *UiButton { return &UiButton{ - UiHtmlInner{ - HtmlGetter: innerHtml, + UiHTMLInner{ + HTMLGetter: innerHTML, }, } } -func (rq RequestWriter) Button(innerHtml any, params ...any) error { - return rq.UI(NewUiButton(MakeHtmlGetter(innerHtml)), params...) +func (rq RequestWriter) Button(innerHTML any, params ...any) error { + return rq.UI(NewUiButton(MakeHTMLGetter(innerHTML)), params...) } diff --git a/uicontainer.go b/uicontainer.go index 0723817..ecd8689 100644 --- a/uicontainer.go +++ b/uicontainer.go @@ -5,13 +5,13 @@ import ( ) type UiContainer struct { - OuterHtmlTag string + OuterHTMLTag string uiWrapContainer } -func NewUiContainer(outerHtmlTag string, c Container) *UiContainer { +func NewUiContainer(outerHTMLTag string, c Container) *UiContainer { return &UiContainer{ - OuterHtmlTag: outerHtmlTag, + OuterHTMLTag: outerHTMLTag, uiWrapContainer: uiWrapContainer{ Container: c, }, @@ -19,9 +19,9 @@ func NewUiContainer(outerHtmlTag string, c Container) *UiContainer { } func (ui *UiContainer) JawsRender(e *Element, w io.Writer, params []any) error { - return ui.renderContainer(e, w, ui.OuterHtmlTag, params) + return ui.renderContainer(e, w, ui.OuterHTMLTag, params) } -func (rq RequestWriter) Container(outerHtmlTag string, c Container, params ...any) error { - return rq.UI(NewUiContainer(outerHtmlTag, c), params...) +func (rq RequestWriter) Container(outerHTMLTag string, c Container, params ...any) error { + return rq.UI(NewUiContainer(outerHTMLTag, c), params...) } diff --git a/uicontainer_test.go b/uicontainer_test.go index 8653fd0..bb51802 100644 --- a/uicontainer_test.go +++ b/uicontainer_test.go @@ -41,7 +41,7 @@ func TestRequest_Container(t *testing.T) { { name: "one", args: args{ - c: &testContainer{[]UI{NewUiSpan(testHtmlGetter("foo"))}}, + c: &testContainer{[]UI{NewUiSpan(testHTMLGetter("foo"))}}, params: []any{"hidden"}, }, want: ``, @@ -49,7 +49,7 @@ func TestRequest_Container(t *testing.T) { { name: "two", args: args{ - c: &testContainer{[]UI{NewUiSpan(testHtmlGetter("foo")), NewUiSpan(testHtmlGetter("bar"))}}, + c: &testContainer{[]UI{NewUiSpan(testHTMLGetter("foo")), NewUiSpan(testHTMLGetter("bar"))}}, params: []any{"hidden"}, }, want: ``, @@ -64,7 +64,7 @@ func TestRequest_Container(t *testing.T) { if err != nil { t.Error(err) } - if got := rq.BodyHtml(); !reflect.DeepEqual(got, tt.want) { + if got := rq.BodyHTML(); !reflect.DeepEqual(got, tt.want) { t.Errorf("Request.Container()\nwant %v\n got %v", tt.want, got) } }) @@ -72,9 +72,9 @@ func TestRequest_Container(t *testing.T) { } func TestRequest_Container_Alteration(t *testing.T) { - span1 := NewUiSpan(MakeHtmlGetter("span1")) - span2 := NewUiSpan(MakeHtmlGetter("span2")) - span3 := NewUiSpan(MakeHtmlGetter("span3")) + span1 := NewUiSpan(MakeHTMLGetter("span1")) + span2 := NewUiSpan(MakeHTMLGetter("span2")) + span3 := NewUiSpan(MakeHTMLGetter("span3")) tests := []struct { name string c *testContainer diff --git a/uidiv.go b/uidiv.go index 32263ea..b40ddda 100644 --- a/uidiv.go +++ b/uidiv.go @@ -5,21 +5,21 @@ import ( ) type UiDiv struct { - UiHtmlInner + UiHTMLInner } func (ui *UiDiv) JawsRender(e *Element, w io.Writer, params []any) error { return ui.renderInner(e, w, "div", "", params) } -func NewUiDiv(innerHtml HtmlGetter) *UiDiv { +func NewUiDiv(innerHTML HTMLGetter) *UiDiv { return &UiDiv{ - UiHtmlInner{ - HtmlGetter: innerHtml, + UiHTMLInner{ + HTMLGetter: innerHTML, }, } } -func (rq RequestWriter) Div(innerHtml any, params ...any) error { - return rq.UI(NewUiDiv(MakeHtmlGetter(innerHtml)), params...) +func (rq RequestWriter) Div(innerHTML any, params ...any) error { + return rq.UI(NewUiDiv(MakeHTMLGetter(innerHTML)), params...) } diff --git a/uihtmlinner.go b/uihtmlinner.go index 609889b..fecbba5 100644 --- a/uihtmlinner.go +++ b/uihtmlinner.go @@ -4,15 +4,15 @@ import ( "io" ) -type UiHtmlInner struct { - HtmlGetter +type UiHTMLInner struct { + HTMLGetter } -func (ui *UiHtmlInner) renderInner(e *Element, w io.Writer, htmltag, htmltype string, params []any) error { - e.ApplyGetter(ui.HtmlGetter) - return WriteHtmlInner(w, e.Jid(), htmltag, htmltype, ui.JawsGetHtml(e), e.ApplyParams(params)...) +func (ui *UiHTMLInner) renderInner(e *Element, w io.Writer, htmltag, htmltype string, params []any) error { + e.ApplyGetter(ui.HTMLGetter) + return WriteHTMLInner(w, e.Jid(), htmltag, htmltype, ui.JawsGetHTML(e), e.ApplyParams(params)...) } -func (ui *UiHtmlInner) JawsUpdate(e *Element) { - e.SetInner(ui.JawsGetHtml(e)) +func (ui *UiHTMLInner) JawsUpdate(e *Element) { + e.SetInner(ui.JawsGetHTML(e)) } diff --git a/uihtmlinner_test.go b/uihtmlinner_test.go index af9dafd..b8a96a7 100644 --- a/uihtmlinner_test.go +++ b/uihtmlinner_test.go @@ -11,7 +11,7 @@ import ( "github.com/linkdata/jaws/what" ) -func TestUiHtmlInner_JawsUpdate(t *testing.T) { +func TestUiHTMLInner_JawsUpdate(t *testing.T) { jw := New() defer jw.Close() nextJid = 0 @@ -23,9 +23,9 @@ func TestUiHtmlInner_JawsUpdate(t *testing.T) { if err := ui.JawsRender(elem, &sb, nil); err != nil { t.Fatal(err) } - wantHtml := "
first
" - if sb.String() != wantHtml { - t.Errorf("got %q, want %q", sb.String(), wantHtml) + wantHTML := "
first
" + if sb.String() != wantHTML { + t.Errorf("got %q, want %q", sb.String(), wantHTML) } ts.Set(template.HTML("second")) ui.JawsUpdate(elem) diff --git a/uiimg.go b/uiimg.go index f6100c1..0c5338d 100644 --- a/uiimg.go +++ b/uiimg.go @@ -14,7 +14,7 @@ func (ui *UiImg) JawsRender(e *Element, w io.Writer, params []any) error { e.ApplyGetter(ui.Getter) srcattr := template.HTMLAttr("src=" + strconv.Quote(ui.JawsGet(e))) // #nosec G203 attrs := append(e.ApplyParams(params), srcattr) - return WriteHtmlInner(w, e.Jid(), "img", "", "", attrs...) + return WriteHTMLInner(w, e.Jid(), "img", "", "", attrs...) } func (ui *UiImg) JawsUpdate(e *Element) { diff --git a/uiimg_test.go b/uiimg_test.go index 6832773..edeecf3 100644 --- a/uiimg_test.go +++ b/uiimg_test.go @@ -13,10 +13,10 @@ func TestRequest_Img(t *testing.T) { ts := newTestSetter("image.png") - wantHtml := "" + wantHTML := "" rq.Img(ts, "hidden") - if gotHtml := rq.BodyString(); gotHtml != wantHtml { - t.Errorf("Request.Img() = %q, want %q", gotHtml, wantHtml) + if gotHTML := rq.BodyString(); gotHTML != wantHTML { + t.Errorf("Request.Img() = %q, want %q", gotHTML, wantHTML) } ts.Set("image2.jpg") diff --git a/uiinputbool.go b/uiinputbool.go index f622293..942da84 100644 --- a/uiinputbool.go +++ b/uiinputbool.go @@ -20,7 +20,7 @@ func (ui *UiInputBool) renderBoolInput(e *Element, w io.Writer, htmltype string, if v { attrs = append(attrs, "checked") } - return WriteHtmlInput(w, e.Jid(), htmltype, "", attrs) + return WriteHTMLInput(w, e.Jid(), htmltype, "", attrs) } func (ui *UiInputBool) JawsUpdate(e *Element) { diff --git a/uiinputdate.go b/uiinputdate.go index 5bf9586..e28824e 100644 --- a/uiinputdate.go +++ b/uiinputdate.go @@ -20,7 +20,7 @@ func (ui *UiInputDate) renderDateInput(e *Element, w io.Writer, htmltype string, ui.applyGetter(e, ui.Setter) attrs := e.ApplyParams(params) ui.Last.Store(ui.JawsGet(e)) - return WriteHtmlInput(w, e.Jid(), htmltype, ui.str(), attrs) + return WriteHTMLInput(w, e.Jid(), htmltype, ui.str(), attrs) } func (ui *UiInputDate) JawsUpdate(e *Element) { diff --git a/uiinputfloat.go b/uiinputfloat.go index 9a05ce5..aaab216 100644 --- a/uiinputfloat.go +++ b/uiinputfloat.go @@ -20,7 +20,7 @@ func (ui *UiInputFloat) renderFloatInput(e *Element, w io.Writer, htmltype strin ui.applyGetter(e, ui.Setter) attrs := e.ApplyParams(params) ui.Last.Store(ui.JawsGet(e)) - return WriteHtmlInput(w, e.Jid(), htmltype, ui.str(), attrs) + return WriteHTMLInput(w, e.Jid(), htmltype, ui.str(), attrs) } func (ui *UiInputFloat) JawsUpdate(e *Element) { diff --git a/uiinputtext.go b/uiinputtext.go index 760e9f1..fccce86 100644 --- a/uiinputtext.go +++ b/uiinputtext.go @@ -16,7 +16,7 @@ func (ui *UiInputText) renderStringInput(e *Element, w io.Writer, htmltype strin attrs := e.ApplyParams(params) v := ui.JawsGet(e) ui.Last.Store(v) - return WriteHtmlInput(w, e.Jid(), htmltype, v, attrs) + return WriteHTMLInput(w, e.Jid(), htmltype, v, attrs) } func (ui *UiInputText) JawsUpdate(e *Element) { diff --git a/uilabel.go b/uilabel.go index 5c8fa7f..b503ab5 100644 --- a/uilabel.go +++ b/uilabel.go @@ -5,21 +5,21 @@ import ( ) type UiLabel struct { - UiHtmlInner + UiHTMLInner } func (ui *UiLabel) JawsRender(e *Element, w io.Writer, params []any) error { return ui.renderInner(e, w, "label", "", params) } -func NewUiLabel(innerHtml HtmlGetter) *UiLabel { +func NewUiLabel(innerHTML HTMLGetter) *UiLabel { return &UiLabel{ - UiHtmlInner{ - HtmlGetter: innerHtml, + UiHTMLInner{ + HTMLGetter: innerHTML, }, } } -func (rq RequestWriter) Label(innerHtml any, params ...any) error { - return rq.UI(NewUiLabel(MakeHtmlGetter(innerHtml)), params...) +func (rq RequestWriter) Label(innerHTML any, params ...any) error { + return rq.UI(NewUiLabel(MakeHTMLGetter(innerHTML)), params...) } diff --git a/uili.go b/uili.go index 2450a2b..3cea94b 100644 --- a/uili.go +++ b/uili.go @@ -5,21 +5,21 @@ import ( ) type UiLi struct { - UiHtmlInner + UiHTMLInner } func (ui *UiLi) JawsRender(e *Element, w io.Writer, params []any) error { return ui.renderInner(e, w, "li", "", params) } -func NewUiLi(innerHtml HtmlGetter) *UiLi { +func NewUiLi(innerHTML HTMLGetter) *UiLi { return &UiLi{ - UiHtmlInner{ - HtmlGetter: innerHtml, + UiHTMLInner{ + HTMLGetter: innerHTML, }, } } -func (rq RequestWriter) Li(innerHtml any, params ...any) error { - return rq.UI(NewUiLi(MakeHtmlGetter(innerHtml)), params...) +func (rq RequestWriter) Li(innerHTML any, params ...any) error { + return rq.UI(NewUiLi(MakeHTMLGetter(innerHTML)), params...) } diff --git a/uioption.go b/uioption.go index 2eaacdb..959fa8d 100644 --- a/uioption.go +++ b/uioption.go @@ -16,7 +16,7 @@ func (ui UiOption) JawsRender(e *Element, w io.Writer, params []any) error { if ui.Checked() { attrs = append(attrs, "selected") } - return WriteHtmlInner(w, e.Jid(), "option", "", ui.JawsGetHtml(e), attrs...) + return WriteHTMLInner(w, e.Jid(), "option", "", ui.JawsGetHTML(e), attrs...) } func (ui UiOption) JawsUpdate(e *Element) { diff --git a/uioption_test.go b/uioption_test.go index 8fb88a2..48f5c89 100644 --- a/uioption_test.go +++ b/uioption_test.go @@ -20,9 +20,9 @@ func TestUiOption(t *testing.T) { if err := ui.JawsRender(elem, &sb, []any{"hidden"}); err != nil { t.Fatal(err) } - wantHtml := "" - if gotHtml := sb.String(); gotHtml != wantHtml { - t.Errorf("got %q, want %q", gotHtml, wantHtml) + wantHTML := "" + if gotHTML := sb.String(); gotHTML != wantHTML { + t.Errorf("got %q, want %q", gotHTML, wantHTML) } nb.Set(false) diff --git a/uiradiogroup_test.go b/uiradiogroup_test.go index c63c69d..d088e9d 100644 --- a/uiradiogroup_test.go +++ b/uiradiogroup_test.go @@ -13,15 +13,15 @@ func TestRequest_RadioGroup(t *testing.T) { nba.Add("1", "one") rel := rq.RadioGroup(nba) - wantHtml := "" - gotHtml := string(rel[0].Radio("radioattr")) - if gotHtml != wantHtml { - t.Errorf("got %q, want %q", gotHtml, wantHtml) + wantHTML := "" + gotHTML := string(rel[0].Radio("radioattr")) + if gotHTML != wantHTML { + t.Errorf("got %q, want %q", gotHTML, wantHTML) } - wantHtml = "" - gotHtml = string(rel[0].Label("labelattr")) - if gotHtml != wantHtml { - t.Errorf("got %q, want %q", gotHtml, wantHtml) + wantHTML = "" + gotHTML = string(rel[0].Label("labelattr")) + if gotHTML != wantHTML { + t.Errorf("got %q, want %q", gotHTML, wantHTML) } } diff --git a/uiselect_test.go b/uiselect_test.go index 6a9c466..aab2df2 100644 --- a/uiselect_test.go +++ b/uiselect_test.go @@ -43,10 +43,10 @@ func TestRequest_Select(t *testing.T) { a.Add("2", "two") a.Set("1", true) - wantHtml := "" + wantHTML := "" rq.Select(a, "disabled") - if gotHtml := rq.BodyString(); gotHtml != wantHtml { - t.Errorf("Request.Select() = %q, want %q", gotHtml, wantHtml) + if gotHTML := rq.BodyString(); gotHTML != wantHTML { + t.Errorf("Request.Select() = %q, want %q", gotHTML, wantHTML) } if !a.IsChecked("1") { diff --git a/uispan.go b/uispan.go index b43fc0e..394cd4b 100644 --- a/uispan.go +++ b/uispan.go @@ -5,21 +5,21 @@ import ( ) type UiSpan struct { - UiHtmlInner + UiHTMLInner } func (ui *UiSpan) JawsRender(e *Element, w io.Writer, params []any) error { return ui.renderInner(e, w, "span", "", params) } -func NewUiSpan(innerHtml HtmlGetter) *UiSpan { +func NewUiSpan(innerHTML HTMLGetter) *UiSpan { return &UiSpan{ - UiHtmlInner{ - HtmlGetter: innerHtml, + UiHTMLInner{ + HTMLGetter: innerHTML, }, } } -func (rq RequestWriter) Span(innerHtml any, params ...any) error { - return rq.UI(NewUiSpan(MakeHtmlGetter(innerHtml)), params...) +func (rq RequestWriter) Span(innerHTML any, params ...any) error { + return rq.UI(NewUiSpan(MakeHTMLGetter(innerHTML)), params...) } diff --git a/uitd.go b/uitd.go index 39eb515..6c730b9 100644 --- a/uitd.go +++ b/uitd.go @@ -5,21 +5,21 @@ import ( ) type UiTd struct { - UiHtmlInner + UiHTMLInner } func (ui *UiTd) JawsRender(e *Element, w io.Writer, params []any) error { return ui.renderInner(e, w, "td", "", params) } -func NewUiTd(innerHtml HtmlGetter) *UiTd { +func NewUiTd(innerHTML HTMLGetter) *UiTd { return &UiTd{ - UiHtmlInner{ - HtmlGetter: innerHtml, + UiHTMLInner{ + HTMLGetter: innerHTML, }, } } -func (rq RequestWriter) Td(innerHtml any, params ...any) error { - return rq.UI(NewUiTd(MakeHtmlGetter(innerHtml)), params...) +func (rq RequestWriter) Td(innerHTML any, params ...any) error { + return rq.UI(NewUiTd(MakeHTMLGetter(innerHTML)), params...) } diff --git a/uitemplate_test.go b/uitemplate_test.go index 95cc162..1bf21a4 100644 --- a/uitemplate_test.go +++ b/uitemplate_test.go @@ -65,7 +65,7 @@ func TestRequest_Template(t *testing.T) { }() } rq.Template(tt.args.templ, tt.args.dot, tt.args.params...) - got := rq.BodyHtml() + got := rq.BodyHTML() is.Equal(len(rq.elems), 1) elem := rq.elems[0] if tt.errtxt != "" { diff --git a/uitextarea.go b/uitextarea.go index 2c13b67..b7856ad 100644 --- a/uitextarea.go +++ b/uitextarea.go @@ -12,7 +12,7 @@ type UiTextarea struct { func (ui *UiTextarea) JawsRender(e *Element, w io.Writer, params []any) error { ui.applyGetter(e, ui.Setter) attrs := e.ApplyParams(params) - return WriteHtmlInner(w, e.Jid(), "textarea", "", template.HTML(ui.JawsGet(e)), attrs...) // #nosec G203 + return WriteHTMLInner(w, e.Jid(), "textarea", "", template.HTML(ui.JawsGet(e)), attrs...) // #nosec G203 } func (ui *UiTextarea) JawsUpdate(e *Element) { diff --git a/uitr.go b/uitr.go index e21772b..47ea453 100644 --- a/uitr.go +++ b/uitr.go @@ -5,21 +5,21 @@ import ( ) type UiTr struct { - UiHtmlInner + UiHTMLInner } func (ui *UiTr) JawsRender(e *Element, w io.Writer, params []any) error { return ui.renderInner(e, w, "tr", "", params) } -func NewUiTr(innerHtml HtmlGetter) *UiTr { +func NewUiTr(innerHTML HTMLGetter) *UiTr { return &UiTr{ - UiHtmlInner{ - HtmlGetter: innerHtml, + UiHTMLInner{ + HTMLGetter: innerHTML, }, } } -func (rq RequestWriter) Tr(innerHtml any, params ...any) error { - return rq.UI(NewUiTr(MakeHtmlGetter(innerHtml)), params...) +func (rq RequestWriter) Tr(innerHTML any, params ...any) error { + return rq.UI(NewUiTr(MakeHTMLGetter(innerHTML)), params...) } diff --git a/writehtml.go b/writehtml.go index c04d601..f1202a6 100644 --- a/writehtml.go +++ b/writehtml.go @@ -42,7 +42,7 @@ func appendAttrs(b []byte, attrs []template.HTMLAttr) []byte { return b } -func WriteHtmlTag(w io.Writer, jid jid.Jid, htmlTag, typeAttr, valueAttr string, attrs []template.HTMLAttr) (err error) { +func WriteHTMLTag(w io.Writer, jid jid.Jid, htmlTag, typeAttr, valueAttr string, attrs []template.HTMLAttr) (err error) { b := jid.AppendStartTagAttr(nil, htmlTag) if typeAttr != "" { b = append(b, ` type=`...) @@ -58,15 +58,15 @@ func WriteHtmlTag(w io.Writer, jid jid.Jid, htmlTag, typeAttr, valueAttr string, return } -func WriteHtmlInput(w io.Writer, jid jid.Jid, typeAttr, valueAttr string, attrs []template.HTMLAttr) (err error) { - return WriteHtmlTag(w, jid, "input", typeAttr, valueAttr, attrs) +func WriteHTMLInput(w io.Writer, jid jid.Jid, typeAttr, valueAttr string, attrs []template.HTMLAttr) (err error) { + return WriteHTMLTag(w, jid, "input", typeAttr, valueAttr, attrs) } -func WriteHtmlInner(w io.Writer, jid jid.Jid, htmlTag, typeAttr string, innerHtml template.HTML, attrs ...template.HTMLAttr) (err error) { - if err = WriteHtmlTag(w, jid, htmlTag, typeAttr, "", attrs); err == nil { - if innerHtml != "" || needClosingTag(htmlTag) { +func WriteHTMLInner(w io.Writer, jid jid.Jid, htmlTag, typeAttr string, innerHTML template.HTML, attrs ...template.HTMLAttr) (err error) { + if err = WriteHTMLTag(w, jid, htmlTag, typeAttr, "", attrs); err == nil { + if innerHTML != "" || needClosingTag(htmlTag) { var b []byte - b = append(b, innerHtml...) + b = append(b, innerHTML...) b = append(b, "') @@ -76,8 +76,8 @@ func WriteHtmlInner(w io.Writer, jid jid.Jid, htmlTag, typeAttr string, innerHtm return } -func WriteHtmlSelect(w io.Writer, jid jid.Jid, nba *NamedBoolArray, attrs []template.HTMLAttr) (err error) { - if err = WriteHtmlTag(w, jid, "select", "", "", attrs); err == nil { +func WriteHTMLSelect(w io.Writer, jid jid.Jid, nba *NamedBoolArray, attrs []template.HTMLAttr) (err error) { + if err = WriteHTMLTag(w, jid, "select", "", "", attrs); err == nil { var b []byte nba.ReadLocked(func(nba []*NamedBool) { for _, nb := range nba { @@ -87,7 +87,7 @@ func WriteHtmlSelect(w io.Writer, jid jid.Jid, nba *NamedBoolArray, attrs []temp b = append(b, ` selected`...) } b = append(b, '>') - b = append(b, nb.Html()...) + b = append(b, nb.HTML()...) b = append(b, ""...) } }) diff --git a/writehtml_test.go b/writehtml_test.go index d86c910..8810557 100644 --- a/writehtml_test.go +++ b/writehtml_test.go @@ -8,7 +8,7 @@ import ( "github.com/linkdata/jaws/jid" ) -func Test_WriteHtmlInner(t *testing.T) { +func Test_WriteHTMLInner(t *testing.T) { type args struct { jid jid.Jid tag string @@ -22,7 +22,7 @@ func Test_WriteHtmlInner(t *testing.T) { want string }{ { - name: "HtmlInner no attrs", + name: "HTMLInner no attrs", args: args{ jid: 1, tag: "tag1", @@ -32,7 +32,7 @@ func Test_WriteHtmlInner(t *testing.T) { want: `inner_text`, }, { - name: "HtmlInner singleton tag", + name: "HTMLInner singleton tag", args: args{ jid: 2, tag: "img", @@ -42,7 +42,7 @@ func Test_WriteHtmlInner(t *testing.T) { want: ``, }, { - name: "HtmlInner two filled attrs, one empty", + name: "HTMLInner two filled attrs, one empty", args: args{ jid: 3, tag: "tag1", @@ -56,17 +56,17 @@ func Test_WriteHtmlInner(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { var sb strings.Builder - if err := WriteHtmlInner(&sb, tt.args.jid, tt.args.tag, tt.args.typ, tt.args.inner, tt.args.attrs...); err != nil { + if err := WriteHTMLInner(&sb, tt.args.jid, tt.args.tag, tt.args.typ, tt.args.inner, tt.args.attrs...); err != nil { t.Fatal(err) } if got := sb.String(); got != tt.want { - t.Errorf("HtmlInner() = %v, want %v", got, tt.want) + t.Errorf("HTMLInner() = %v, want %v", got, tt.want) } }) } } -func Test_WriteHtmlSelect(t *testing.T) { +func Test_WriteHTMLSelect(t *testing.T) { type args struct { jid jid.Jid val *NamedBoolArray @@ -78,7 +78,7 @@ func Test_WriteHtmlSelect(t *testing.T) { want string }{ { - name: "HtmlSelect empty NamedBoolArray and one attr", + name: "HTMLSelect empty NamedBoolArray and one attr", args: args{ jid: 2, val: NewNamedBoolArray(), @@ -87,7 +87,7 @@ func Test_WriteHtmlSelect(t *testing.T) { want: "", }, { - name: "HtmlSelect NamedBoolArray with data", + name: "HTMLSelect NamedBoolArray with data", args: args{ jid: 3, val: func() (nba *NamedBoolArray) { @@ -110,17 +110,17 @@ func Test_WriteHtmlSelect(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { var sb strings.Builder - if err := WriteHtmlSelect(&sb, tt.args.jid, tt.args.val, tt.args.attrs); err != nil { + if err := WriteHTMLSelect(&sb, tt.args.jid, tt.args.val, tt.args.attrs); err != nil { t.Fatal(err) } if got := sb.String(); got != tt.want { - t.Errorf("HtmlSelect():\n got = %q\nwant = %q", got, tt.want) + t.Errorf("HTMLSelect():\n got = %q\nwant = %q", got, tt.want) } }) } } -func Test_WriteHtmlInput(t *testing.T) { +func Test_WriteHTMLInput(t *testing.T) { type args struct { jid jid.Jid typ string @@ -133,7 +133,7 @@ func Test_WriteHtmlInput(t *testing.T) { want string }{ { - name: "HtmlInput no attrs", + name: "HTMLInput no attrs", args: args{ jid: 1, typ: "input_type", @@ -142,7 +142,7 @@ func Test_WriteHtmlInput(t *testing.T) { want: ``, }, { - name: "HtmlInput one empty attr", + name: "HTMLInput one empty attr", args: args{ jid: 2, typ: "input_type2", @@ -152,7 +152,7 @@ func Test_WriteHtmlInput(t *testing.T) { want: ``, }, { - name: "HtmlInput one filled attr", + name: "HTMLInput one filled attr", args: args{ jid: 3, typ: "input_type2", @@ -162,7 +162,7 @@ func Test_WriteHtmlInput(t *testing.T) { want: ``, }, { - name: "HtmlInput two filled attr, one empty", + name: "HTMLInput two filled attr, one empty", args: args{ jid: 4, typ: "input_type2", @@ -175,11 +175,11 @@ func Test_WriteHtmlInput(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { var sb strings.Builder - if err := WriteHtmlInput(&sb, tt.args.jid, tt.args.typ, tt.args.val, tt.args.attrs); err != nil { + if err := WriteHTMLInput(&sb, tt.args.jid, tt.args.typ, tt.args.val, tt.args.attrs); err != nil { t.Fatal(err) } if got := sb.String(); got != tt.want { - t.Errorf("HtmlInput() = %v, want %v", got, tt.want) + t.Errorf("HTMLInput() = %v, want %v", got, tt.want) } }) } From 86e59637fe11de6d6f810e0b1ae35a950e2a57bb Mon Sep 17 00:00:00 2001 From: Johan Lindh Date: Tue, 17 Dec 2024 09:20:32 +0100 Subject: [PATCH 2/2] docs --- README.md | 8 ++++++-- htmlgetter.go | 1 + htmlgetterfunc.go | 2 +- stringgetterfunc.go | 2 +- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 19cbdf5..e2061a5 100644 --- a/README.md +++ b/README.md @@ -169,14 +169,18 @@ In order of precedence, this can be: * a static `template.HTML` or `string` to be used as-is with no HTML escaping. * everything else is rendered using `fmt.Sprint()` and escaped using `html.EscapeString`. +You can use `jaws.HTMLGetterFunc` or `jaws.StringGetterFunc` to easily build a custom renderer +for those trivial rendering tasks. + ### Data binding HTML input elements (e.g. `jaws.RequestWriter.Range()`) require bi-directional data flow between the server and the browser. The first argument to these is usually a `Setter[T]` where `T` is one of `string`, `float64`, `bool` or `time.Time`. It can also be a `Getter[T]`, in which case the HTML element should be made read-only. -You can also use a `Binder[T]` that combines a (RW)Locker and a pointer to the value, and allows you to add chained setters, -getters and on-success handlers. It can be used as a `jaws.HTMLGetter`. +Since all data access need to be protected with locks, you will usually use `jaws.Bind()` to create a `jaws.Binder[T]` +that combines a (RW)Locker and a pointer to a value of type `T`. It also allows you to add chained setters, +getters and on-success handlers. ### Session handling diff --git a/htmlgetter.go b/htmlgetter.go index 62d66d7..5ea7132 100644 --- a/htmlgetter.go +++ b/htmlgetter.go @@ -4,6 +4,7 @@ import ( "html/template" ) +// A HTMLGetter is the primary way to deliver generated HTML content to dynamic HTML nodes. type HTMLGetter interface { JawsGetHTML(e *Element) template.HTML } diff --git a/htmlgetterfunc.go b/htmlgetterfunc.go index afafe98..629e355 100644 --- a/htmlgetterfunc.go +++ b/htmlgetterfunc.go @@ -18,6 +18,6 @@ func (g *htmlGetterFunc) JawsGetTag(e *Request) any { } // HTMLGetterFunc wraps a function and returns a HTMLGetter. -func HTMLGetterFunc(fn func(*Element) template.HTML, tags ...any) HTMLGetter { +func HTMLGetterFunc(fn func(elem *Element) (tmpl template.HTML), tags ...any) HTMLGetter { return &htmlGetterFunc{fn: fn, tags: tags} } diff --git a/stringgetterfunc.go b/stringgetterfunc.go index be0aa93..c1baa18 100644 --- a/stringgetterfunc.go +++ b/stringgetterfunc.go @@ -14,6 +14,6 @@ func (g *stringGetterFunc) JawsGetTag(e *Request) any { } // StringGetterFunc wraps a function and returns a StringGetter. -func StringGetterFunc(fn func(*Element) string, tags ...any) StringGetter { +func StringGetterFunc(fn func(elem *Element) (s string), tags ...any) StringGetter { return &stringGetterFunc{fn: fn, tags: tags} }