Skip to content

Commit

Permalink
changed view helper
Browse files Browse the repository at this point in the history
  • Loading branch information
anthdm committed Jun 8, 2024
1 parent 85a106b commit 49f59f0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
7 changes: 6 additions & 1 deletion bootstrap/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ 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
)

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
Expand All @@ -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 => ../
2 changes: 2 additions & 0 deletions bootstrap/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
14 changes: 10 additions & 4 deletions view/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down

0 comments on commit 49f59f0

Please sign in to comment.