Skip to content

Commit

Permalink
update and restructure
Browse files Browse the repository at this point in the history
  • Loading branch information
stanistan committed Apr 2, 2024
1 parent 5579f71 commit b62e076
Show file tree
Hide file tree
Showing 23 changed files with 441 additions and 381 deletions.
3 changes: 0 additions & 3 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ linters:
- depguard
- exhaustivestruct
- exhaustruct
- gochecknoglobals
- golint
- ifshort
- interfacer
Expand All @@ -18,5 +17,3 @@ linters:
- structcheck
- varcheck
- varnamelen
- wrapcheck
- wsl
File renamed without changes.
2 changes: 1 addition & 1 deletion bin/golangci-lint
63 changes: 0 additions & 63 deletions common_views.go

This file was deleted.

5 changes: 5 additions & 0 deletions el/attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ func Class(names ...string) AttrFunc {
})
}

// ID is the ID attribute.
func ID(id string) Attr {
return Attr{Key: "id", Value: id}
}

// Href creates an href [Attr] with the given value.
func Href(href string) Attr {
return Attr{Key: "href", Value: href}
Expand Down
8 changes: 6 additions & 2 deletions el/el_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import (
"testing"

"github.com/alecthomas/assert/v2"

"github.com/stanistan/veun"
"github.com/stanistan/veun/el"
)

//nolint:funlen
func TestElementExpRender(t *testing.T) {
t.Parallel()

for idx, testCase := range []struct {
in veun.AsView
out string
Expand Down Expand Up @@ -82,11 +83,14 @@ func TestElementExpRender(t *testing.T) {
},
} {
testCase := testCase

t.Run(fmt.Sprintf("test i-%d", idx), func(t *testing.T) {
t.Parallel()

out, err := veun.Render(context.Background(), testCase.in)

assert.NoError(t, err)
assert.Equal(t, template.HTML(testCase.out), out)
assert.Equal(t, template.HTML(testCase.out), out) //nolint:gosec
})
}
}
22 changes: 17 additions & 5 deletions el/element.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@ import (
"context"
"html/template"

"github.com/stanistan/veun"
"github.com/stanistan/veun/internal/view"
)

type element[T elementKind] struct {
tag tag
inner T
}

func (e element[T]) View(_ context.Context) (*veun.View, error) {
return veun.V(e), nil
func (e element[T]) View(_ context.Context) (*view.View, error) {
return view.V(e), nil
}

//nolint:wrapcheck
func (e element[T]) AsHTML(ctx context.Context) (template.HTML, error) {
return e.inner.AsHTML(ctx, e.tag)
}
Expand All @@ -25,7 +26,7 @@ func (e *element[T]) attrs(fn func(Attrs)) {
}

func newElementWithChildren(t string, ps []Param) element[nodeChildren] {
e := element[nodeChildren]{tag: tag{name: t}}
e := element[nodeChildren]{tag: tag{name: t}, inner: nodeChildren{}}
for _, p := range ps {
p.applyToElement(&e)
}
Expand All @@ -34,10 +35,21 @@ func newElementWithChildren(t string, ps []Param) element[nodeChildren] {
}

func newVoidElement(t string, ps []VoidParam) element[void] {
e := element[void]{tag: tag{name: t}}
e := element[void]{tag: tag{name: t}, inner: void{}}
for _, p := range ps {
p.applyToVoidElement(&e)
}

return e
}

func MapFragment[T any, U Param, E ~[]T](
in E, fn func(T, int) U,
) Fragment {
var out Fragment
for idx, v := range in {
out = append(out, fn(v, idx))
}

return out
}
Loading

0 comments on commit b62e076

Please sign in to comment.