Skip to content

Commit

Permalink
Replace the handful of custom tpl functions with Sprig.
Browse files Browse the repository at this point in the history
  • Loading branch information
knadh committed May 31, 2023
1 parent 53c3be1 commit 0dea0c9
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 22 deletions.
12 changes: 2 additions & 10 deletions cmd/dictpress/site.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"io"
"net/http"
"net/url"
"strings"

"github.com/Masterminds/sprig/v3"
"github.com/knadh/dictpress/internal/data"
"github.com/knadh/paginator"
"github.com/labstack/echo/v4"
Expand Down Expand Up @@ -182,15 +182,7 @@ func handleStaticPage(c echo.Context) error {

// loadSite loads HTML site theme templates.
func loadSite(path string, loadPages bool) (*template.Template, error) {
t := template.New("site")

// Helper functions.
t.Funcs(template.FuncMap{
"JoinStrings": strings.Join,
"ToUpper": strings.ToUpper,
"ToLower": strings.ToLower,
"Title": strings.Title,
})
t := template.New("site").Funcs(sprig.FuncMap())

// Go percentage encodes unicode characters printed in <a href>,
// but the encoded values are in lowercase hex (for some reason)
Expand Down
18 changes: 14 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/knadh/dictpress
go 1.17

require (
github.com/Masterminds/sprig/v3 v3.2.3
github.com/jmoiron/sqlx v1.3.1
github.com/knadh/goyesql v0.0.0-20190822122127-22fd9176b589
github.com/knadh/knphone v0.0.0-20190624172359-d31f66505cbf
Expand All @@ -17,18 +18,27 @@ require (
)

require (
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver/v3 v3.2.1 // indirect
github.com/fsnotify/fsnotify v1.4.9 // indirect
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/huandu/xstrings v1.4.0 // indirect
github.com/imdario/mergo v0.3.16 // indirect
github.com/labstack/gommon v0.3.1 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/mapstructure v1.4.1 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/pelletier/go-toml v1.8.1 // indirect
github.com/shopspring/decimal v1.3.1 // indirect
github.com/spf13/cast v1.5.1 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.1 // indirect
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f // indirect
golang.org/x/sys v0.0.0-20211103235746-7861aae1554b // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/crypto v0.9.0 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/sys v0.8.0 // indirect
golang.org/x/text v0.9.0 // indirect
golang.org/x/time v0.0.0-20201208040808-7e3f01d25324 // indirect
)

0 comments on commit 0dea0c9

Please sign in to comment.