From becd6dacd71a64df6d60b34cebdba44360272271 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 27 May 2015 11:10:09 -0700 Subject: [PATCH] template/interpolate: support custom functions --- template/interpolate/funcs.go | 5 +++++ template/interpolate/i.go | 3 +++ 2 files changed, 8 insertions(+) diff --git a/template/interpolate/funcs.go b/template/interpolate/funcs.go index 1ddbbe167..ca51fea81 100644 --- a/template/interpolate/funcs.go +++ b/template/interpolate/funcs.go @@ -45,6 +45,11 @@ func Funcs(ctx *Context) template.FuncMap { for k, v := range FuncGens { result[k] = v(ctx) } + if ctx != nil { + for k, v := range ctx.Funcs { + result[k] = v + } + } return template.FuncMap(result) } diff --git a/template/interpolate/i.go b/template/interpolate/i.go index d52653fcf..fa3a31395 100644 --- a/template/interpolate/i.go +++ b/template/interpolate/i.go @@ -11,6 +11,9 @@ type Context struct { // Data is the data for the template that is available Data interface{} + // Funcs are extra functions available in the template + Funcs map[string]interface{} + // UserVariables is the mapping of user variables that the // "user" function reads from. UserVariables map[string]string