about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--components/attributes.go37
-rw-r--r--components/attributes_test.go39
-rw-r--r--components/components.go (renamed from components/documents.go)31
-rw-r--r--components/components_test.go (renamed from components/documents_test.go)30
-rw-r--r--components/elements.go18
-rw-r--r--components/elements_test.go30
6 files changed, 61 insertions, 124 deletions
diff --git a/components/attributes.go b/components/attributes.go
deleted file mode 100644
index dc7ef9b..0000000
--- a/components/attributes.go
+++ /dev/null
@@ -1,37 +0,0 @@
-package components
-
-import (
-	"io"
-	"sort"
-	"strings"
-
-	g "github.com/maragudk/gomponents"
-	"github.com/maragudk/gomponents/html"
-)
-
-// Classes is a map of strings to booleans, which Renders to an attribute with name "class".
-// The attribute value is a sorted, space-separated string of all the map keys,
-// for which the corresponding map value is true.
-type Classes map[string]bool
-
-func (c Classes) Render(w io.Writer) error {
-	var included []string
-	for c, include := range c {
-		if include {
-			included = append(included, c)
-		}
-	}
-	sort.Strings(included)
-	return html.Class(strings.Join(included, " ")).Render(w)
-}
-
-func (c Classes) Type() g.NodeType {
-	return g.AttributeType
-}
-
-// String satisfies fmt.Stringer.
-func (c Classes) String() string {
-	var b strings.Builder
-	_ = c.Render(&b)
-	return b.String()
-}
diff --git a/components/attributes_test.go b/components/attributes_test.go
deleted file mode 100644
index dcfbad2..0000000
--- a/components/attributes_test.go
+++ /dev/null
@@ -1,39 +0,0 @@
-package components_test
-
-import (
-	"os"
-	"testing"
-
-	g "github.com/maragudk/gomponents"
-	c "github.com/maragudk/gomponents/components"
-	"github.com/maragudk/gomponents/internal/assert"
-)
-
-func TestClasses(t *testing.T) {
-	t.Run("given a map, returns sorted keys from the map with value true", func(t *testing.T) {
-		assert.Equal(t, ` class="boheme-hat hat partyhat"`, c.Classes{
-			"boheme-hat": true,
-			"hat":        true,
-			"partyhat":   true,
-			"turtlehat":  false,
-		})
-	})
-
-	t.Run("renders as attribute in an element", func(t *testing.T) {
-		e := g.El("div", c.Classes{"hat": true})
-		assert.Equal(t, `<div class="hat"></div>`, e)
-	})
-
-	t.Run("also works with fmt", func(t *testing.T) {
-		a := c.Classes{"hat": true}
-		if a.String() != ` class="hat"` {
-			t.FailNow()
-		}
-	})
-}
-
-func ExampleClasses() {
-	e := g.El("div", c.Classes{"party-hat": true, "boring-hat": false})
-	_ = e.Render(os.Stdout)
-	// Output: <div class="party-hat"></div>
-}
diff --git a/components/documents.go b/components/components.go
index c7d8f8d..379d18d 100644
--- a/components/documents.go
+++ b/components/components.go
@@ -2,6 +2,10 @@
 package components
 
 import (
+	"io"
+	"sort"
+	"strings"
+
 	g "github.com/maragudk/gomponents"
 	. "github.com/maragudk/gomponents/html"
 )
@@ -31,3 +35,30 @@ func HTML5(p HTML5Props) g.Node {
 		),
 	)
 }
