Add Helm 0.3 template renderer.

pull/196/head
Matt Butcher 10 years ago
parent 180bc7da05
commit 5efc021978

@ -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
}

@ -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())
}
}

16
glide.lock generated

@ -1,6 +1,8 @@
hash: db55a031aaa2f352fa5e9e4fda871039afb80e383a57fc77e4b35114d47cca8a hash: 0bcb72b361ed27dccc62c1f6551b21e57c0478ffdc5b2c70c2a0cebab31b4180
updated: 2016-01-26T17:30:54.243252416-07:00 updated: 2016-01-28T16:05:55.056196328-07:00
imports: imports:
- name: github.com/aokoli/goutils
version: 9c37978a95bd5c709a15883b6242714ea6709e64
- name: github.com/emicklei/go-restful - name: github.com/emicklei/go-restful
version: b86acf97a74ed7603ac78d012f5535b4d587b156 version: b86acf97a74ed7603ac78d012f5535b4d587b156
- name: github.com/ghodss/yaml - name: github.com/ghodss/yaml
@ -8,7 +10,7 @@ imports:
- name: github.com/golang/glog - name: github.com/golang/glog
version: 23def4e6c14b4da8ac2ed8007337bc5eb5007998 version: 23def4e6c14b4da8ac2ed8007337bc5eb5007998
- name: github.com/golang/protobuf - name: github.com/golang/protobuf
version: 6aaa8d47701fa6cf07e914ec01fde3d4a1fe79c3 version: 45bba206dd5270d96bac4942dcfe515726613249
- name: github.com/google/go-github - name: github.com/google/go-github
version: b8b4ac742977310ff6e75140a403a38dab109977 version: b8b4ac742977310ff6e75140a403a38dab109977
subpackages: subpackages:
@ -18,13 +20,15 @@ imports:
- name: github.com/gorilla/context - name: github.com/gorilla/context
version: 1c83b3eabd45b6d76072b66b746c20815fb2872d version: 1c83b3eabd45b6d76072b66b746c20815fb2872d
- name: github.com/gorilla/handlers - name: github.com/gorilla/handlers
version: 8f2758070a82adb7a3ad6b223a0b91878f32d400 version: 44328eee346b9614b3fe8ca84e72fe23736afbfb
- name: github.com/gorilla/mux - name: github.com/gorilla/mux
version: 26a6070f849969ba72b72256e9f14cf519751690 version: 26a6070f849969ba72b72256e9f14cf519751690
- name: github.com/gorilla/schema - name: github.com/gorilla/schema
version: 14c555599c2a4f493c1e13fd1ea6fdf721739028 version: 14c555599c2a4f493c1e13fd1ea6fdf721739028
- name: github.com/Masterminds/semver - name: github.com/Masterminds/semver
version: c4f7ef0702f269161a60489ccbbc9f1241ad1265 version: c4f7ef0702f269161a60489ccbbc9f1241ad1265
- name: github.com/Masterminds/sprig
version: 93e0202ba8792558ba3767a3707d8e896eda95c0
- name: github.com/mjibson/appstats - name: github.com/mjibson/appstats
version: 0542d5f0e87ea3a8fa4174322b9532f5d04f9fa8 version: 0542d5f0e87ea3a8fa4174322b9532f5d04f9fa8
- name: golang.org/x/crypto - name: golang.org/x/crypto
@ -39,13 +43,13 @@ imports:
version: "" version: ""
repo: https://google.golang.com/appengine repo: https://google.golang.com/appengine
- name: google.golang.org/api - name: google.golang.org/api
version: 0caa37974a5f5ae67172acf68b4970f7864f994c version: f6ba98773d96b877b246f3a9266493dfc11e276b
- name: google.golang.org/appengine - name: google.golang.org/appengine
version: 6bde959377a90acb53366051d7d587bfd7171354 version: 6bde959377a90acb53366051d7d587bfd7171354
- name: google.golang.org/cloud - name: google.golang.org/cloud
version: fb10e8da373d97f6ba5e648299a10b3b91f14cd5 version: fb10e8da373d97f6ba5e648299a10b3b91f14cd5
- name: google.golang.org/grpc - name: google.golang.org/grpc
version: e29d659177655e589850ba7d3d83f7ce12ef23dd version: 23d551898cf40a24d0ce7a859c75b322a7035673
- name: gopkg.in/yaml.v2 - name: gopkg.in/yaml.v2
version: f7716cbe52baa25d2e9b0d0da546fcf909fc16b4 version: f7716cbe52baa25d2e9b0d0da546fcf909fc16b4
devImports: [] devImports: []

@ -9,3 +9,4 @@ import:
- package: github.com/gorilla/mux - package: github.com/gorilla/mux
- package: gopkg.in/yaml.v2 - package: gopkg.in/yaml.v2
- package: github.com/Masterminds/semver - package: github.com/Masterminds/semver
- package: github.com/Masterminds/sprig

Loading…
Cancel
Save