From 2958991c9393caff25672eaaa665349820db284c Mon Sep 17 00:00:00 2001 From: matheusgomes28 Date: Thu, 1 Feb 2024 22:25:21 +0000 Subject: [PATCH] Adding basic tailwind conversion code --- Makefile | 2 ++ app/app.go | 9 +++++--- tailwind.config.js | 12 +++++++++++ views/tailwind/footer.templ | 5 +++++ views/tailwind/header.templ | 33 +++++++++++++++++++++++++++++ views/tailwind/index.templ | 42 +++++++++++++++++++++++++++++++++++++ 6 files changed, 100 insertions(+), 3 deletions(-) create mode 100644 tailwind.config.js create mode 100644 views/tailwind/footer.templ create mode 100644 views/tailwind/header.templ create mode 100644 views/tailwind/index.templ diff --git a/Makefile b/Makefile index 33eec30..786c68b 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,7 @@ # Go parameters GOCMD=go TEMPL=templ +TAILWIND=tailwindcss-linux-x64 BUILD_DIR=./tmp URCHIN_DIR=./cmd/urchin URCHIN_ADMIN_DIR=./cmd/urchin-admin @@ -13,6 +14,7 @@ all: build test build: $(TEMPL) generate + $(TAILWIND) -i ./static/style.css -o ./static/output.css -m $(GOCMD) build -v -o $(BUILD_DIR)/$(BINARY_NAME) $(URCHIN_DIR) $(GOCMD) build -v -o $(BUILD_DIR)/$(ADMIN_BINARY_NAME) $(URCHIN_ADMIN_DIR) diff --git a/app/app.go b/app/app.go index c45e92b..575a91c 100644 --- a/app/app.go +++ b/app/app.go @@ -3,10 +3,12 @@ package app import ( "net/http" + "github.com/a-h/templ" "github.com/gin-gonic/gin" "github.com/matheusgomes28/common" "github.com/matheusgomes28/database" "github.com/matheusgomes28/views" + "github.com/matheusgomes28/views/tailwind" "github.com/rs/zerolog/log" ) @@ -14,7 +16,8 @@ func Run(app_settings common.AppSettings, database database.Database) error { r := gin.Default() r.MaxMultipartMemory = 1 - r.GET("/", makeHomeHandler(app_settings, database)) + r.GET("/", makeHomeHandler(app_settings, database, views.MakeIndex)) + r.GET("/tailwind", makeHomeHandler(app_settings, database, tailwind.MakeIndex)) // Contact form related endpoints r.GET("/contact", makeContactPageHandler(app_settings, database)) @@ -32,7 +35,7 @@ func Run(app_settings common.AppSettings, database database.Database) error { /// This function will act as the handler for /// the home page -func makeHomeHandler(settings common.AppSettings, db database.Database) func(*gin.Context) { +func makeHomeHandler(settings common.AppSettings, db database.Database, factory func([]common.Post) templ.Component) func(*gin.Context) { return func(c *gin.Context){ posts, err := db.GetPosts() if err != nil { @@ -40,6 +43,6 @@ func makeHomeHandler(settings common.AppSettings, db database.Database) func(*gi return } - render(c, http.StatusOK, views.MakeIndex(posts)) + render(c, http.StatusOK, factory(posts)) } } diff --git a/tailwind.config.js b/tailwind.config.js new file mode 100644 index 0000000..2ca95ae --- /dev/null +++ b/tailwind.config.js @@ -0,0 +1,12 @@ +/** @type {import('tailwindcss').Config} */ +module.exports = { + content: ["./**/*.templ"], + theme: { + extend: {}, + fontFamily: { + 'roboto': ['Roboto', 'sans-serif'], + 'bangers': ['Bangers', 'sans-serif'], + } + }, + plugins: [], +} diff --git a/views/tailwind/footer.templ b/views/tailwind/footer.templ new file mode 100644 index 0000000..71c5432 --- /dev/null +++ b/views/tailwind/footer.templ @@ -0,0 +1,5 @@ +package tailwind + +templ MakeFooter() { + +} diff --git a/views/tailwind/header.templ b/views/tailwind/header.templ new file mode 100644 index 0000000..b84f014 --- /dev/null +++ b/views/tailwind/header.templ @@ -0,0 +1,33 @@ +package tailwind + +type Link struct { + Href string + Name string +} + +templ MakeNavBar(links []Link) { +
+ + + + +
+
+} \ No newline at end of file diff --git a/views/tailwind/index.templ b/views/tailwind/index.templ new file mode 100644 index 0000000..0d86c42 --- /dev/null +++ b/views/tailwind/index.templ @@ -0,0 +1,42 @@ +package tailwind + +import ( + "fmt" + . "github.com/matheusgomes28/common" +) + +templ MakeIndex(posts []Post) { + + + + // This should go into Make HTML Headers + + + Menu and Contact Form + + + + + + + @MakeNavBar([]Link{ + {Name: "Home", Href: "/"}, + {Name: "About", Href: "/about"}, + {Name: "Services", Href: "/services"}, + {Name: "Contact", Href: "/contact"}, + }) +
+ for _, post := range posts { + + } +
+ @MakeFooter() + + +}