Skip to content

Commit 2e6f7da

Browse files
authored
Merge pull request #120 from dreth/Add-<ruby>-<rt>-and-<rp>-with-tests
add <ruby>, <rt>, <rp> and tests
2 parents 394d310 + c05cf33 commit 2e6f7da

File tree

2 files changed

+43
-10
lines changed

2 files changed

+43
-10
lines changed

elements.go

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,16 @@ func Section(attrs attrs.Props, children ...Node) *Element {
295295
return newElement("section", attrs, children...)
296296
}
297297

298+
// Details creates a <details> element.
299+
func Details(attrs attrs.Props, children ...Node) *Element {
300+
return newElement("details", attrs, children...)
301+
}
302+
303+
// Summary creates a <summary> element.
304+
func Summary(attrs attrs.Props, children ...Node) *Element {
305+
return newElement("summary", attrs, children...)
306+
}
307+
298308
// ========== Semantic Form Elements ==========
299309

300310
// Fieldset creates a <fieldset> element.
@@ -368,11 +378,6 @@ func Data(attrs attrs.Props, children ...Node) *Element {
368378
return newElement("data", attrs, children...)
369379
}
370380

371-
// Details creates a <details> element.
372-
func Details(attrs attrs.Props, children ...Node) *Element {
373-
return newElement("details", attrs, children...)
374-
}
375-
376381
// FigCaption creates a <figcaption> element.
377382
func FigCaption(attrs attrs.Props, children ...Node) *Element {
378383
return newElement("figcaption", attrs, children...)
@@ -408,11 +413,6 @@ func Small(attrs attrs.Props, children ...Node) *Element {
408413
return newElement("small", attrs, children...)
409414
}
410415

411-
// Summary creates a <summary> element.
412-
func Summary(attrs attrs.Props, children ...Node) *Element {
413-
return newElement("summary", attrs, children...)
414-
}
415-
416416
// Time creates a <time> element.
417417
func Time(attrs attrs.Props, children ...Node) *Element {
418418
return newElement("time", attrs, children...)
@@ -423,6 +423,21 @@ func Var(attrs attrs.Props, children ...Node) *Element {
423423
return newElement("var", attrs, children...)
424424
}
425425

426+
// Ruby creates a <ruby> element.
427+
func Ruby(attrs attrs.Props, children ...Node) *Element {
428+
return newElement("ruby", attrs, children...)
429+
}
430+
431+
// Rt creates a <rt> element.
432+
func Rt(attrs attrs.Props, children ...Node) *Element {
433+
return newElement("rt", attrs, children...)
434+
}
435+
436+
// Rp creates a <rp> element.
437+
func Rp(attrs attrs.Props, children ...Node) *Element {
438+
return newElement("rp", attrs, children...)
439+
}
440+
426441
// ========== Tables ==========
427442

428443
// Table creates a <table> element.

elements_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,24 @@ func TestVar(t *testing.T) {
541541
assert.Equal(t, expected, el.Render())
542542
}
543543

544+
func TestRuby(t *testing.T) {
545+
expected := `<ruby>漢</ruby>`
546+
el := Ruby(nil, Text("漢"))
547+
assert.Equal(t, expected, el.Render())
548+
}
549+
550+
func TestRt(t *testing.T) {
551+
expected := `<ruby> 漢 <rp>(</rp><rt>kan</rt><rp>)</rp> 字 <rp>(</rp><rt>ji</rt><rp>)</rp> </ruby>`
552+
el := Ruby(nil, Text(" 漢 "), Rp(nil, Text("(")), Rt(nil, Text("kan")), Rp(nil, Text(")")), Text(" 字 "), Rp(nil, Text("(")), Rt(nil, Text("ji")), Rp(nil, Text(")")), Text(" "))
553+
assert.Equal(t, expected, el.Render())
554+
}
555+
556+
func TestRp(t *testing.T) {
557+
expected := `<ruby> 漢 <rp>(</rp> 字 <rp>)</rp> </ruby>`
558+
el := Ruby(nil, Text(" 漢 "), Rp(nil, Text("(")), Text(" 字 "), Rp(nil, Text(")")), Text(" "))
559+
assert.Equal(t, expected, el.Render())
560+
}
561+
544562
// ========== Tables ==========
545563

546564
func TestTr(t *testing.T) {

0 commit comments

Comments
 (0)