Changed: DB Params
This commit is contained in:
19
templ/examples/external-libraries/components.templ
Normal file
19
templ/examples/external-libraries/components.templ
Normal file
@@ -0,0 +1,19 @@
|
||||
package main
|
||||
|
||||
script graph(data []TimeValue) {
|
||||
const chart = LightweightCharts.createChart(document.body, { width: 400, height: 300 });
|
||||
const lineSeries = chart.addLineSeries();
|
||||
lineSeries.setData(data);
|
||||
}
|
||||
|
||||
templ page(data []TimeValue) {
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8"/>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
||||
<title>Graphs</title>
|
||||
<script src="https://unpkg.com/lightweight-charts/dist/lightweight-charts.standalone.production.js"></script>
|
||||
</head>
|
||||
<body onload={ graph(data) }></body>
|
||||
</html>
|
||||
}
|
69
templ/examples/external-libraries/components_templ.go
Normal file
69
templ/examples/external-libraries/components_templ.go
Normal file
@@ -0,0 +1,69 @@
|
||||
// Code generated by templ - DO NOT EDIT.
|
||||
|
||||
// templ: version: v0.3.833
|
||||
package main
|
||||
|
||||
//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 graph(data []TimeValue) templ.ComponentScript {
|
||||
return templ.ComponentScript{
|
||||
Name: `__templ_graph_c2ba`,
|
||||
Function: `function __templ_graph_c2ba(data){const chart = LightweightCharts.createChart(document.body, { width: 400, height: 300 });
|
||||
const lineSeries = chart.addLineSeries();
|
||||
lineSeries.setData(data);
|
||||
}`,
|
||||
Call: templ.SafeScript(`__templ_graph_c2ba`, data),
|
||||
CallInline: templ.SafeScriptInline(`__templ_graph_c2ba`, data),
|
||||
}
|
||||
}
|
||||
|
||||
func page(data []TimeValue) 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, "<html><head><meta charset=\"UTF-8\"><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"><title>Graphs</title><script src=\"https://unpkg.com/lightweight-charts/dist/lightweight-charts.standalone.production.js\"></script></head>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = templ.RenderScriptItems(ctx, templ_7745c5c3_Buffer, graph(data))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 2, "<body onload=\"")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var2 templ.ComponentScript = graph(data)
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var2.Call)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 3, "\"></body></html>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
var _ = templruntime.GeneratedTemplate
|
9
templ/examples/external-libraries/go.mod
Normal file
9
templ/examples/external-libraries/go.mod
Normal file
@@ -0,0 +1,9 @@
|
||||
module github.com/a-h/templ/examples/external-libraries
|
||||
|
||||
go 1.23
|
||||
|
||||
toolchain go1.23.3
|
||||
|
||||
require github.com/a-h/templ v0.2.304
|
||||
|
||||
replace github.com/a-h/templ => ../../
|
2
templ/examples/external-libraries/go.sum
Normal file
2
templ/examples/external-libraries/go.sum
Normal file
@@ -0,0 +1,2 @@
|
||||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
39
templ/examples/external-libraries/main.go
Normal file
39
templ/examples/external-libraries/main.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type TimeValue struct {
|
||||
Time string `json:"time"`
|
||||
Value float64 `json:"value"`
|
||||
}
|
||||
|
||||
func main() {
|
||||
mux := http.NewServeMux()
|
||||
|
||||
// Handle template.
|
||||
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
data := []TimeValue{
|
||||
{Time: "2019-04-11", Value: 80.01},
|
||||
{Time: "2019-04-12", Value: 96.63},
|
||||
{Time: "2019-04-13", Value: 76.64},
|
||||
{Time: "2019-04-14", Value: 81.89},
|
||||
{Time: "2019-04-15", Value: 74.43},
|
||||
{Time: "2019-04-16", Value: 80.01},
|
||||
{Time: "2019-04-17", Value: 96.63},
|
||||
{Time: "2019-04-18", Value: 76.64},
|
||||
{Time: "2019-04-19", Value: 81.89},
|
||||
{Time: "2019-04-20", Value: 74.43},
|
||||
}
|
||||
page(data).Render(r.Context(), w)
|
||||
})
|
||||
|
||||
// Start the server.
|
||||
fmt.Println("listening on :8080")
|
||||
if err := http.ListenAndServe(":8080", mux); err != nil {
|
||||
log.Printf("error listening: %v", err)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user