Templates partials

pull/811/head
MouseRage 9 years ago
parent 632756a653
commit 66d04cbb6e

@ -5,8 +5,10 @@ import (
"errors" "errors"
"fmt" "fmt"
"log" "log"
"path"
"regexp" "regexp"
"sort" "sort"
"strings"
"github.com/technosophos/moniker" "github.com/technosophos/moniker"
ctx "golang.org/x/net/context" ctx "golang.org/x/net/context"
@ -213,6 +215,11 @@ func (s *releaseServer) InstallRelease(c ctx.Context, req *services.InstallRelea
b := bytes.NewBuffer(nil) b := bytes.NewBuffer(nil)
for name, file := range files { for name, file := range files {
// Ignore templates that starts with underscore to handle them as partials
if strings.HasPrefix(path.Base(name), "_") {
continue
}
// Ignore empty documents because the Kubernetes library can't handle // Ignore empty documents because the Kubernetes library can't handle
// them. // them.
if len(file) > 0 { if len(file) > 0 {

@ -97,6 +97,8 @@ func TestInstallReleaseDryRun(t *testing.T) {
{Name: "hello", Data: []byte("hello: world")}, {Name: "hello", Data: []byte("hello: world")},
{Name: "goodbye", Data: []byte("goodbye: world")}, {Name: "goodbye", Data: []byte("goodbye: world")},
{Name: "empty", Data: []byte("")}, {Name: "empty", Data: []byte("")},
{Name: "with-partials", Data: []byte("hello: {{ template \"partials/_planet\" . }}")},
{Name: "partials/_planet", Data: []byte("Earth")},
}, },
}, },
DryRun: true, DryRun: true,
@ -117,6 +119,14 @@ func TestInstallReleaseDryRun(t *testing.T) {
t.Errorf("unexpected output: %s", res.Release.Manifest) t.Errorf("unexpected output: %s", res.Release.Manifest)
} }
if !strings.Contains(res.Release.Manifest, "hello: Earth") {
t.Errorf("Should contain partial content. %s", res.Release.Manifest)
}
if strings.Contains(res.Release.Manifest, "hello: {{ template \"partials/_planet\" . }}") {
t.Errorf("Should not contain partial templates itself. %s", res.Release.Manifest)
}
if strings.Contains(res.Release.Manifest, "empty") { if strings.Contains(res.Release.Manifest, "empty") {
t.Errorf("Should not contain template data for an empty file. %s", res.Release.Manifest) t.Errorf("Should not contain template data for an empty file. %s", res.Release.Manifest)
} }

Loading…
Cancel
Save