Repository: maragudk/gomponents
Pull request #10 (2020-09-21 09:15:28)

Add a lot of common elements
Especially add elements that are either used in every document, that nearly always have text content, or that are almost always used with certain attributes.

codecov[bot]: # [Codecov](https://codecov.io/gh/maragudk/gomponents/pull/10?src=pr&el=h1) Report
> Merging [#10](https://codecov.io/gh/maragudk/gomponents/pull/10?src=pr&el=desc) into [master](https://codecov.io/gh/maragudk/gomponents/commit/02d963de1090382d820aa371fd265452f5e5542c?el=desc) will **increase** coverage by `0.56%`.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/maragudk/gomponents/pull/10/graphs/tree.svg?width=650&height=150&src=pr&token=JYN032TYAC)](https://codecov.io/gh/maragudk/gomponents/pull/10?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master      #10      +/-   ##
==========================================
+ Coverage   98.14%   98.71%   +0.56%     
==========================================
  Files           3        3              
  Lines          54       78      +24     
==========================================
+ Hits           53       77      +24     
  Misses          1        1              
```


| [Impacted Files](https://codecov.io/gh/maragudk/gomponents/pull/10?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [el/elements.go](https://codecov.io/gh/maragudk/gomponents/pull/10/diff?src=pr&el=tree#diff-ZWwvZWxlbWVudHMuZ28=) | `100.00% <100.00%> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/maragudk/gomponents/pull/10?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/maragudk/gomponents/pull/10?src=pr&el=footer). Last update [02d963d...4664874](https://codecov.io/gh/maragudk/gomponents/pull/10?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/el/elements.go b/el/elements.go
index ecff7e8..a0ea3d5 100644
--- a/el/elements.go
+++ b/el/elements.go
@@ -39,3 +39,93 @@ func Body(children ...g.Node) g.NodeFunc {
 func Title(title string) g.NodeFunc {
 	return g.El("title", g.Text(title))
 }
+
+func Meta(children ...g.Node) g.NodeFunc {
+	return g.El("meta", children...)
+}
+
+func Link(children ...g.Node) g.NodeFunc {
+	return g.El("link", children...)
+}
+
+func Style(children ...g.Node) g.NodeFunc {
+	return g.El("style", children...)
+}
+
+func Div(children ...g.Node) g.NodeFunc {
+	return g.El("div", children...)
+}
+
+func Span(children ...g.Node) g.NodeFunc {
+	return g.El("span", children...)
+}
+
+func A(href string, children ...g.Node) g.NodeFunc {
+	return g.El("a", prepend(g.Attr("href", href), children)...)
+}
+
+func P(children ...g.Node) g.NodeFunc {
+	return g.El("p", children...)
+}
+
+func H1(text string) g.NodeFunc {
+	return g.El("h1", g.Text(text))
+}
+
+func H2(text string) g.NodeFunc {
+	return g.El("h2", g.Text(text))
+}
+
+func H3(text string) g.NodeFunc {
+	return g.El("h3", g.Text(text))
+}
+
+func H4(text string) g.NodeFunc {
+	return g.El("h4", g.Text(text))
+}
+
+func H5(text string) g.NodeFunc {
+	return g.El("h5", g.Text(text))
+}
+
+func H6(text string) g.NodeFunc {
+	return g.El("h6", g.Text(text))
+}
+
+func Ol(children ...g.Node) g.NodeFunc {
+	return g.El("ol", children...)
+}
+
+func Ul(children ...g.Node) g.NodeFunc {
+	return g.El("ul", children...)
+}
+
+func Li(children ...g.Node) g.NodeFunc {
+	return g.El("li", children...)
+}
+
+func B(text string) g.NodeFunc {
+	return g.El("b", g.Text(text))
+}
+
+func Strong(text string) g.NodeFunc {
+	return g.El("strong", g.Text(text))
+}
+
+func I(text string) g.NodeFunc {
+	return g.El("i", g.Text(text))
+}
+
+func Em(text string) g.NodeFunc {
+	return g.El("em", g.Text(text))
+}
+
+func Img(src, alt string) g.NodeFunc {
+	return g.El("img", g.Attr("src", src), g.Attr("alt", alt))
+}
+
+func prepend(node g.Node, nodes []g.Node) []g.Node {
+	newNodes := []g.Node{node}
+	newNodes = append(newNodes, nodes...)
+	return newNodes
+}


Test patch:
diff --git a/el/elements_test.go b/el/elements_test.go
index eb0db47..0eee5f3 100644
--- a/el/elements_test.go
+++ b/el/elements_test.go
@@ -37,3 +37,129 @@ func TestTitle(t *testing.T) {
 		assert.Equal(t, "<title>hat</title>", el.Title("hat"))
 	})
 }
