Store the RawContents of the template on the template object

This allows children to get the raw templates without re-reading the
file.
This commit is contained in:
Seth Vargo 2015-02-03 18:14:21 -05:00
parent 08ba23f10f
commit 5d37c58457
2 changed files with 10 additions and 3 deletions

View File

@ -3,15 +3,16 @@ package packer
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"github.com/hashicorp/go-version"
"github.com/mitchellh/mapstructure"
jsonutil "github.com/mitchellh/packer/common/json"
"io" "io"
"io/ioutil" "io/ioutil"
"os" "os"
"sort" "sort"
"text/template" "text/template"
"time" "time"
"github.com/hashicorp/go-version"
"github.com/mitchellh/mapstructure"
jsonutil "github.com/mitchellh/packer/common/json"
) )
// The rawTemplate struct represents the structure of a template read // The rawTemplate struct represents the structure of a template read
@ -33,6 +34,7 @@ type rawTemplate struct {
// The Template struct represents a parsed template, parsed into the most // The Template struct represents a parsed template, parsed into the most
// completed form it can be without additional processing by the caller. // completed form it can be without additional processing by the caller.
type Template struct { type Template struct {
RawContents []byte
Description string Description string
Variables map[string]RawVariable Variables map[string]RawVariable
Builders map[string]RawBuilderConfig Builders map[string]RawBuilderConfig
@ -163,6 +165,7 @@ func ParseTemplate(data []byte, vars map[string]string) (t *Template, err error)
} }
t = &Template{} t = &Template{}
t.RawContents = data
t.Description = rawTpl.Description t.Description = rawTpl.Description
t.Variables = make(map[string]RawVariable) t.Variables = make(map[string]RawVariable)
t.Builders = make(map[string]RawBuilderConfig) t.Builders = make(map[string]RawBuilderConfig)

View File

@ -58,6 +58,10 @@ func TestParseTemplateFile_basic(t *testing.T) {
if len(result.Builders) != 1 { if len(result.Builders) != 1 {
t.Fatalf("bad: %#v", result.Builders) t.Fatalf("bad: %#v", result.Builders)
} }
if string(result.RawContents) != data {
t.Fatalf("expected %q to be %q", result.RawContents, data)
}
} }
func TestParseTemplateFile_minPackerVersionBad(t *testing.T) { func TestParseTemplateFile_minPackerVersionBad(t *testing.T) {