From 19a0334a926846a4d93bb53389ed4b3559b9139a Mon Sep 17 00:00:00 2001 From: Preston Baxter Date: Fri, 27 Oct 2023 23:44:22 -0500 Subject: [PATCH] start the tmpl journey --- ui/.air.toml | 46 ++++++++++++++++++++++++++++++++++++ ui/.gitignore | 2 ++ ui/go.mod | 5 +++- ui/go.sum | 5 ++-- ui/main.go | 12 ++++++---- ui/static/index.css | 0 ui/tailwing.config.js | 5 ++++ ui/templates/home.templ | 5 ++++ ui/templates/home_templ.go | 48 ++++++++++++++++++++++++++++++++++++++ 9 files changed, 121 insertions(+), 7 deletions(-) create mode 100644 ui/.air.toml create mode 100644 ui/.gitignore create mode 100644 ui/static/index.css create mode 100644 ui/tailwing.config.js create mode 100644 ui/templates/home.templ create mode 100644 ui/templates/home_templ.go diff --git a/ui/.air.toml b/ui/.air.toml new file mode 100644 index 0000000..98dffdf --- /dev/null +++ b/ui/.air.toml @@ -0,0 +1,46 @@ +root = "." +testdata_dir = "testdata" +tmp_dir = "tmp" + +[build] + args_bin = [] + bin = "./tmp/main" + cmd = "templ generate; go build -o ./tmp/main ." + delay = 1000 + exclude_dir = ["assets", "tmp", "vendor", "testdata", "dist"] + exclude_file = [] + exclude_regex = ["_test.go", "_templ.go"] + exclude_unchanged = false + follow_symlink = false + full_bin = "" + include_dir = [] + include_ext = ["go", "tpl", "tmpl", "html", "templ"] + include_file = [] + kill_delay = "0s" + log = "build-errors.log" + poll = false + poll_interval = 0 + post_cmd = [] + pre_cmd = [] + rerun = false + rerun_delay = 500 + send_interrupt = false + stop_on_error = false + +[color] + app = "" + build = "yellow" + main = "magenta" + runner = "green" + watcher = "cyan" + +[log] + main_only = false + time = false + +[misc] + clean_on_exit = false + +[screen] + clear_on_rebuild = false + keep_scroll = true diff --git a/ui/.gitignore b/ui/.gitignore new file mode 100644 index 0000000..05de4fa --- /dev/null +++ b/ui/.gitignore @@ -0,0 +1,2 @@ +dist/* +tmp/* diff --git a/ui/go.mod b/ui/go.mod index 4e60622..269a5b4 100644 --- a/ui/go.mod +++ b/ui/go.mod @@ -2,7 +2,10 @@ module preston-baxter.com/capstone/frontend-service go 1.19 -require github.com/gin-gonic/gin v1.9.1 +require ( + github.com/a-h/templ v0.2.408 + github.com/gin-gonic/gin v1.9.1 +) require ( github.com/bytedance/sonic v1.9.1 // indirect diff --git a/ui/go.sum b/ui/go.sum index 0e0c33a..4965d62 100644 --- a/ui/go.sum +++ b/ui/go.sum @@ -1,3 +1,5 @@ +github.com/a-h/templ v0.2.408 h1:WmXdjVjxjMJyjRg+34cgg+hRC0duDg9OJy6euZbS4ek= +github.com/a-h/templ v0.2.408/go.mod h1:6Lfhsl3Z4/vXl7jjEjkJRCqoWDGjDnuKgzjYMDSddas= github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM= github.com/bytedance/sonic v1.9.1 h1:6iJ6NqdoxCDr6mbY8h18oSO+cShGSMRGCEo7F2h0x8s= github.com/bytedance/sonic v1.9.1/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U= @@ -23,8 +25,8 @@ github.com/go-playground/validator/v10 v10.14.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QX github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= -github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= @@ -72,7 +74,6 @@ golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE= golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng= diff --git a/ui/main.go b/ui/main.go index 126b19c..6bb408d 100644 --- a/ui/main.go +++ b/ui/main.go @@ -1,17 +1,21 @@ package main import ( - "net/http" + "bytes" "github.com/gin-gonic/gin" + "preston-baxter.com/capstone/frontend-service/templates" ) func main() { r := gin.Default() r.GET("/", func(c *gin.Context) { - c.JSON(http.StatusOK, gin.H{ - "message": "pong", - }) + raw := []byte{} + buf := bytes.NewBuffer(raw) + templates.Hello("str").Render(c.Request.Context(), buf) + + + c.Data(200, "text/html", []byte(buf.String())) }) r.Run() // listen and serve on 0.0.0.0:8080 (for windows "localhost:8080") } diff --git a/ui/static/index.css b/ui/static/index.css new file mode 100644 index 0000000..e69de29 diff --git a/ui/tailwing.config.js b/ui/tailwing.config.js new file mode 100644 index 0000000..c53c079 --- /dev/null +++ b/ui/tailwing.config.js @@ -0,0 +1,5 @@ +module.exports = { + content: ["**/*.templ"], + theme: { extend: {}, }, + plugins: [], +} diff --git a/ui/templates/home.templ b/ui/templates/home.templ new file mode 100644 index 0000000..6424008 --- /dev/null +++ b/ui/templates/home.templ @@ -0,0 +1,5 @@ +package templates + +templ Hello(name string) { +
Hello, { name }
+} diff --git a/ui/templates/home_templ.go b/ui/templates/home_templ.go new file mode 100644 index 0000000..5875c76 --- /dev/null +++ b/ui/templates/home_templ.go @@ -0,0 +1,48 @@ +// Code generated by templ@v0.2.408 DO NOT EDIT. + +package templates + +//lint:file-ignore SA4006 This context is only used if a nested component is present. + +import "github.com/a-h/templ" +import "context" +import "io" +import "bytes" + +func Hello(name string) templ.Component { + return templ.ComponentFunc(func(templ_7745c5c3_Ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) + if !templ_7745c5c3_IsBuffer { + templ_7745c5c3_Buffer = templ.GetBuffer() + defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) + } + templ_7745c5c3_Ctx = templ.InitializeContext(templ_7745c5c3_Ctx) + templ_7745c5c3_Var1 := templ.GetChildren(templ_7745c5c3_Ctx) + if templ_7745c5c3_Var1 == nil { + templ_7745c5c3_Var1 = templ.NopComponent + } + templ_7745c5c3_Ctx = templ.ClearChildren(templ_7745c5c3_Ctx) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Var2 := `Hello, ` + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var2) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var3 string = name + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + if !templ_7745c5c3_IsBuffer { + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W) + } + return templ_7745c5c3_Err + }) +}