diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2017-05-01 18:40:34 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2017-05-01 21:44:15 +0200 |
commit | 690b0f8ff5795318dfa3834a5a75d6623e7d934a (patch) | |
tree | 1112306f4c6fecc0966d880dec702c3804633deb /tpl/time | |
parent | e2b067f0504ba41ef45786e2f83d7002bd13a7eb (diff) |
tpl: Add docshelper for template funcs
And fix some other minor related issues.
Updates #3418
Diffstat (limited to 'tpl/time')
-rw-r--r-- | tpl/time/init.go | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/tpl/time/init.go b/tpl/time/init.go index d91c1376f..33f8a7dbb 100644 --- a/tpl/time/init.go +++ b/tpl/time/init.go @@ -24,22 +24,32 @@ func init() { f := func(d *deps.Deps) *internal.TemplateFuncsNamespace { ctx := New() - examples := [][2]string{ - {`{{ (time "2015-01-21").Year }}`, `2015`}, - {`dateFormat: {{ dateFormat "Monday, Jan 2, 2006" "2015-01-21" }}`, `dateFormat: Wednesday, Jan 21, 2015`}, - } - - return &internal.TemplateFuncsNamespace{ + ns := &internal.TemplateFuncsNamespace{ Name: name, Context: func() interface{} { return ctx }, - Aliases: map[string]interface{}{ - "dateFormat": ctx.Format, - "now": ctx.Now, - "time": ctx.AsTime, - }, - Examples: examples, } + ns.AddMethodMapping(ctx.Format, + []string{"dateFormat"}, + [][2]string{ + {`dateFormat: {{ dateFormat "Monday, Jan 2, 2006" "2015-01-21" }}`, `dateFormat: Wednesday, Jan 21, 2015`}, + }, + ) + + ns.AddMethodMapping(ctx.Now, + []string{"now"}, + [][2]string{}, + ) + + ns.AddMethodMapping(ctx.AsTime, + []string{"asTime"}, // TODO(bep) handle duplicate + [][2]string{ + {`{{ (asTime "2015-01-21").Year }}`, `2015`}, + }, + ) + + return ns + } internal.AddTemplateFuncsNamespace(f) |