Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/hugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2017-05-01 19:40:34 +0300
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2017-05-01 22:44:15 +0300
commit690b0f8ff5795318dfa3834a5a75d6623e7d934a (patch)
tree1112306f4c6fecc0966d880dec702c3804633deb /tpl/inflect
parente2b067f0504ba41ef45786e2f83d7002bd13a7eb (diff)
tpl: Add docshelper for template funcs
And fix some other minor related issues. Updates #3418
Diffstat (limited to 'tpl/inflect')
-rw-r--r--tpl/inflect/init.go43
1 files changed, 27 insertions, 16 deletions
diff --git a/tpl/inflect/init.go b/tpl/inflect/init.go
index b42ae5af3..50d012d35 100644
--- a/tpl/inflect/init.go
+++ b/tpl/inflect/init.go
@@ -24,26 +24,37 @@ func init() {
f := func(d *deps.Deps) *internal.TemplateFuncsNamespace {
ctx := New()
- examples := [][2]string{
- {`{{ humanize "my-first-post" }}`, `My first post`},
- {`{{ humanize "myCamelPost" }}`, `My camel post`},
- {`{{ humanize "52" }}`, `52nd`},
- {`{{ humanize 103 }}`, `103rd`},
- {`{{ "cat" | pluralize }}`, `cats`},
- {`{{ "cats" | singularize }}`, `cat`},
- }
-
- return &internal.TemplateFuncsNamespace{
+ ns := &internal.TemplateFuncsNamespace{
Name: name,
Context: func() interface{} { return ctx },
- Aliases: map[string]interface{}{
- "humanize": ctx.Humanize,
- "pluralize": ctx.Pluralize,
- "singularize": ctx.Singularize,
- },
- Examples: examples,
}
+ ns.AddMethodMapping(ctx.Humanize,
+ []string{"humanize"},
+ [][2]string{
+ {`{{ humanize "my-first-post" }}`, `My first post`},
+ {`{{ humanize "myCamelPost" }}`, `My camel post`},
+ {`{{ humanize "52" }}`, `52nd`},
+ {`{{ humanize 103 }}`, `103rd`},
+ },
+ )
+
+ ns.AddMethodMapping(ctx.Pluralize,
+ []string{"pluralize"},
+ [][2]string{
+ {`{{ "cat" | pluralize }}`, `cats`},
+ },
+ )
+
+ ns.AddMethodMapping(ctx.Singularize,
+ []string{"singularize"},
+ [][2]string{
+ {`{{ "cats" | singularize }}`, `cat`},
+ },
+ )
+
+ return ns
+
}
internal.AddTemplateFuncsNamespace(f)