mirror of
https://codeberg.org/video-prize-ranch/rimgo.git
synced 2026-01-28 01:21:16 +00:00
add noteq
This commit is contained in:
17
render/helpers.go
Normal file
17
render/helpers.go
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
package render
|
||||||
|
|
||||||
|
import "github.com/mailgun/raymond/v2"
|
||||||
|
|
||||||
|
func (r *renderer) registerHelpers() {
|
||||||
|
funcmap := map[string]any{
|
||||||
|
"noteq": noteq,
|
||||||
|
}
|
||||||
|
raymond.RegisterHelpers(funcmap)
|
||||||
|
}
|
||||||
|
|
||||||
|
func noteq(a, b any, options *raymond.Options) any {
|
||||||
|
if raymond.Str(a) != raymond.Str(b) {
|
||||||
|
return options.Fn()
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
@@ -20,7 +20,6 @@ func Render(out io.Writer, name string, bind map[string]any) error {
|
|||||||
|
|
||||||
type renderer struct {
|
type renderer struct {
|
||||||
templates map[string]*raymond.Template
|
templates map[string]*raymond.Template
|
||||||
funcmap map[string]any
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const ext = ".hbs"
|
const ext = ".hbs"
|
||||||
@@ -28,7 +27,7 @@ const ext = ".hbs"
|
|||||||
func Initialize(views fs.FS) {
|
func Initialize(views fs.FS) {
|
||||||
r := new(renderer)
|
r := new(renderer)
|
||||||
r.templates = make(map[string]*raymond.Template)
|
r.templates = make(map[string]*raymond.Template)
|
||||||
raymond.RegisterHelpers(r.funcmap)
|
r.registerHelpers()
|
||||||
fs.WalkDir(views, "/", func(path string, d fs.DirEntry, err error) error {
|
fs.WalkDir(views, "/", func(path string, d fs.DirEntry, err error) error {
|
||||||
if err != nil || d.IsDir() {
|
if err != nil || d.IsDir() {
|
||||||
return err
|
return err
|
||||||
|
|||||||
Reference in New Issue
Block a user