diff --git a/pkg/handlers/auth.go b/pkg/handlers/auth.go index 7109e32..ec575b4 100644 --- a/pkg/handlers/auth.go +++ b/pkg/handlers/auth.go @@ -20,7 +20,6 @@ import ( "git.grosinger.net/tgrosinger/saasitone/pkg/services" "git.grosinger.net/tgrosinger/saasitone/templ/layouts" "git.grosinger.net/tgrosinger/saasitone/templ/pages" - "git.grosinger.net/tgrosinger/saasitone/templates" ) const ( @@ -79,7 +78,6 @@ func (h *Auth) Routes(g *echo.Group) { func (h *Auth) ForgotPasswordPage(ctx echo.Context) error { p := page.New(ctx) - p.Name = templates.PageForgotPassword p.Title = "Forgot password" f := form.Get[pages.ForgotPasswordForm](ctx) @@ -147,7 +145,6 @@ func (h *Auth) ForgotPasswordSubmit(ctx echo.Context) error { func (h *Auth) LoginPage(ctx echo.Context) error { p := page.New(ctx) - p.Name = templates.PageLogin p.Title = "Log in" f := form.Get[pages.LoginForm](ctx) @@ -221,7 +218,6 @@ func (h *Auth) Logout(ctx echo.Context) error { func (h *Auth) RegisterPage(ctx echo.Context) error { p := page.New(ctx) - p.Name = templates.PageRegister p.Title = "Register" f := form.Get[pages.RegisterForm](ctx) @@ -331,7 +327,6 @@ func (h *Auth) sendVerificationEmail(ctx echo.Context, usr sqlc.User) { func (h *Auth) ResetPasswordPage(ctx echo.Context) error { p := page.New(ctx) - p.Name = templates.PageResetPassword p.Title = "Reset password" f := form.Get[pages.ResetPasswordForm](ctx) diff --git a/pkg/handlers/cache.go b/pkg/handlers/cache.go index 4078d33..a3e3a05 100644 --- a/pkg/handlers/cache.go +++ b/pkg/handlers/cache.go @@ -12,7 +12,6 @@ import ( "git.grosinger.net/tgrosinger/saasitone/pkg/services" "git.grosinger.net/tgrosinger/saasitone/templ/layouts" "git.grosinger.net/tgrosinger/saasitone/templ/pages" - "git.grosinger.net/tgrosinger/saasitone/templates" ) const ( @@ -44,7 +43,6 @@ func (h *Cache) Routes(g *echo.Group) { func (h *Cache) Page(ctx echo.Context) error { p := page.New(ctx) - p.Name = templates.PageCache p.Title = "Set a cache entry" // Fetch the value from the cache diff --git a/pkg/handlers/contact.go b/pkg/handlers/contact.go index 632710a..f23529d 100644 --- a/pkg/handlers/contact.go +++ b/pkg/handlers/contact.go @@ -12,7 +12,6 @@ import ( "git.grosinger.net/tgrosinger/saasitone/pkg/services" "git.grosinger.net/tgrosinger/saasitone/templ/layouts" "git.grosinger.net/tgrosinger/saasitone/templ/pages" - "git.grosinger.net/tgrosinger/saasitone/templates" ) const ( @@ -44,7 +43,6 @@ func (h *Contact) Routes(g *echo.Group) { func (h *Contact) Page(ctx echo.Context) error { p := page.New(ctx) - p.Name = templates.PageContact p.Title = "Contact us" f := form.Get[pages.ContactForm](ctx) diff --git a/pkg/handlers/error.go b/pkg/handlers/error.go index b61dd80..17d02ee 100644 --- a/pkg/handlers/error.go +++ b/pkg/handlers/error.go @@ -12,7 +12,6 @@ import ( "git.grosinger.net/tgrosinger/saasitone/pkg/services" "git.grosinger.net/tgrosinger/saasitone/templ/layouts" "git.grosinger.net/tgrosinger/saasitone/templ/pages" - "git.grosinger.net/tgrosinger/saasitone/templates" ) type Error struct { @@ -41,7 +40,6 @@ func (e *Error) Page(err error, ctx echo.Context) { // Render the error page p := page.New(ctx) - p.Name = templates.PageError p.Title = http.StatusText(code) p.StatusCode = code p.HTMX.Request.Enabled = false diff --git a/pkg/handlers/pages.go b/pkg/handlers/pages.go index 5d030bc..318a1c3 100644 --- a/pkg/handlers/pages.go +++ b/pkg/handlers/pages.go @@ -8,7 +8,6 @@ import ( "git.grosinger.net/tgrosinger/saasitone/pkg/services" "git.grosinger.net/tgrosinger/saasitone/templ/layouts" "git.grosinger.net/tgrosinger/saasitone/templ/pages" - "git.grosinger.net/tgrosinger/saasitone/templates" ) const ( @@ -40,7 +39,6 @@ func (h *Pages) Routes(g *echo.Group) { func (h *Pages) Home(ctx echo.Context) error { p := page.New(ctx) - p.Name = templates.PageHome p.Metatags.Description = "Welcome to the homepage." p.Metatags.Keywords = []string{"Go", "MVC", "Web", "Software"} p.Pager = page.NewPager(ctx, 4) @@ -58,7 +56,6 @@ func (h *Pages) Home(ctx echo.Context) error { func (h *Pages) About(ctx echo.Context) error { p := page.New(ctx) - p.Name = templates.PageAbout p.Title = "About" // This page will be cached! diff --git a/pkg/handlers/search.go b/pkg/handlers/search.go index 687bd50..48ff071 100644 --- a/pkg/handlers/search.go +++ b/pkg/handlers/search.go @@ -11,7 +11,6 @@ import ( "git.grosinger.net/tgrosinger/saasitone/pkg/services" "git.grosinger.net/tgrosinger/saasitone/templ/layouts" "git.grosinger.net/tgrosinger/saasitone/templ/pages" - "git.grosinger.net/tgrosinger/saasitone/templates" ) const routeNameSearch = "search" @@ -37,7 +36,6 @@ func (h *Search) Routes(g *echo.Group) { func (h *Search) Page(ctx echo.Context) error { p := page.New(ctx) - p.Name = templates.PageSearch // Fake search results var results []pages.SearchResult diff --git a/pkg/handlers/task.go b/pkg/handlers/task.go index d1fba5a..85e55e8 100644 --- a/pkg/handlers/task.go +++ b/pkg/handlers/task.go @@ -16,7 +16,6 @@ import ( "git.grosinger.net/tgrosinger/saasitone/pkg/tasks" "git.grosinger.net/tgrosinger/saasitone/templ/layouts" "git.grosinger.net/tgrosinger/saasitone/templ/pages" - "git.grosinger.net/tgrosinger/saasitone/templates" ) const ( @@ -48,7 +47,6 @@ func (h *Task) Routes(g *echo.Group) { func (h *Task) Page(ctx echo.Context) error { p := page.New(ctx) - p.Name = templates.PageTask p.Title = "Create a task" f := form.Get[pages.TaskForm](ctx) diff --git a/pkg/middleware/cache_test.go b/pkg/middleware/cache_test.go index b71db96..292c2ce 100644 --- a/pkg/middleware/cache_test.go +++ b/pkg/middleware/cache_test.go @@ -13,14 +13,12 @@ import ( "git.grosinger.net/tgrosinger/saasitone/pkg/tests" "git.grosinger.net/tgrosinger/saasitone/templ/pages" "git.grosinger.net/tgrosinger/saasitone/templ/layouts" - "git.grosinger.net/tgrosinger/saasitone/templates" ) func TestServeCachedPage(t *testing.T) { // Cache a page ctx, rec := tests.NewContext(c.Web, "/cache") p := page.New(ctx) - p.Name = templates.PageHome p.Cache.Enabled = true p.Cache.Expiration = time.Minute p.StatusCode = http.StatusCreated diff --git a/pkg/page/page.go b/pkg/page/page.go index cd64276..5e847e2 100644 --- a/pkg/page/page.go +++ b/pkg/page/page.go @@ -12,7 +12,6 @@ import ( "git.grosinger.net/tgrosinger/saasitone/pkg/htmx" "git.grosinger.net/tgrosinger/saasitone/pkg/models/sqlc" "git.grosinger.net/tgrosinger/saasitone/pkg/msg" - "git.grosinger.net/tgrosinger/saasitone/templates" ) // Page consists of all data that will be used to render a page response for a given route. @@ -42,24 +41,8 @@ type Page struct { // ToURL is a function to convert a route name and optional route parameters to a URL ToURL func(name string, params ...interface{}) string - // Data stores whatever additional data that needs to be passed to the templates. - // This is what the handler uses to pass the content of the page. - Data any - - // Form stores a struct that represents a form on the page. - // This should be a struct with fields for each form field, using both "form" and "validate" tags - // It should also contain form.FormSubmission if you wish to have validation - // messages and markup presented to the user - Form any - LayoutComponent func(content templ.Component) templ.Component - // Name stores the name of the page as well as the name of the template file which will be used to render - // the content portion of the layout template. - // This should match a template file located within the pages directory inside the templates directory. - // The template extension should not be included in this value. - Name templates.Page - // IsHome stores whether the requested page is the home page or not IsHome bool diff --git a/pkg/services/template_renderer.go b/pkg/services/template_renderer.go index 41d67c5..3a3d135 100644 --- a/pkg/services/template_renderer.go +++ b/pkg/services/template_renderer.go @@ -98,11 +98,6 @@ func (t *TemplateRenderer) Parse() *templateBuilder { } func (t *TemplateRenderer) RenderPageTempl(ctx echo.Context, page page.Page, content templ.Component) error { - // Page name is required - if page.Name == "" { - return echo.NewHTTPError(http.StatusInternalServerError, "page render failed due to missing name") - } - // Use the app name in configuration if a value was not set if page.AppName == "" { page.AppName = t.config.App.Name @@ -201,6 +196,7 @@ func (t *TemplateRenderer) GetCachedPage(ctx echo.Context, url string) (*CachedP return p.(*CachedPage), nil } + // getCacheKey gets a cache key for a given group and ID func (t *TemplateRenderer) getCacheKey(group, key string) string { if group != "" { diff --git a/pkg/services/template_renderer_test.go b/pkg/services/template_renderer_test.go index b2fa82f..d91d9ed 100644 --- a/pkg/services/template_renderer_test.go +++ b/pkg/services/template_renderer_test.go @@ -78,7 +78,6 @@ func TestTemplateRenderer_RenderPage(t *testing.T) { tests.InitSession(ctx) p := page.New(ctx) - p.Name = "test" p.Cache.Enabled = false p.Headers["A"] = "b" p.Headers["C"] = "d" @@ -86,14 +85,6 @@ func TestTemplateRenderer_RenderPage(t *testing.T) { return ctx, rec, p } - t.Run("missing name", func(t *testing.T) { - // Rendering should fail if the Page has no name - ctx, _, p := setup() - p.Name = "" - err := c.TemplateRenderer.RenderPageTempl(ctx, p, pages.Error(p)) - assert.Error(t, err) - }) - t.Run("htmx rendering", func(t *testing.T) { ctx, _, p := setup() p.HTMX.Request.Enabled = true diff --git a/templates/templates.go b/templates/templates.go index 239d489..f7047a5 100644 --- a/templates/templates.go +++ b/templates/templates.go @@ -9,30 +9,6 @@ import ( "runtime" ) -type ( - Layout string - Page string -) - -const ( - LayoutMain Layout = "main" - LayoutHTMX Layout = "htmx" -) - -const ( - PageAbout Page = "about" - PageCache Page = "cache" - PageContact Page = "contact" - PageError Page = "error" - PageForgotPassword Page = "forgot-password" - PageHome Page = "home" - PageLogin Page = "login" - PageRegister Page = "register" - PageResetPassword Page = "reset-password" - PageSearch Page = "search" - PageTask Page = "task" -) - //go:embed * var templates embed.FS