Example #1
0
func (e *engine) writeTemplate(t tpl.Templater) (err error) {
	f, err := os.Create(filepath.Join(e.outDir, t.BaseFilename()))
	if err != nil {
		return err
	}
	defer func() {
		if cerr := f.Close(); cerr != nil {
			err = cerr
		}
	}()
	w := bufio.NewWriter(f)
	defer func() {
		if cerr := w.Flush(); cerr != nil {
			err = cerr
		}
	}()
	err = e.renderTemplate(t, w)
	return err
}
Example #2
0
func (e *engine) renderTemplate(tpl tpl.Templater, outWriter io.Writer) error {
	var buffer bytes.Buffer
	err := tpl.Content(&buffer)
	if err != nil {
		return err
	}
	tmpl, err := template.New("tpl").Funcs(templateFuncs).Parse(buffer.String())
	if err != nil {
		return err
	}
	return tmpl.Execute(outWriter, e.renderOptions)
}
Example #3
0
		createTemplateFile(tmpDir, "packer.json.provisioners.partial")
		createTemplateFile(tmpDir, "Vagrantfile.template")
	})
	JustBeforeEach(func() {
		templates = tpl.New(tmpDir, osName)
	})
	AfterEach(func() {
		os.RemoveAll(tmpDir)
	})

	Context("Windows2012r2", func() {
		BeforeEach(func() {
			osName = "windows2012r2"
		})
		Describe("Autounattend.xml.template root template", func() {
			var rootTemplate tpl.Templater
			JustBeforeEach(func() {
				rootTemplate = templates.FindTemplate(filepath.Join(tmpDir, "Autounattend.xml.template"))
			})
			It("should be found", func() {
				Expect(rootTemplate).ToNot(BeNil())
			})
			It("should have 2 partial templates", func() {
				Expect(rootTemplate.ListTemplates()).To(HaveLen(2))
			})
			It("should include Autounattend.xml.oobe.partial", func() {
				path := filepath.Join(tmpDir, "Autounattend.xml.oobe.partial")
				Expect(rootTemplate.FindTemplate(path)).ToNot(BeNil())
			})
			It("should include Autounattend.xml.disks.partial", func() {
				path := filepath.Join(tmpDir, "Autounattend.xml.disks.partial")