diff --git a/renderer/funcmap.go b/renderer/funcmap.go index d8f2b24d..1a3a267f 100644 --- a/renderer/funcmap.go +++ b/renderer/funcmap.go @@ -4,6 +4,7 @@ import ( "errors" "fmt" "html/template" + "log" "net/url" "reflect" "strings" @@ -35,9 +36,36 @@ var ( "anchor": anchor, "html": html, "field": field, + "modelName": modelName, + "active": active, + "pluralize": pluralize, + "lower": lower, } ) +func modelName(value interface{}) string { + if t := reflect.TypeOf(value); t.Kind() == reflect.Ptr { + return t.Elem().Name() + } else { + return t.Name() + } +} + +func lower(text string) string { + return strings.ToLower(text) +} + +func pluralize(text string) string { + return inflection.Plural(text) +} + +func active(value string, model interface{}) string { + log.Println(pluralize(lower(modelName(model)))) + if value == pluralize(lower(modelName(model))) { + return "active" + } + return "" +} func field(name string, value interface{}) interface{} { if value != nil { s := reflect.ValueOf(value).Elem() diff --git a/templates/layout/base.html.tpl b/templates/layout/base.html.tpl index 95213792..f32d24cf 100644 --- a/templates/layout/base.html.tpl +++ b/templates/layout/base.html.tpl @@ -11,17 +11,16 @@
-