Repository: maragudk/gomponents
Pull request #54 (2020-12-10 12:10:12)

Rename Document to Doctype

codecov[bot]: # [Codecov](https://codecov.io/gh/maragudk/gomponents/pull/54?src=pr&el=h1) Report
> Merging [#54](https://codecov.io/gh/maragudk/gomponents/pull/54?src=pr&el=desc) (e127ac6) into [master](https://codecov.io/gh/maragudk/gomponents/commit/a76262652b227c95ce140f3698c46f59b79354ac?el=desc) (a762626) will **not change** coverage.
> The diff coverage is `100.00%`.

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

```diff
@@            Coverage Diff            @@
##            master       #54   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            5         5           
  Lines          238       238           
=========================================
  Hits           238       238           
```


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

------

[Continue to review full report at Codecov](https://codecov.io/gh/maragudk/gomponents/pull/54?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/54?src=pr&el=footer). Last update [a762626...e127ac6](https://codecov.io/gh/maragudk/gomponents/pull/54?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/README.md b/README.md
index cd8a887..5a8a954 100644
--- a/README.md
+++ b/README.md
@@ -54,7 +54,7 @@ func handler(w http.ResponseWriter, r *http.Request) {
 }
 
 func Page(title, currentPath string) g.Node {
-	return Document(
+	return Doctype(
 		HTML(
 			Lang("en"),
 			Head(
@@ -94,7 +94,7 @@ import (
 	"net/http"
 
 	g "github.com/maragudk/gomponents"
-	. "github.com/maragudk/gomponents/components"
+	c "github.com/maragudk/gomponents/components"
 	. "github.com/maragudk/gomponents/html"
 )
 
@@ -107,7 +107,7 @@ func handler(w http.ResponseWriter, r *http.Request) {
 }
 
 func Page(title, currentPath string) g.Node {
-	return HTML5(HTML5Props{
+	return c.HTML5(c.HTML5Props{
 		Title:    title,
 		Language: "en",
 		Head: []g.Node{
@@ -129,7 +129,7 @@ func Navbar(currentPath string) g.Node {
 }
 
 func NavbarLink(href, name, currentPath string) g.Node {
-	return A(href, Classes{"is-active": currentPath == href}, g.Text(name))
+	return A(href, c.Classes{"is-active": currentPath == href}, g.Text(name))
 }
 ```
 
diff --git a/components/documents.go b/components/documents.go
index e2d3a22..17b421a 100644
--- a/components/documents.go
+++ b/components/documents.go
@@ -25,7 +25,7 @@ func HTML5(p HTML5Props) g.NodeFunc {
 	if p.Description != "" {
 		description = Meta(Name("description"), Content(p.Description))
 	}
-	return Document(
+	return Doctype(
 		HTML(lang,
 			Head(
 				Meta(Charset("utf-8")),
diff --git a/examples/simple/simple.go b/examples/simple/simple.go
index 535fa6e..529cf18 100644
--- a/examples/simple/simple.go
+++ b/examples/simple/simple.go
@@ -27,7 +27,7 @@ type props struct {
 }
 
 func page(p props) g.Node {
-	return h.Document(
+	return h.Doctype(
 		h.HTML(h.Lang("en"),
 			h.Head(
 				h.TitleEl(p.title),
diff --git a/html/elements.go b/html/elements.go
index 8045561..4f1a0ec 100644
--- a/html/elements.go
+++ b/html/elements.go
@@ -14,13 +14,13 @@ func A(href string, children ...g.Node) g.NodeFunc {
 	return g.El("a", g.Attr("href", href), g.Group(children))
 }
 
-// Document returns an special kind of Node that prefixes its child with the string "<!doctype html>".
-func Document(child g.Node) g.NodeFunc {
+// Doctype returns a special kind of Node that prefixes its sibling with the string "<!doctype html>".
+func Doctype(sibling g.Node) g.NodeFunc {
 	return func(w io.Writer) error {
 		if _, err := w.Write([]byte("<!doctype html>")); err != nil {
 			return err
 		}
-		return child.Render(w)
+		return sibling.Render(w)
 	}
 }
 


Test patch:
diff --git a/html/elements_test.go b/html/elements_test.go
index e550bfe..f89919d 100644
--- a/html/elements_test.go
+++ b/html/elements_test.go
@@ -16,13 +16,13 @@ func (w *erroringWriter) Write(p []byte) (n int, err error) {
 	return 0, errors.New("don't want to write")
 }
 
-func TestDocument(t *testing.T) {
+func TestDoctype(t *testing.T) {
 	t.Run("returns doctype and children", func(t *testing.T) {
-		assert.Equal(t, `<!doctype html><html></html>`, Document(g.El("html")))
+		assert.Equal(t, `<!doctype html><html></html>`, Doctype(g.El("html")))
 	})
 
 	t.Run("errors on write error in Render", func(t *testing.T) {
-		err := Document(g.El("html")).Render(&erroringWriter{})
+		err := Doctype(g.El("html")).Render(&erroringWriter{})
 		assert.Error(t, err)
 	})
 }