// Set the template to be used
// "files" or "file"
973523
func (t *Template) Set(name string) error {
	t.name = name
	if name != "files" && name != "file" {
		return errors.New(`Error: Template must be "files" or "file"`)
	}

	if name == "files" {
		t.template = filesTemplate
	} else if name == "file" {
		t.template = fileTemplate
	}

	return nil
}
933352
func (s *EnvironmentDescription) SetTemplateName(v string) *EnvironmentDescription {
	s.TemplateName = &v
	return s
}
775633
func (s *DescribeEventsInput) SetTemplateName(v string) *DescribeEventsInput {
	s.TemplateName = &v
	return s
}
1107277
func (email *Email) SetTemplate(htmlTemplate string) {
	email.rw.Lock()
	defer email.rw.Unlock()

	// parse email htmlTemplate, will panic if fails
	email.template = template.Must(template.New("email").Funcs(
		template.FuncMap{
			"ts": func(e log.Entry) (ts string) {
				ts = e.Timestamp.Format(email.timestampFormat)
				return
			},
		},
	).Parse(htmlTemplate))
}
587194
func execTemplate(c *Config, mdata metadata.Metadata, meta map[string]string, files []FileInfo, ctx httpserver.Context) ([]byte, error) {
	mdData := Data{
		Context: ctx,
		Doc:     mdata.Variables,
		Styles:  c.Styles,
		Scripts: c.Scripts,
		Meta:    meta,
		Files:   files,
	}

	b := new(bytes.Buffer)
	if err := c.Template.ExecuteTemplate(b, mdata.Template, mdData); err != nil {
		return nil, err
	}

	return b.Bytes(), nil
}
105149
func (loader *MapLoader) LoadTemplate(name string) (string, error) {
	if src, ok := (*loader)[name]; ok {
		return src, nil
	}
	return "", Errorf("Could not find template " + name)
}
163035
func (c *Clientset) Template() templateinternalversion.TemplateInterface {
	return &faketemplateinternalversion.FakeTemplate{Fake: &c.Fake}
}
252567
func (r *Router) Template(t *template.Template) {
	r.Lock()
	defer r.Unlock()
	r.views = template.Must(t.Clone())
}
1221228
func (_class VMClass) SetIsATemplate(sessionID SessionRef, self VMRef, value bool) (_err error) {
	_method := "VM.set_is_a_template"
	_sessionIDArg, _err := convertSessionRefToXen(fmt.Sprintf("%s(%s)", _method, "session_id"), sessionID)
	if _err != nil {
		return
	}
	_selfArg, _err := convertVMRefToXen(fmt.Sprintf("%s(%s)", _method, "self"), self)
	if _err != nil {
		return
	}
	_valueArg, _err := convertBoolToXen(fmt.Sprintf("%s(%s)", _method, "value"), value)
	if _err != nil {
		return
	}
	_, _err =  _class.client.APICall(_method, _sessionIDArg, _selfArg, _valueArg)
	return
}
473467
func (s *CreateChangeSetInput) SetTemplateBody(v string) *CreateChangeSetInput {
	s.TemplateBody = &v
	return s
}
415419
func (s *CreateStackInput) SetTemplateURL(v string) *CreateStackInput {
	s.TemplateURL = &v
	return s
}
1297993
func (s *UpdateTemplateInput) SetTemplate(v *Template) *UpdateTemplateInput {
	s.Template = v
	return s
}
605897
func compileTemplate(p, base string) error {
	ext := path.Ext(p)
	c, ok := compilers[ext]
	// Ignore file if no template compiler exist for this extension
	if ok {
		t, err := c.Compile(p)
		if err != nil {
			return err
		}
		key, err := filepath.Rel(base, p)
		if err != nil {
			return err
		}
		ghost.LogFn("ghost.templates : storing template for file %s", key)
		templaters[key] = t
	}
	return nil
}
552767
func writeTemplate(fileName string, tmpl *template.Template, data interface{}) {
	buf := &bytes.Buffer{}
	err := tmpl.Execute(buf, data)
	if err != nil {
		log.Fatal(err)
	}

	formatted, err := format.Source(buf.Bytes())
	if err != nil {
		log.Fatal(err)
	}

	fd, err := os.Create(fileName)
	if err != nil {
		log.Fatal(err)
	}
	defer fd.Close()

	fd.Write(formatted)
}
872159
func (t *Templater) Add(path, content string) (err error) {
	// Lock
	t.m.Lock()
	defer t.m.Unlock()

	// Parse content
	var tpl = template.New("root")
	if tpl, err = tpl.Parse(content); err != nil {
		err = errors.Wrapf(err, "astitemplate: parsing template content for path %s failed", path)
		return
	}

	// Parse files
	if tpl, err = tpl.ParseFiles(t.layouts...); err != nil {
		err = errors.Wrapf(err, "astitemplate: parsing layouts %s for path %s failed", strings.Join(t.layouts, ", "), path)
		return
	}

	// Add template
	t.templates[path] = tpl
	return
}
907638
func (s *EventDescription) SetTemplateName(v string) *EventDescription {
	s.TemplateName = &v
	return s
}
1306182
func (r *rawTemplate) Template() (*Template, error) {
	var result Template
	var errs error

	// Copy some literals
	result.Description = r.Description
	result.MinVersion = r.MinVersion
	result.RawContents = r.RawContents

	// Gather the comments
	if len(r.Comments) > 0 {
		result.Comments = make(map[string]string, len(r.Comments))

		for _, c := range r.Comments {
			for k, v := range c {
				result.Comments[k] = v
			}
		}
	}

	// Gather the variables
	if len(r.Variables) > 0 {
		result.Variables = make(map[string]*Variable, len(r.Variables))
	}

	for k, rawV := range r.Variables {
		var v Variable
		v.Key = k

		// Variable is required if the value is exactly nil
		v.Required = rawV == nil

		// Weak decode the default if we have one
		if err := r.decoder(&v.Default, nil).Decode(rawV); err != nil {
			errs = multierror.Append(errs, fmt.Errorf(
				"variable %s: %s", k, err))
			continue
		}

		for _, sVar := range r.SensitiveVariables {
			if sVar == k {
				result.SensitiveVariables = append(result.SensitiveVariables, &v)
			}
		}

		result.Variables[k] = &v
	}

	// Let's start by gathering all the builders
	if len(r.Builders) > 0 {
		result.Builders = make(map[string]*Builder, len(r.Builders))
	}
	for i, rawB := range r.Builders {
		var b Builder
		if err := mapstructure.WeakDecode(rawB, &b); err != nil {
			errs = multierror.Append(errs, fmt.Errorf(
				"builder %d: %s", i+1, err))
			continue
		}

		// Set the raw configuration and delete any special keys
		b.Config = rawB.(map[string]interface{})

		delete(b.Config, "name")
		delete(b.Config, "type")

		if len(b.Config) == 0 {
			b.Config = nil
		}

		// If there is no type set, it is an error
		if b.Type == "" {
			errs = multierror.Append(errs, fmt.Errorf(
				"builder %d: missing 'type'", i+1))
			continue
		}

		// The name defaults to the type if it isn't set
		if b.Name == "" {
			b.Name = b.Type
		}

		// If this builder already exists, it is an error
		if _, ok := result.Builders[b.Name]; ok {
			errs = multierror.Append(errs, fmt.Errorf(
				"builder %d: builder with name '%s' already exists",
				i+1, b.Name))
			continue
		}

		// Append the builders
		result.Builders[b.Name] = &b
	}

	// Gather all the post-processors
	if len(r.PostProcessors) > 0 {
		result.PostProcessors = make([][]*PostProcessor, 0, len(r.PostProcessors))
	}
	for i, v := range r.PostProcessors {
		// Parse the configurations. We need to do this because post-processors
		// can take three different formats.
		configs, err := r.parsePostProcessor(i, v)
		if err != nil {
			errs = multierror.Append(errs, err)
			continue
		}

		// Parse the PostProcessors out of the configs
		pps := make([]*PostProcessor, 0, len(configs))
		for j, c := range configs {
			var pp PostProcessor
			if err := r.decoder(&pp, nil).Decode(c); err != nil {
				errs = multierror.Append(errs, fmt.Errorf(
					"post-processor %d.%d: %s", i+1, j+1, err))
				continue
			}

			// Type is required
			if pp.Type == "" {
				errs = multierror.Append(errs, fmt.Errorf(
					"post-processor %d.%d: type is required", i+1, j+1))
				continue
			}

			// Set the raw configuration and delete any special keys
			pp.Config = c

			// The name defaults to the type if it isn't set
			if pp.Name == "" {
				pp.Name = pp.Type
			}

			delete(pp.Config, "except")
			delete(pp.Config, "only")
			delete(pp.Config, "keep_input_artifact")
			delete(pp.Config, "type")
			delete(pp.Config, "name")

			if len(pp.Config) == 0 {
				pp.Config = nil
			}

			pps = append(pps, &pp)
		}

		result.PostProcessors = append(result.PostProcessors, pps)
	}

	// Gather all the provisioners
	if len(r.Provisioners) > 0 {
		result.Provisioners = make([]*Provisioner, 0, len(r.Provisioners))
	}
	for i, v := range r.Provisioners {
		var p Provisioner
		if err := r.decoder(&p, nil).Decode(v); err != nil {
			errs = multierror.Append(errs, fmt.Errorf(
				"provisioner %d: %s", i+1, err))
			continue
		}

		// Type is required before any richer validation
		if p.Type == "" {
			errs = multierror.Append(errs, fmt.Errorf(
				"provisioner %d: missing 'type'", i+1))
			continue
		}

		// Set the raw configuration and delete any special keys
		p.Config = v.(map[string]interface{})

		delete(p.Config, "except")
		delete(p.Config, "only")
		delete(p.Config, "override")
		delete(p.Config, "pause_before")
		delete(p.Config, "type")
		delete(p.Config, "timeout")

		if len(p.Config) == 0 {
			p.Config = nil
		}

		result.Provisioners = append(result.Provisioners, &p)
	}

	// Push
	if len(r.Push) > 0 {
		var p Push
		if err := r.decoder(&p, nil).Decode(r.Push); err != nil {
			errs = multierror.Append(errs, fmt.Errorf(
				"push: %s", err))
		}

		result.Push = p
	}

	// If we have errors, return those with a nil result
	if errs != nil {
		return nil, errs
	}

	return &result, nil
}