mirror of https://github.com/mickael-menu/zk
Add the {{slug}} template helper
parent
76ac1d1bb1
commit
6dfa9b6949
@ -1 +1 @@
|
||||
Salut, <{{name}}>!
|
||||
Salut, {{name}}!
|
||||
|
@ -0,0 +1,22 @@
|
||||
package helpers
|
||||
|
||||
import (
|
||||
"github.com/aymerick/raymond"
|
||||
"github.com/gosimple/slug"
|
||||
"github.com/mickael-menu/zk/util"
|
||||
)
|
||||
|
||||
// FIXME Support custom languages with slug.MakeLang()
|
||||
func RegisterSlug(logger util.Logger, lang string) {
|
||||
raymond.RegisterHelper("slug", func(opt interface{}) string {
|
||||
switch arg := opt.(type) {
|
||||
case *raymond.Options:
|
||||
return slug.MakeLang(arg.Fn(), lang)
|
||||
case string:
|
||||
return slug.MakeLang(arg, lang)
|
||||
default:
|
||||
logger.Printf("the {{slug}} template helper is expecting a string as argument, received: %v", opt)
|
||||
return ""
|
||||
}
|
||||
})
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package util
|
||||
|
||||
// Logger can be used to report logging messages.
|
||||
// The native log.Logger type implements this interface.
|
||||
type Logger interface {
|
||||
Printf(format string, v ...interface{})
|
||||
Println(v ...interface{})
|
||||
}
|
Loading…
Reference in New Issue