Skip to content

Commit 5b99ac1

Browse files
John DoakJohn Doak
authored andcommitted
added <i> tag
1 parent 8692bca commit 5b99ac1

3 files changed

Lines changed: 81 additions & 1 deletion

File tree

html/i.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package html
2+
3+
import (
4+
"html/template"
5+
"strings"
6+
)
7+
8+
var iTmpl = template.Must(template.New("i").Parse(strings.TrimSpace(`
9+
<i {{.Self.Attr }} {{.Self.GlobalAttrs.Attr}} {{.Self.Events.Attr}}>
10+
{{- $data := .}}
11+
{{- .Self.Element.Execute $data}}
12+
</i>
13+
`)))
14+
15+
// I defines a part of text in an alternate voice or mood.
16+
type I struct {
17+
GlobalAttrs
18+
19+
Element TextElement
20+
21+
Events *Events
22+
}
23+
24+
func (i *I) Attr() template.HTMLAttr {
25+
output := structToString(i)
26+
return template.HTMLAttr(output)
27+
}
28+
29+
func (i *I) Execute(pipe Pipeline) string {
30+
pipe.Self = i
31+
32+
if err := iTmpl.Execute(pipe.W, pipe); err != nil {
33+
panic(err)
34+
}
35+
36+
return EmptyString
37+
}

html/i_test.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package html
2+
3+
import (
4+
"context"
5+
"strings"
6+
"testing"
7+
)
8+
9+
func TestI(t *testing.T) {
10+
tests := []struct {
11+
desc string
12+
i *I
13+
want string
14+
}{
15+
{
16+
desc: "Empty attributes",
17+
i: &I{},
18+
want: `<i >
19+
</i>`,
20+
},
21+
{
22+
desc: "All attributes + 1 global + 1 event",
23+
i: &I{
24+
GlobalAttrs: GlobalAttrs{
25+
AccessKey: "key",
26+
},
27+
Element: TextElement("text"),
28+
Events: (&Events{}).AddScript(OnError, "handleError"),
29+
},
30+
want: `<i accesskey="key" onerror="handleError">text
31+
</i>`,
32+
},
33+
}
34+
35+
for _, test := range tests {
36+
got := &strings.Builder{}
37+
pipe := NewPipeline(context.Background(), nil, got)
38+
test.i.Execute(pipe)
39+
if test.want != got.String() {
40+
t.Errorf("TestI(%s): \n\tgot %q\n\twant %q", test.desc, got, test.want)
41+
}
42+
}
43+
}

html/textarea.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ type TextArea struct {
4747
Wrap WrapType
4848
// Placeholder specifies a short hint that describes the expected value of a text area.
4949
Placeholder string
50-
50+
5151
// AutoFocus specifies that a text area should automatically get focus when the page loads.
5252
AutoFocus bool `html:"attr"`
5353
// Disabled specifies that a text area should be disabled.

0 commit comments

Comments
 (0)