+
+// Classes is a map of strings to booleans, which Renders to an attribute with name "class".
+// The attribute value is a sorted, space-separated string of all the map keys,
+// for which the corresponding map value is true.
+type Classes map[string]bool
+
+func (c Classes) Render(w io.Writer) error {
+	var included []string
+	for c, include := range c {
+		if include {
+			included = append(included, c)
+		}
+	}
+	sort.Strings(included)
+	return Class(strings.Join(included, " ")).Render(w)
+}
+
+func (c Classes) Type() g.NodeType {
+	return g.AttributeType
+}
+
+// String satisfies fmt.Stringer.
+func (c Classes) String() string {
+	var b strings.Builder
+	_ = c.Render(&b)
+	return b.String()
+}
diff --git a/components/documents_test.go b/components/components_test.go
index 21261fa..6420cab 100644
--- a/components/documents_test.go
+++ b/components/components_test.go
@@ -1,6 +1,7 @@
 package components_test
 
 import (
+	"os"
 	"testing"
 
 	g "github.com/maragudk/gomponents"
@@ -30,3 +31,32 @@ 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)
 	})
 }
+
+func TestClasses(t *testing.T) {
+	t.Run("given a map, returns sorted keys from the map with value true", func(t *testing.T) {
+		assert.Equal(t, ` class="boheme-hat hat partyhat"`, Classes{
+			"boheme-hat": true,
+			"hat":        true,
+			"partyhat":   true,
+			"turtlehat":  false,
+		})
+	})
+
+	t.Run("renders as attribute in an element", func(t *testing.T) {
+		e := g.El("div", Classes{"hat": true})
+		assert.Equal(t, `<div class="hat"></div>`, e)
+	})
+
+	t.Run("also works with fmt", func(t *testing.T) {
+		a := Classes{"hat": true}
+		if a.String() != ` class="hat"` {
+			t.FailNow()
+		}
+	})
+}
+
+func ExampleClasses() {
+	e := g.El("div", Classes{"party-hat": true, "boring-hat": false})
+	_ = e.Render(os.Stdout)
+	// Output: <div class="party-hat"></div>
+}
diff --git a/components/elements.go b/components/elements.go
deleted file mode 100644
index c9e1427..0000000
--- a/components/elements.go
+++ /dev/null
@@ -1,18 +0,0 @@
-package components
-
-import (
-	g "github.com/maragudk/gomponents"
-	. "github.com/maragudk/gomponents/html"
-)
-
-func InputHidden(name, value string, children ...g.Node) g.Node {
-	return Input(Type("hidden"), Name(name), Value(value), g.Group(children))
-}
-
-func LinkStylesheet(href string, children ...g.Node) g.Node {
-	return Link(Rel("stylesheet"), Href(href), g.Group(children))
-}
-
-func LinkPreload(href, as string, children ...g.Node) g.Node {
-	return Link(Rel("preload"), Href(href), As(as), g.Group(children))
-}
diff --git a/components/elements_test.go b/components/elements_test.go
deleted file mode 100644
index 7afa7db..0000000
--- a/components/elements_test.go
+++ /dev/null
@@ -1,30 +0,0 @@
-package components_test
-
-import (
-	"testing"
-
-	g "github.com/maragudk/gomponents"
-	c "github.com/maragudk/gomponents/components"
-	"github.com/maragudk/gomponents/internal/assert"
-)
-
-func TestInputHidden(t *testing.T) {
-	t.Run("returns an input element with type hidden, and the given name and value", func(t *testing.T) {
-		n := c.InputHidden("id", "partyhat", g.Attr("class", "hat"))
-		assert.Equal(t, `<input type="hidden" name="id" value="partyhat" class="hat">`, n)
-	})
-}
-
-func TestLinkStylesheet(t *testing.T) {
-	t.Run("returns a link element with rel stylesheet and the given href", func(t *testing.T) {
-		n := c.LinkStylesheet("style.css", g.Attr("media", "print"))
-		assert.Equal(t, `<link rel="stylesheet" href="style.css" media="print">`, n)
-	})
-}
-
-func TestLinkPreload(t *testing.T) {
-	t.Run("returns a link element with rel preload and the given href and as", func(t *testing.T) {
-		n := c.LinkPreload("party.woff2", "font", g.Attr("type", "font/woff2"))
-		assert.Equal(t, `<link rel="preload" href="party.woff2" as="font" type="font/woff2">`, n)
-	})
-}