refactor: moving templates into dir
routes probably can live in main.go for simpler exercises
This commit is contained in:
parent
9c19bd7b6b
commit
78c9bd1d61
2
Makefile
2
Makefile
|
@ -1,5 +1,5 @@
|
||||||
# List of all .templ files
|
# List of all .templ files
|
||||||
TEMPL_FILES := $(wildcard *.templ)
|
TEMPL_FILES := $(shell find templates -type f -name '*.templ')
|
||||||
|
|
||||||
# Name of the generated file(s) from templ
|
# Name of the generated file(s) from templ
|
||||||
GENERATED_FILES := $(TEMPL_FILES:.templ=_templ.go)
|
GENERATED_FILES := $(TEMPL_FILES:.templ=_templ.go)
|
||||||
|
|
2
go.mod
2
go.mod
|
@ -2,4 +2,4 @@ module sunshine.industries/temp-exercise
|
||||||
|
|
||||||
go 1.21.7
|
go 1.21.7
|
||||||
|
|
||||||
require github.com/a-h/templ v0.2.598 // indirect
|
require github.com/a-h/templ v0.2.598
|
||||||
|
|
2
go.sum
2
go.sum
|
@ -1,2 +1,4 @@
|
||||||
github.com/a-h/templ v0.2.598 h1:6jMIHv6wQZvdPxTuv87erW4RqN/FPU0wk7ZHN5wVuuo=
|
github.com/a-h/templ v0.2.598 h1:6jMIHv6wQZvdPxTuv87erW4RqN/FPU0wk7ZHN5wVuuo=
|
||||||
github.com/a-h/templ v0.2.598/go.mod h1:SA7mtYwVEajbIXFRh3vKdYm/4FYyLQAtPH1+KxzGPA8=
|
github.com/a-h/templ v0.2.598/go.mod h1:SA7mtYwVEajbIXFRh3vKdYm/4FYyLQAtPH1+KxzGPA8=
|
||||||
|
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||||
|
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||||
|
|
6
main.go
6
main.go
|
@ -2,12 +2,14 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/a-h/templ"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"sunshine.industries/temp-exercise/templates"
|
||||||
|
"github.com/a-h/templ"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
component := hello("some name")
|
component := templates.Hello("some name")
|
||||||
|
|
||||||
http.Handle("/", templ.Handler(component))
|
http.Handle("/", templ.Handler(component))
|
||||||
|
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
package main
|
package templates
|
||||||
|
|
||||||
var myVar string = "some string, changed. and more"
|
var myVar string = "some string, changed. and more"
|
||||||
var anotherVar string = "hoho, cool"
|
var anotherVar string = "hoho, cool"
|
||||||
|
|
||||||
templ hello(name string) {
|
templ Hello(name string) {
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>This is the title of the webpage!</title>
|
<title>This is the title of the the webpage!</title>
|
||||||
<link href="./static/output.css" rel="stylesheet"/>
|
<link href="/static/output.css" rel="stylesheet"/>
|
||||||
</head>
|
</head>
|
||||||
<body class="bg-blue-200">
|
<body class="bg-blue-100 text-xl">
|
||||||
<p class="text-purple-500">This is an example paragraph. Anything in the <strong>body</strong> tag will appear on the page, just like this <strong>p</strong> tag and its contents.</p>
|
<p class="text-purple-700">This is an example paragraph. Anything in the <strong>body</strong> tag will appear on the page, just like this <strong>p</strong> tag and its contents.</p>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
}
|
}
|
Loading…
Reference in New Issue