Repository: maragudk/gomponents
Pull request #238 (2024-11-05 16:00:13)

Add support for additional HTML attributes in HTML5 template
This PR updates the HTML5 function to accept and render additional HTML attributes. An additional test case to validate this enhancement has been added as well.

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/maragudk/gomponents/pull/238?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=maragudk) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 100.00%. Comparing base [(`033f6ac`)](https://app.codecov.io/gh/maragudk/gomponents/commit/033f6ac3c36da0e95882d2e00b8cdd54468d3050?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=maragudk) to head [(`60a8d25`)](https://app.codecov.io/gh/maragudk/gomponents/commit/60a8d253a95dce25ed3838b2b4a1f5e21c2dae81?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=maragudk).
> Report is 31 commits behind head on main.

<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff            @@
##              main      #238   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            9         5    -4     
  Lines          534       534           
=========================================
  Hits           534       534           
```

</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/maragudk/gomponents/pull/238?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=maragudk).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=maragudk).


Patch:
diff --git a/components/components.go b/components/components.go
index cc565f3..122882f 100644
--- a/components/components.go
+++ b/components/components.go
@@ -18,12 +18,13 @@ type HTML5Props struct {
 	Language    string
 	Head        []g.Node
 	Body        []g.Node
+	HTMLAttrs   []g.Node
 }
 
 // HTML5 document template.
 func HTML5(p HTML5Props) g.Node {
 	return Doctype(
-		HTML(g.If(p.Language != "", Lang(p.Language)),
+		HTML(g.If(p.Language != "", Lang(p.Language)), g.Group(p.HTMLAttrs),
 			Head(
 				Meta(Charset("utf-8")),
 				Meta(Name("viewport"), Content("width=device-width, initial-scale=1")),


Test patch:
diff --git a/components/components_test.go b/components/components_test.go
index cfc4116..75e8bb0 100644
--- a/components/components_test.go
+++ b/components/components_test.go
@@ -30,6 +30,19 @@ func TestHTML5(t *testing.T) {
 
 		assert.Equal(t, `<!doctype html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>Hat</title></head><body></body></html>`, e)
 	})
+
+	t.Run("returns an html5 document template with additional HTML attributes", func(t *testing.T) {
+		e := HTML5(HTML5Props{
+			Title:       "Hat",
+			Description: "Love hats.",
+			Language:    "en",
+			Head:        []g.Node{Link(Rel("stylesheet"), Href("/hat.css"))},
+			Body:        []g.Node{Div()},
+			HTMLAttrs:   []g.Node{Class("h-full"), ID("htmlid")},
+		})
+
+		assert.Equal(t, `<!doctype html><html lang="en" class="h-full" id="htmlid"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>Hat</title><meta name="description" content="Love hats."><link rel="stylesheet" href="/hat.css"></head><body><div></div></body></html>`, e)
+	})
 }
 
 func TestClasses(t *testing.T) {