Changed: DB Params
This commit is contained in:
6
templ/generator/test-templ-in-go-template/expected.html
Normal file
6
templ/generator/test-templ-in-go-template/expected.html
Normal file
@@ -0,0 +1,6 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<body>
|
||||
<div>Hello, World!</div>
|
||||
</body>
|
||||
</html>
|
39
templ/generator/test-templ-in-go-template/render_test.go
Normal file
39
templ/generator/test-templ-in-go-template/render_test.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package testgotemplates
|
||||
|
||||
import (
|
||||
"context"
|
||||
_ "embed"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/a-h/templ"
|
||||
"github.com/a-h/templ/generator/htmldiff"
|
||||
)
|
||||
|
||||
//go:embed expected.html
|
||||
var expected string
|
||||
|
||||
func TestExample(t *testing.T) {
|
||||
// Create the templ component.
|
||||
templComponent := greeting()
|
||||
html, err := templ.ToGoHTML(context.Background(), templComponent)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to convert to html: %v", err)
|
||||
}
|
||||
|
||||
// Use it within the text/html template.
|
||||
b := new(strings.Builder)
|
||||
err = example.Execute(b, html)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to execute template: %v", err)
|
||||
}
|
||||
|
||||
// Compare the output with the expected.
|
||||
diff, err := htmldiff.DiffStrings(expected, b.String())
|
||||
if err != nil {
|
||||
t.Fatalf("failed to diff strings: %v", err)
|
||||
}
|
||||
if diff != "" {
|
||||
t.Error(diff)
|
||||
}
|
||||
}
|
15
templ/generator/test-templ-in-go-template/template.templ
Normal file
15
templ/generator/test-templ-in-go-template/template.templ
Normal file
@@ -0,0 +1,15 @@
|
||||
package testgotemplates
|
||||
|
||||
import "html/template"
|
||||
|
||||
var example = template.Must(template.New("example").Parse(`<!DOCTYPE html>
|
||||
<html>
|
||||
<body>
|
||||
{{ . }}
|
||||
</body>
|
||||
</html>
|
||||
`))
|
||||
|
||||
templ greeting() {
|
||||
<div>Hello, World!</div>
|
||||
}
|
50
templ/generator/test-templ-in-go-template/template_templ.go
Normal file
50
templ/generator/test-templ-in-go-template/template_templ.go
Normal file
@@ -0,0 +1,50 @@
|
||||
// Code generated by templ - DO NOT EDIT.
|
||||
|
||||
// templ: version: v0.3.833
|
||||
package testgotemplates
|
||||
|
||||
//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"
|
||||
|
||||
import "html/template"
|
||||
|
||||
var example = template.Must(template.New("example").Parse(`<!DOCTYPE html>
|
||||
<html>
|
||||
<body>
|
||||
{{ . }}
|
||||
</body>
|
||||
</html>
|
||||
`))
|
||||
|
||||
func greeting() 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, "<div>Hello, World!</div>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
var _ = templruntime.GeneratedTemplate
|
Reference in New Issue
Block a user