Remove unused Page properties

This commit is contained in:
Tony Grosinger 2024-07-27 12:07:17 -07:00
parent 48dd3433a7
commit 9b057ae87e
12 changed files with 1 additions and 75 deletions

View File

@ -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)

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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!

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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 != "" {

View File

@ -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

View File

@ -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