diff --git a/expandybird/gotpl/template.go b/expandybird/gotpl/template.go new file mode 100644 index 000000000..51f6b7c47 --- /dev/null +++ b/expandybird/gotpl/template.go @@ -0,0 +1,26 @@ +package action + +import ( + "io" + "text/template" + + "github.com/Masterminds/sprig" + "github.com/kubernetes/deployment-manager/log" +) + +// Render renders a template and values into an output stream. +// +// tpl should be a string template. +func Render(out io.Writer, tpl string, vals interface{}) error { + t, err := template.New("helmTpl").Funcs(sprig.TxtFuncMap()).Parse(tpl) + if err != nil { + return err + } + + log.Debug("Vals: %#v", vals) + + if err := t.ExecuteTemplate(out, "helmTpl", vals); err != nil { + return err + } + return nil +} diff --git a/expandybird/gotpl/template_test.go b/expandybird/gotpl/template_test.go new file mode 100644 index 000000000..0ba55ba88 --- /dev/null +++ b/expandybird/gotpl/template_test.go @@ -0,0 +1,21 @@ +package action + +import ( + "bytes" + "testing" +) + +func TestRender(t *testing.T) { + var b bytes.Buffer + + tpl := `{{.Hello | upper}}` + vals := map[string]string{"Hello": "hello"} + + if err := Render(&b, tpl, vals); err != nil { + t.Errorf("Failed to compile/render template: %s", err) + } + + if b.String() != "HELLO" { + t.Errorf("Expected HELLO. Got %q", b.String()) + } +} diff --git a/glide.lock b/glide.lock index 2e98b0206..5809e9d10 100644 --- a/glide.lock +++ b/glide.lock @@ -1,6 +1,8 @@ -hash: db55a031aaa2f352fa5e9e4fda871039afb80e383a57fc77e4b35114d47cca8a -updated: 2016-01-26T17:30:54.243252416-07:00 +hash: 0bcb72b361ed27dccc62c1f6551b21e57c0478ffdc5b2c70c2a0cebab31b4180 +updated: 2016-01-28T16:05:55.056196328-07:00 imports: +- name: github.com/aokoli/goutils + version: 9c37978a95bd5c709a15883b6242714ea6709e64 - name: github.com/emicklei/go-restful version: b86acf97a74ed7603ac78d012f5535b4d587b156 - name: github.com/ghodss/yaml @@ -8,7 +10,7 @@ imports: - name: github.com/golang/glog version: 23def4e6c14b4da8ac2ed8007337bc5eb5007998 - name: github.com/golang/protobuf - version: 6aaa8d47701fa6cf07e914ec01fde3d4a1fe79c3 + version: 45bba206dd5270d96bac4942dcfe515726613249 - name: github.com/google/go-github version: b8b4ac742977310ff6e75140a403a38dab109977 subpackages: @@ -18,13 +20,15 @@ imports: - name: github.com/gorilla/context version: 1c83b3eabd45b6d76072b66b746c20815fb2872d - name: github.com/gorilla/handlers - version: 8f2758070a82adb7a3ad6b223a0b91878f32d400 + version: 44328eee346b9614b3fe8ca84e72fe23736afbfb - name: github.com/gorilla/mux version: 26a6070f849969ba72b72256e9f14cf519751690 - name: github.com/gorilla/schema version: 14c555599c2a4f493c1e13fd1ea6fdf721739028 - name: github.com/Masterminds/semver version: c4f7ef0702f269161a60489ccbbc9f1241ad1265 +- name: github.com/Masterminds/sprig + version: 93e0202ba8792558ba3767a3707d8e896eda95c0 - name: github.com/mjibson/appstats version: 0542d5f0e87ea3a8fa4174322b9532f5d04f9fa8 - name: golang.org/x/crypto @@ -39,13 +43,13 @@ imports: version: "" repo: https://google.golang.com/appengine - name: google.golang.org/api - version: 0caa37974a5f5ae67172acf68b4970f7864f994c + version: f6ba98773d96b877b246f3a9266493dfc11e276b - name: google.golang.org/appengine version: 6bde959377a90acb53366051d7d587bfd7171354 - name: google.golang.org/cloud version: fb10e8da373d97f6ba5e648299a10b3b91f14cd5 - name: google.golang.org/grpc - version: e29d659177655e589850ba7d3d83f7ce12ef23dd + version: 23d551898cf40a24d0ce7a859c75b322a7035673 - name: gopkg.in/yaml.v2 version: f7716cbe52baa25d2e9b0d0da546fcf909fc16b4 devImports: [] diff --git a/glide.yaml b/glide.yaml index be7d7dc53..818716509 100644 --- a/glide.yaml +++ b/glide.yaml @@ -9,3 +9,4 @@ import: - package: github.com/gorilla/mux - package: gopkg.in/yaml.v2 - package: github.com/Masterminds/semver +- package: github.com/Masterminds/sprig