From 690b0f8ff5795318dfa3834a5a75d6623e7d934a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Mon, 1 May 2017 18:40:34 +0200 Subject: tpl: Add docshelper for template funcs And fix some other minor related issues. Updates #3418 --- tpl/inflect/init.go | 43 +++++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 16 deletions(-) (limited to 'tpl/inflect') 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) -- cgit v1.2.3