From 815c6a689dd3c2b801cb0f4f2bf37ddf75e12500 Mon Sep 17 00:00:00 2001 From: Lucas Schumacher Date: Thu, 1 Aug 2024 18:25:25 -0400 Subject: [PATCH] Add tailwind v2 CSS framework --- controllers/static.go | 8 ++++---- main.go | 6 +++--- templates/contact.gohtml | 11 +++++++++-- templates/faq.gohtml | 28 +++++++++++++++++++++------- templates/home.gohtml | 35 +++++++++++++++++++++++------------ 5 files changed, 60 insertions(+), 28 deletions(-) diff --git a/controllers/static.go b/controllers/static.go index ed0e68b..8d6f009 100644 --- a/controllers/static.go +++ b/controllers/static.go @@ -7,8 +7,8 @@ import ( "strings" ) -func StaticTemplate(templatePath string) http.HandlerFunc { - tpl := views.Must(views.FromFS(templates.FS, templatePath)) +func StaticTemplate(templatePath ...string) http.HandlerFunc { + tpl := views.Must(views.FromFS(templates.FS, templatePath...)) var testWriter strings.Builder err := tpl.ExecuteWriter(&testWriter, nil) @@ -19,7 +19,7 @@ func StaticTemplate(templatePath string) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { tpl.Execute(w, nil) } } -func FAQ(templatePath string) http.HandlerFunc { +func FAQ(templatePath ...string) http.HandlerFunc { questions := []struct { Question string Answer string @@ -34,7 +34,7 @@ func FAQ(templatePath string) http.HandlerFunc { }, } - tpl := views.Must(views.FromFS(templates.FS, templatePath)) + tpl := views.Must(views.FromFS(templates.FS, templatePath...)) var testWriter strings.Builder err := tpl.ExecuteWriter(&testWriter, nil) diff --git a/main.go b/main.go index 2fb796d..bc32995 100644 --- a/main.go +++ b/main.go @@ -18,9 +18,9 @@ func notFoundHandler(w http.ResponseWriter, r *http.Request) { func main() { r := chi.NewRouter() r.Use(middleware.Logger) - r.Get("/", ctrlrs.StaticTemplate("home.gohtml")) - r.Get("/contact", ctrlrs.StaticTemplate("contact.gohtml")) - r.Get("/faq", ctrlrs.FAQ("faq.gohtml")) + r.Get("/", ctrlrs.StaticTemplate("home.gohtml", "tailwind.gohtml")) + r.Get("/contact", ctrlrs.StaticTemplate("contact.gohtml", "tailwind.gohtml")) + r.Get("/faq", ctrlrs.FAQ("faq.gohtml", "tailwind.gohtml")) r.NotFound(notFoundHandler) fmt.Println("Starting the server on :3000...") http.ListenAndServe(":3000", r) diff --git a/templates/contact.gohtml b/templates/contact.gohtml index 5b55289..b1a4ba5 100644 --- a/templates/contact.gohtml +++ b/templates/contact.gohtml @@ -1,2 +1,9 @@ -

Contact Page

-

To get in touch, email me at example@example.com

+ + + {{template "head" .}} + +

Contact Page

+

To get in touch, email me at example@example.com

+ {{template "footer" .}} + + diff --git a/templates/faq.gohtml b/templates/faq.gohtml index d103002..4492c8c 100644 --- a/templates/faq.gohtml +++ b/templates/faq.gohtml @@ -1,10 +1,24 @@ -

FAQ

-
-{{range .}} - {{template "qa" .}} -{{end}} + + + {{template "head" .}} + +

FAQ

+
+
+ {{range .}} + {{template "qa" .}} + {{end}} +
+ {{template "footer" .}} + + + + + {{define "qa"}} -

{{.Question}}

-

{{.Answer}}

+
+

{{.Question}}

+

{{.Answer}}

+
{{end}} diff --git a/templates/home.gohtml b/templates/home.gohtml index f7e14f4..2a13949 100644 --- a/templates/home.gohtml +++ b/templates/home.gohtml @@ -1,15 +1,26 @@ -

Welcome to my awesome site!

-{{template "lorem-ipsum"}} -{{template "lorem-ipsum"}} -{{template "lorem-ipsum"}} + + + {{template "head" .}} + +

+ Welcome to my awesome site! +

+
+ {{template "lorem-ipsum"}} + {{template "lorem-ipsum"}} + {{template "lorem-ipsum"}} +
+ {{template "footer" .}} + + {{define "lorem-ipsum"}} -

- Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor - incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis - nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. - Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore - eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt - in culpa qui officia deserunt mollit anim id est laborum. -

+

+ Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor + incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis + nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. + Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore + eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt + in culpa qui officia deserunt mollit anim id est laborum. +

{{end}}