changed view helper

This commit is contained in:
anthdm 2024-06-08 11:49:34 +02:00
parent 85a106b871
commit 49f59f090f
3 changed files with 18 additions and 5 deletions

View file

@ -8,6 +8,7 @@ require (
)
require (
github.com/anthdm/gothkit v0.0.0-20240608092625-85a106b8717c
github.com/fatih/color v1.16.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
@ -15,7 +16,6 @@ require (
require (
github.com/a-h/templ v0.2.707
github.com/anthdm/gothkit v0.0.0-20240608091251-8198dfa775c8
github.com/go-chi/chi/v5 v5.0.12
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/joho/godotenv v1.5.1
@ -26,3 +26,8 @@ require (
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
golang.org/x/sys v0.19.0 // indirect
)
// Uncomment this if you are working directly on the core gothkit repo.
// This will directly reflect changes you've made in the gothkit core repo
// to the bootstrap folder.
// replace github.com/anthdm/gothkit => ../

View file

@ -2,6 +2,8 @@ github.com/a-h/templ v0.2.707 h1:T1Gkd2ugbRglZ9rYw/VBchWOSZVKmetDbBkm4YubM7U=
github.com/a-h/templ v0.2.707/go.mod h1:5cqsugkq9IerRNucNsI4DEamdHPsoGMQy99DzydLhM8=
github.com/anthdm/gothkit v0.0.0-20240608091251-8198dfa775c8 h1:2C+WGVrNvIiSLFLJRRgKasJ8aWXR2pfsOh3T5flcMwI=
github.com/anthdm/gothkit v0.0.0-20240608091251-8198dfa775c8/go.mod h1:/zW/YMI9hOvRTQwmpfRU+CoJ+m4LZYuzC496KFOJAM8=
github.com/anthdm/gothkit v0.0.0-20240608092625-85a106b8717c h1:JYV/co6zKfSR4eR/MVORi6wQvva1tikbBS8Xgd2GVFc=
github.com/anthdm/gothkit v0.0.0-20240608092625-85a106b8717c/go.mod h1:/zW/YMI9hOvRTQwmpfRU+CoJ+m4LZYuzC496KFOJAM8=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=

View file

@ -5,17 +5,22 @@ import (
"fmt"
"net/url"
"github.com/a-h/templ"
"github.com/anthdm/gothkit/kit"
"github.com/anthdm/gothkit/kit/middleware"
)
func Asset(name string) templ.SafeURL {
return templ.URL(fmt.Sprintf("/public/assets/%s", name))
// Asset is view helper that returns the full asset path as a
// string based on the given asset name.
//
// view.Asset("styles.css") // => /public/assets/styles.css.
func Asset(name string) string {
return fmt.Sprintf("/public/assets/%s", name)
}
// Auth is a view helper function that returns the current Auth.
// If Auth is not set a default auth will be returned
//
// view.Auth(ctx)
func Auth(ctx context.Context) kit.Auth {
value, ok := ctx.Value(kit.AuthKey{}).(kit.Auth)
if !ok {
@ -26,7 +31,8 @@ func Auth(ctx context.Context) kit.Auth {
// URL is a view helper that returns the current URL.
// The request path can be acccessed with:
// view.URL(ctx).Path
//
// view.URL(ctx).Path // => ex. /login
func URL(ctx context.Context) *url.URL {
value, ok := ctx.Value(middleware.RequestURLKey{}).(*url.URL)
if !ok {