Changed: DB Params
This commit is contained in:
2
templ/generator/test-style-attribute/expected.html
Normal file
2
templ/generator/test-style-attribute/expected.html
Normal file
@@ -0,0 +1,2 @@
|
||||
<button style="background-color:blue;color:red;">Click me</button>
|
||||
<button style="background-color: red;">Click me</button>
|
64
templ/generator/test-style-attribute/render_test.go
Normal file
64
templ/generator/test-style-attribute/render_test.go
Normal file
@@ -0,0 +1,64 @@
|
||||
package teststyleattribute
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/a-h/templ"
|
||||
"github.com/a-h/templ/generator/htmldiff"
|
||||
)
|
||||
|
||||
//go:embed expected.html
|
||||
var expected string
|
||||
|
||||
func Test(t *testing.T) {
|
||||
var stringCSS = "background-color:blue;color:red"
|
||||
var safeCSS = templ.SafeCSS("background-color:blue;color:red;")
|
||||
var mapStringString = map[string]string{
|
||||
"color": "red",
|
||||
"background-color": "blue",
|
||||
}
|
||||
var mapStringSafeCSSProperty = map[string]templ.SafeCSSProperty{
|
||||
"color": templ.SafeCSSProperty("red"),
|
||||
"background-color": templ.SafeCSSProperty("blue"),
|
||||
}
|
||||
var kvStringStringSlice = []templ.KeyValue[string, string]{
|
||||
templ.KV("background-color", "blue"),
|
||||
templ.KV("color", "red"),
|
||||
}
|
||||
var kvStringBoolSlice = []templ.KeyValue[string, bool]{
|
||||
templ.KV("background-color:blue", true),
|
||||
templ.KV("color:red", true),
|
||||
templ.KV("color:blue", false),
|
||||
}
|
||||
var kvSafeCSSBoolSlice = []templ.KeyValue[templ.SafeCSS, bool]{
|
||||
templ.KV(templ.SafeCSS("background-color:blue"), true),
|
||||
templ.KV(templ.SafeCSS("color:red"), true),
|
||||
templ.KV(templ.SafeCSS("color:blue"), false),
|
||||
}
|
||||
|
||||
tests := []any{
|
||||
stringCSS,
|
||||
safeCSS,
|
||||
mapStringString,
|
||||
mapStringSafeCSSProperty,
|
||||
kvStringStringSlice,
|
||||
kvStringBoolSlice,
|
||||
kvSafeCSSBoolSlice,
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(fmt.Sprintf("%T", test), func(t *testing.T) {
|
||||
component := Button(test, "Click me")
|
||||
|
||||
diff, err := htmldiff.Diff(component, expected)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if diff != "" {
|
||||
t.Error(diff)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
10
templ/generator/test-style-attribute/template.templ
Normal file
10
templ/generator/test-style-attribute/template.templ
Normal file
@@ -0,0 +1,10 @@
|
||||
package teststyleattribute
|
||||
|
||||
templ Button[T any](style T, text string) {
|
||||
<button style={ style }>{ text }</button>
|
||||
<button style={ getFunctionResult() }>{ text }</button>
|
||||
}
|
||||
|
||||
func getFunctionResult() (string, error) {
|
||||
return "background-color: red", nil
|
||||
}
|
96
templ/generator/test-style-attribute/template_templ.go
Normal file
96
templ/generator/test-style-attribute/template_templ.go
Normal file
@@ -0,0 +1,96 @@
|
||||
// Code generated by templ - DO NOT EDIT.
|
||||
|
||||
// templ: version: v0.3.833
|
||||
package teststyleattribute
|
||||
|
||||
//lint:file-ignore SA4006 This context is only used if a nested component is present.
|
||||
|
||||
import "github.com/a-h/templ"
|
||||
import templruntime "github.com/a-h/templ/runtime"
|
||||
|
||||
func Button[T any](style T, text string) templ.Component {
|
||||
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
|
||||
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
|
||||
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
|
||||
return templ_7745c5c3_CtxErr
|
||||
}
|
||||
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
|
||||
if !templ_7745c5c3_IsBuffer {
|
||||
defer func() {
|
||||
templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
|
||||
if templ_7745c5c3_Err == nil {
|
||||
templ_7745c5c3_Err = templ_7745c5c3_BufErr
|
||||
}
|
||||
}()
|
||||
}
|
||||
ctx = templ.InitializeContext(ctx)
|
||||
templ_7745c5c3_Var1 := templ.GetChildren(ctx)
|
||||
if templ_7745c5c3_Var1 == nil {
|
||||
templ_7745c5c3_Var1 = templ.NopComponent
|
||||
}
|
||||
ctx = templ.ClearChildren(ctx)
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "<button style=\"")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var2 string
|
||||
templ_7745c5c3_Var2, templ_7745c5c3_Err = templruntime.SanitizeStyleAttributeValues(style)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `templ/generator/test-style-attribute/template.templ`, Line: 4, Col: 22}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var2))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 2, "\">")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var3 string
|
||||
templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(text)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `templ/generator/test-style-attribute/template.templ`, Line: 4, Col: 31}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 3, "</button> <button style=\"")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var4 string
|
||||
templ_7745c5c3_Var4, templ_7745c5c3_Err = templruntime.SanitizeStyleAttributeValues(getFunctionResult())
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `templ/generator/test-style-attribute/template.templ`, Line: 5, Col: 36}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 4, "\">")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var5 string
|
||||
templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(text)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `templ/generator/test-style-attribute/template.templ`, Line: 5, Col: 45}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 5, "</button>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func getFunctionResult() (string, error) {
|
||||
return "background-color: red", nil
|
||||
}
|
||||
|
||||
var _ = templruntime.GeneratedTemplate
|
Reference in New Issue
Block a user