Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more list elems #22

Merged
merged 2 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ In this example, if `isAdmin` is `true`, the `Admin Panel` link is rendered. Oth
- `Button`: Button `<button>`
- `Code`: Code `<code>`
- `Div`: Division `<div>`
- `Dl`: Description List `<dl>`
- `Dt`: Description Term `<dt>`
- `Dd`: Description Description `<dd>`
- `Em`: Emphasis `<em>`
- `Form`: Form `<form>`
- `H1`: Heading 1 `<h1>`
Expand All @@ -110,6 +113,7 @@ In this example, if `isAdmin` is `true`, the `Admin Panel` link is rendered. Oth
- `Label`: Label `<label>`
- `Li`: List Item `<li>`
- `Meta`: Meta `<meta>`
- `Ol`: Ordered List `<ol>`
- `Option`: Dropdown option `<option>`
- `P`: Paragraph `<p>`
- `Pre`: Preformatted Text `<pre>`
Expand Down
16 changes: 16 additions & 0 deletions elements.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,22 @@ func Ul(props Attrs, children ...Node) *Element {
return NewElement("ul", props, children...)
}

func Ol(props Attrs, children ...Node) *Element {
return NewElement("ol", props, children...)
}

func Dl(props Attrs, children ...Node) *Element {
return NewElement("dl", props, children...)
}

func Dt(props Attrs, children ...Node) *Element {
return NewElement("dt", props, children...)
}

func Dd(props Attrs, children ...Node) *Element {
return NewElement("dd", props, children...)
}

// ========== Forms ==========

func Button(props Attrs, children ...Node) *Element {
Expand Down
24 changes: 24 additions & 0 deletions elements_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,30 @@ func TestUl(t *testing.T) {
assert.Equal(t, expected, el.Render())
}

func TestOl(t *testing.T) {
expected := `<ol><li>Item 1</li><li>Item 2</li></ol>`
el := Ol(nil, Li(nil, Text("Item 1")), Li(nil, Text("Item 2")))
assert.Equal(t, expected, el.Render())
}

func TestDl(t *testing.T) {
expected := `<dl><dt>Term 1</dt><dd>Description 1</dd><dt>Term 2</dt><dd>Description 2</dd></dl>`
el := Dl(nil, Dt(nil, Text("Term 1")), Dd(nil, Text("Description 1")), Dt(nil, Text("Term 2")), Dd(nil, Text("Description 2")))
assert.Equal(t, expected, el.Render())
}

func TestDt(t *testing.T) {
expected := `<dt>Term 1</dt>`
el := Dt(nil, Text("Term 1"))
assert.Equal(t, expected, el.Render())
}

func TestDd(t *testing.T) {
expected := `<dd>Description 1</dd>`
el := Dd(nil, Text("Description 1"))
assert.Equal(t, expected, el.Render())
}

// ========== Forms ==========

func TestButton(t *testing.T) {
Expand Down