diff --git a/routes/about.go b/routes/about.go index eacf534..07a8c32 100644 --- a/routes/about.go +++ b/routes/about.go @@ -1,23 +1,57 @@ package routes import ( + "html/template" + "goweb/controller" "github.com/labstack/echo/v4" ) -type About struct { - controller.Controller -} +type ( + About struct { + controller.Controller + } + + AboutData struct { + ShowCacheWarning bool + Tabs []AboutTab + } + + AboutTab struct { + Title string + Body template.HTML + } +) func (c *About) Get(ctx echo.Context) error { page := controller.NewPage(ctx) page.Layout = "main" page.Name = "about" page.Title = "About" - page.Data = "The data field can take in anything you want to send to the templates" - page.Cache.Enabled = false + + // This page will be cached! + page.Cache.Enabled = true page.Cache.Tags = []string{"page_about", "page:list"} + // A simple example of how the Data field can contain anything you want to send to the templates + page.Data = AboutData{ + ShowCacheWarning: true, + Tabs: []AboutTab{ + { + Title: "HTMX", + Body: template.HTML(`Completes HTML as a hypertext by providing attributes to AJAXify anything and much more. Visit htmx.org to learn more.`), + }, + { + Title: "Alpine.js", + Body: template.HTML(`Drop-in, Vue-like functionality written directly in your markup. Visit alpinejs.dev to learn more.`), + }, + { + Title: "Bulma", + Body: template.HTML(`Ready-to-use frontend components that you can easily combine to build responsive web interfaces with no JavaScript requirements. Visit bulma.io to learn more.`), + }, + }, + } + return c.RenderPage(ctx, page) } diff --git a/routes/about_test.go b/routes/about_test.go index acf5dba..359a737 100644 --- a/routes/about_test.go +++ b/routes/about_test.go @@ -7,6 +7,8 @@ import ( "github.com/stretchr/testify/assert" ) +// Simple example of how to test routes and their markup using the test HTTP server spun up within +// this test package func TestAbout_Get(t *testing.T) { doc := request(t). setRoute("about"). @@ -14,6 +16,7 @@ func TestAbout_Get(t *testing.T) { assertStatusCode(http.StatusOK). toDoc() + // Goquery is an excellent package to use for testing HTML markup h1 := doc.Find("h1.title") assert.Len(t, h1.Nodes, 1) assert.Equal(t, "About", h1.Text()) diff --git a/templates/pages/about.gohtml b/templates/pages/about.gohtml index b3cd38c..0a71219 100644 --- a/templates/pages/about.gohtml +++ b/templates/pages/about.gohtml @@ -1,43 +1,28 @@ {{define "content"}} -
{{.Data}}
-The following incredible projects make developing advanced, modern frontends possible and simple without having to write a single line of JS or CSS. You can go extremely far without leaving the comfort of Go with server-side rendered HTML.
+{{.Body}}
| # | -Text Feild 1 | -Remove | -|
|---|---|---|---|
| - | - | - | |
| - | |||