From 60a8d253a95dce25ed3838b2b4a1f5e21c2dae81 Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Tue, 5 Nov 2024 16:59:17 +0100 Subject: [PATCH] Add support for additional HTML attributes in HTML5 template Updated the HTML5 function to accept and render additional HTML attributes. Added a new test case to validate this enhancement. --- components/components.go | 3 ++- components/components_test.go | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) 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")), 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, `Hat`, 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, `Hat
`, e) + }) } func TestClasses(t *testing.T) {