+
+func TestMeta(t *testing.T) {
+	t.Run("returns a meta element", func(t *testing.T) {
+		assert.Equal(t, `<meta charset="utf-8"/>`, el.Meta(g.Attr("charset", "utf-8")))
+	})
+}
+
+func TestLink(t *testing.T) {
+	t.Run("returns a link element", func(t *testing.T) {
+		assert.Equal(t, `<link rel="stylesheet"/>`, el.Link(g.Attr("rel", "stylesheet")))
+	})
+}
+
+func TestStyle(t *testing.T) {
+	t.Run("returns a style element", func(t *testing.T) {
+		assert.Equal(t, `<style type="text/css"/>`, el.Style(g.Attr("type", "text/css")))
+	})
+}
+
+func TestDiv(t *testing.T) {
+	t.Run("returns a div element", func(t *testing.T) {
+		assert.Equal(t, `<div><span/></div>`, el.Div(el.Span()))
+	})
+}
+
+func TestSpan(t *testing.T) {
+	t.Run("returns a span element", func(t *testing.T) {
+		assert.Equal(t, `<span>hat</span>`, el.Span(g.Text("hat")))
+	})
+}
+
+func TestA(t *testing.T) {
+	t.Run("returns an a element with a href attribute", func(t *testing.T) {
+		assert.Equal(t, `<a href="#">hat</a>`, el.A("#", g.Text("hat")))
+	})
+}
+
+func TestP(t *testing.T) {
+	t.Run("returns a p element", func(t *testing.T) {
+		assert.Equal(t, `<p>hat</p>`, el.P(g.Text("hat")))
+	})
+}
+
+func TestH1(t *testing.T) {
+	t.Run("returns an h1 element", func(t *testing.T) {
+		assert.Equal(t, `<h1>hat</h1>`, el.H1("hat"))
+	})
+}
+
+func TestH2(t *testing.T) {
+	t.Run("returns an h2 element", func(t *testing.T) {
+		assert.Equal(t, `<h2>hat</h2>`, el.H2("hat"))
+	})
+}
+
+func TestH3(t *testing.T) {
+	t.Run("returns an h3 element", func(t *testing.T) {
+		assert.Equal(t, `<h3>hat</h3>`, el.H3("hat"))
+	})
+}
+
+func TestH4(t *testing.T) {
+	t.Run("returns an h4 element", func(t *testing.T) {
+		assert.Equal(t, `<h4>hat</h4>`, el.H4("hat"))
+	})
+}
+
+func TestH5(t *testing.T) {
+	t.Run("returns an h5 element", func(t *testing.T) {
+		assert.Equal(t, `<h5>hat</h5>`, el.H5("hat"))
+	})
+}
+
+func TestH6(t *testing.T) {
+	t.Run("returns an h6 element", func(t *testing.T) {
+		assert.Equal(t, `<h6>hat</h6>`, el.H6("hat"))
+	})
+}
+
+func TestOl(t *testing.T) {
+	t.Run("returns an ol element", func(t *testing.T) {
+		assert.Equal(t, `<ol><li/></ol>`, el.Ol(el.Li()))
+	})
+}
+
+func TestUl(t *testing.T) {
+	t.Run("returns a ul element", func(t *testing.T) {
+		assert.Equal(t, `<ul><li/></ul>`, el.Ul(el.Li()))
+	})
+}
+
+func TestLi(t *testing.T) {
+	t.Run("returns an li element", func(t *testing.T) {
+		assert.Equal(t, `<li>hat</li>`, el.Li(g.Text("hat")))
+	})
+}
+
+func TestB(t *testing.T) {
+	t.Run("returns a b element", func(t *testing.T) {
+		assert.Equal(t, `<b>hat</b>`, el.B("hat"))
+	})
+}
+
+func TestStrong(t *testing.T) {
+	t.Run("returns a strong element", func(t *testing.T) {
+		assert.Equal(t, `<strong>hat</strong>`, el.Strong("hat"))
+	})
+}
+
+func TestI(t *testing.T) {
+	t.Run("returns an i element", func(t *testing.T) {
+		assert.Equal(t, `<i>hat</i>`, el.I("hat"))
+	})
+}
+
+func TestEm(t *testing.T) {
+	t.Run("returns an em element", func(t *testing.T) {
+		assert.Equal(t, `<em>hat</em>`, el.Em("hat"))
+	})
+}
+
+func TestImg(t *testing.T) {
+	t.Run("returns an img element with href and alt attributes", func(t *testing.T) {
+		assert.Equal(t, `<img src="hat.png" alt="hat"/>`, el.Img("hat.png", "hat"))
+	})
+}