diff options
author | Markus Wüstenberg | 2024-09-19 19:33:58 +0200 |
---|---|---|
committer | GitHub | 2024-09-19 19:33:58 +0200 |
commit | 69b0da41dff1813f3939cf4ea09fbbb2d06b7719 (patch) | |
tree | 5c2eb3befabf9d666691a20f65d79513c5821e11 | |
parent | c97605aca761985ac45adfe19365801ec2682657 (diff) | |
download | gomponents-69b0da41dff1813f3939cf4ea09fbbb2d06b7719.tar.lz gomponents-69b0da41dff1813f3939cf4ea09fbbb2d06b7719.tar.zst gomponents-69b0da41dff1813f3939cf4ea09fbbb2d06b7719.zip |
Drop support for Go 1.16 and Go 1.17 (#203)
Fixes #184
-rw-r--r-- | .github/workflows/ci.yml | 7 | ||||
-rw-r--r-- | examples/simple/simple.go | 3 | ||||
-rw-r--r-- | examples/tailwindcss/tailwindcss.go | 3 | ||||
-rw-r--r-- | gomponents.go | 9 | ||||
-rw-r--r-- | gomponents_generic.go | 13 | ||||
-rw-r--r-- | gomponents_generic_test.go | 34 | ||||
-rw-r--r-- | gomponents_non_generic.go | 13 | ||||
-rw-r--r-- | gomponents_non_generic_test.go | 34 | ||||
-rw-r--r-- | gomponents_test.go | 22 |
9 files changed, 31 insertions, 107 deletions
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cabd79c..b179ab4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,8 +20,6 @@ jobs: strategy: matrix: go: - - "1.16" - - "1.17" - "1.18" - "1.19" - "1.20" @@ -43,13 +41,8 @@ jobs: run: go build -v ./... - name: Test - if: ${{ matrix.go != '1.16' }} run: go test -v -coverprofile=coverage.txt -shuffle on ./... - - name: Test - if: ${{ matrix.go == '1.16' }} - run: go test -v -coverprofile=coverage.txt ./... - - name: Coverage uses: codecov/codecov-action@v3 diff --git a/examples/simple/simple.go b/examples/simple/simple.go index 0a7138a..20c41fb 100644 --- a/examples/simple/simple.go +++ b/examples/simple/simple.go @@ -1,6 +1,3 @@ -//go:build go1.18 -// +build go1.18 - package main import ( diff --git a/examples/tailwindcss/tailwindcss.go b/examples/tailwindcss/tailwindcss.go index 39a012e..6e92288 100644 --- a/examples/tailwindcss/tailwindcss.go +++ b/examples/tailwindcss/tailwindcss.go @@ -1,6 +1,3 @@ -//go:build go1.18 -// +build go1.18 - package main import ( diff --git a/gomponents.go b/gomponents.go index ffe8483..1a3b4ee 100644 --- a/gomponents.go +++ b/gomponents.go @@ -246,6 +246,15 @@ func Rawf(format string, a ...interface{}) Node { }) } +// Map a slice of anything to a slice of Nodes. +func Map[T any](ts []T, cb func(T) Node) []Node { + var nodes []Node + for _, t := range ts { + nodes = append(nodes, cb(t)) + } + return nodes +} + type group struct { children []Node } diff --git a/gomponents_generic.go b/gomponents_generic.go deleted file mode 100644 index 6e6500b..0000000 --- a/gomponents_generic.go +++ /dev/null @@ -1,13 +0,0 @@ -//go:build go1.18 -// +build go1.18 - -package gomponents - -// Map a slice of anything to a slice of Nodes. -func Map[T any](ts []T, cb func(T) Node) []Node { - var nodes []Node - for _, t := range ts { - nodes = append(nodes, cb(t)) - } - return nodes -} diff --git a/gomponents_generic_test.go b/gomponents_generic_test.go deleted file mode 100644 index 0492ae3..0000000 --- a/gomponents_generic_test.go +++ /dev/null @@ -1,34 +0,0 @@ -//go:build go1.18 -// +build go1.18 - -package gomponents_test - -import ( - "os" - "testing" - - g "github.com/maragudk/gomponents" - "github.com/maragudk/gomponents/internal/assert" -) - -func TestMap(t *testing.T) { - t.Run("maps slices to nodes", func(t *testing.T) { - items := []string{"hat", "partyhat", "turtlehat"} - lis := g.Map(items, func(i string) g.Node { - return g.El("li", g.Text(i)) - }) - - list := g.El("ul", lis...) - - assert.Equal(t, `<ul><li>hat</li><li>partyhat</li><li>turtlehat</li></ul>`, list) - }) -} - -func ExampleMap() { - items := []string{"party hat", "super hat"} - e := g.El("ul", g.Group(g.Map(items, func(i string) g.Node { - return g.El("li", g.Text(i)) - }))) - _ = e.Render(os.Stdout) - // Output: <ul><li>party hat</li><li>super hat</li></ul> -} diff --git a/gomponents_non_generic.go b/gomponents_non_generic.go deleted file mode 100644 index 56570d0..0000000 --- a/gomponents_non_generic.go +++ /dev/null @@ -1,13 +0,0 @@ -//go:build !go1.18 -// +build !go1.18 - -package gomponents - -// Map something enumerable to a list of Nodes. -func Map(length int, cb func(i int) Node) []Node { - var nodes []Node - for i := 0; i < length; i++ { - nodes = append(nodes, cb(i)) - } - return nodes -} diff --git a/gomponents_non_generic_test.go b/gomponents_non_generic_test.go deleted file mode 100644 index 4186808..0000000 --- a/gomponents_non_generic_test.go +++ /dev/null @@ -1,34 +0,0 @@ -//go:build !go1.18 -// +build !go1.18 - -package gomponents_test - -import ( - "os" - "testing" - - g "github.com/maragudk/gomponents" - "github.com/maragudk/gomponents/internal/assert" -) - -func TestMap(t *testing.T) { - t.Run("maps slices to nodes", func(t *testing.T) { - items := []string{"hat", "partyhat", "turtlehat"} - lis := g.Map(len(items), func(i int) g.Node { - return g.El("li", g.Text(items[i])) - }) - - list := g.El("ul", lis...) - - assert.Equal(t, `<ul><li>hat</li><li>partyhat</li><li>turtlehat</li></ul>`, list) - }) -} - -func ExampleMap() { - items := []string{"party hat", "super hat"} - e := g.El("ul", g.Group(g.Map(len(items), func(i int) g.Node { - return g.El("li", g.Text(items[i])) - }))) - _ = e.Render(os.Stdout) - // Output: <ul><li>party hat</li><li>super hat</li></ul> -} diff --git a/gomponents_test.go b/gomponents_test.go index f3e81b0..27fb534 100644 --- a/gomponents_test.go +++ b/gomponents_test.go @@ -227,6 +227,28 @@ func ExampleRawf() { // Output: <span><button onclick="javascript:alert('Party time!')">Party hats</button> > normal hats.</span> } +func TestMap(t *testing.T) { + t.Run("maps slices to nodes", func(t *testing.T) { + items := []string{"hat", "partyhat", "turtlehat"} + lis := g.Map(items, func(i string) g.Node { + return g.El("li", g.Text(i)) + }) + + list := g.El("ul", lis...) + + assert.Equal(t, `<ul><li>hat</li><li>partyhat</li><li>turtlehat</li></ul>`, list) + }) +} + +func ExampleMap() { + items := []string{"party hat", "super hat"} + e := g.El("ul", g.Group(g.Map(items, func(i string) g.Node { + return g.El("li", g.Text(i)) + }))) + _ = e.Render(os.Stdout) + // Output: <ul><li>party hat</li><li>super hat</li></ul> +} + func TestGroup(t *testing.T) { t.Run("groups multiple nodes into one", func(t *testing.T) { children := []g.Node{g.El("br", g.Attr("id", "hat")), g.El("hr")} |