support non pointer types on formatter
This commit is contained in:
parent
7fae44790c
commit
e2939cd8ba
6 changed files with 79 additions and 9 deletions
|
|
@ -28,12 +28,28 @@ func Button(props ButtonProps) h.Ren {
|
|||
text := h.Text(props.Text)
|
||||
|
||||
button := h.Button(
|
||||
h.If(props.Id != "", h.Id(props.Id)),
|
||||
h.If(props.Children != nil, h.Children(props.Children...)),
|
||||
h.If(
|
||||
props.Id != "",
|
||||
h.Id(props.Id),
|
||||
),
|
||||
h.If(
|
||||
props.Children != nil,
|
||||
h.Children(props.Children...),
|
||||
),
|
||||
h.Class("flex gap-1 items-center justify-center border p-4 rounded cursor-hover", props.Class),
|
||||
h.If(props.Get != "", h.Get(props.Get)),
|
||||
h.If(props.Target != "", h.HxTarget(props.Target)),
|
||||
h.IfElse(props.Type != "", h.Type(props.Type), h.Type("button")),
|
||||
h.If(
|
||||
props.Get != "",
|
||||
h.Get(props.Get),
|
||||
),
|
||||
h.If(
|
||||
props.Target != "",
|
||||
h.HxTarget(props.Target),
|
||||
),
|
||||
h.IfElse(
|
||||
props.Type != "",
|
||||
h.Type(props.Type),
|
||||
h.Type("button"),
|
||||
),
|
||||
text,
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -5,14 +5,17 @@ import (
|
|||
)
|
||||
|
||||
func RootPage(children ...h.Ren) h.Ren {
|
||||
banner := h.A(h.Class("bg-neutral-200 text-neutral-600 text-center p-2 flex items-center justify-center"),
|
||||
banner := h.A(
|
||||
h.Class("bg-neutral-200 text-neutral-600 text-center p-2 flex items-center justify-center"),
|
||||
h.Href("https://github.com/maddalax/htmgo"),
|
||||
h.Attribute("target", "_blank"),
|
||||
h.Text("Built with htmgo.dev"),
|
||||
)
|
||||
|
||||
return h.Html(
|
||||
h.HxExtensions(h.BaseExtensions()),
|
||||
h.HxExtensions(
|
||||
h.BaseExtensions(),
|
||||
),
|
||||
h.Head(
|
||||
h.Meta("viewport", "width=device-width, initial-scale=1"),
|
||||
h.Link("/public/favicon.ico", "icon"),
|
||||
|
|
|
|||
|
|
@ -6,7 +6,9 @@ import (
|
|||
|
||||
func RootPage(children ...h.Ren) h.Ren {
|
||||
return h.Html(
|
||||
h.HxExtensions(h.BaseExtensions()),
|
||||
h.HxExtensions(
|
||||
h.BaseExtensions(),
|
||||
),
|
||||
h.Head(
|
||||
h.Meta("viewport", "width=device-width, initial-scale=1"),
|
||||
h.Link("/public/favicon.ico", "icon"),
|
||||
|
|
|
|||
|
|
@ -6,7 +6,9 @@ import (
|
|||
|
||||
func RootPage(children ...h.Ren) h.Ren {
|
||||
return h.Html(
|
||||
h.HxExtension(h.BaseExtensions()),
|
||||
h.HxExtension(
|
||||
h.BaseExtensions(),
|
||||
),
|
||||
h.Head(
|
||||
h.Meta("viewport", "width=device-width, initial-scale=1"),
|
||||
h.Meta("title", "htmgo todo mvc"),
|
||||
|
|
|
|||
|
|
@ -48,6 +48,15 @@ func Indent(input string) string {
|
|||
}
|
||||
}
|
||||
|
||||
// support non-pointer return types
|
||||
if v, ok := returnType.(*ast.SelectorExpr); ok {
|
||||
if x, ok := v.X.(*ast.Ident); ok {
|
||||
name := x.Name
|
||||
str := name + "." + v.Sel.Name
|
||||
isHtmgoComponent = slices.Contains(htmgoComponentTypes, str)
|
||||
}
|
||||
}
|
||||
|
||||
if !isHtmgoComponent {
|
||||
continue
|
||||
}
|
||||
|
|
|
|||
38
tools/html-to-htmgo/htmltogo/indent_test.go
Normal file
38
tools/html-to-htmgo/htmltogo/indent_test.go
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
package htmltogo
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestIdentHRen(t *testing.T) {
|
||||
input := `
|
||||
package main
|
||||
import (
|
||||
"github.com/maddalax/htmgo/framework/h"
|
||||
)
|
||||
func Button(props ButtonProps) h.Ren {
|
||||
return h.Div(
|
||||
h.Div(h.Div(),h.P(),h.P(),
|
||||
),
|
||||
)
|
||||
}
|
||||
`
|
||||
indented := Indent(input)
|
||||
assert.Equal(t, `package main
|
||||
|
||||
import (
|
||||
"github.com/maddalax/htmgo/framework/h"
|
||||
)
|
||||
|
||||
func Button(props ButtonProps) h.Ren {
|
||||
return h.Div(
|
||||
h.Div(
|
||||
h.Div(),
|
||||
h.P(),
|
||||
h.P(),
|
||||
),
|
||||
)
|
||||
}
|
||||
`, indented)
|
||||
}
|
||||
Loading…
Reference in a new issue