// writeTemplate writes the given template to the given file, with the given
// data. Templates are assumed to be generating go source files, so they
// are formatted as well.
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)
}
425485
func (t *templateHandler) AddTemplate(name, tpl string) error {
	h := t.getTemplateHandler(name)
	_, err := h.addTemplate(name, tpl)
	if err != nil {
		return err
	}
	return nil
}
518759
func AddTemplates(files ...string) Option {
	return func(r *Renderer) error {
		if len(files) == 0 {
			return errors.New("render: no templates passed")
		}
		r.templateFiles = files
		return nil
	}
}
1344590
func (g *Generator) ProcessTemplate(tmplName, tmpl string, data interface{}) error {
	vars := []string{}
	for varName, varValue := range g.vars {
		vars = append(vars, fmt.Sprintf("{{ $%s := %q }}", varName, varValue))
	}

	if len(vars) > 0 {
		tmpl = strings.Join(vars, "\n") + "\n" + tmpl
	}

	t, err := template.New(tmplName).Funcs(g.templateFuncs).Parse(tmpl)
	if err != nil {
		return fmt.Errorf("failed to parse template: %v\n%s", err, tmpl)
	}

	if err := t.Execute(g.body, data); err != nil {
		return fmt.Errorf("failed to execute template: %v", err)
	}

	return nil
}
852217
func NewTemplate(input string) (*Template, error) {
	hm, err := NewHelperMap()
	if err != nil {
		return nil, errors.WithStack(err)
	}
	t := &Template{
		Input:   input,
		Helpers: hm,
	}
	err = t.Parse()
	if err != nil {
		return t, errors.WithStack(err)
	}
	return t, nil
}
1275586
func loadTemplate(name string, path string) {
	// Read the html template file.
	data, err := ioutil.ReadFile(path)
	if err != nil {
		log.Fatalln(err)
	}

	// Create a template value for this code.
	tmpl, err := template.New(name).Parse(string(data))
	if err != nil {
		log.Fatalln(err)
	}

	// Have we processed this file already?
	if _, exists := views[name]; exists {
		log.Fatalf("Template %s already in use.", name)
	}

	// Store the template for use.
	views[name] = tmpl
}
932657
func NewTemplate(descs []*protokit.FileDescriptor) *Template {
	files := make([]*File, 0, len(descs))

	for _, f := range descs {
		file := &File{
			Name:          f.GetName(),
			Description:   description(f.GetSyntaxComments().String()),
			Package:       f.GetPackage(),
			HasEnums:      len(f.Enums) > 0,
			HasExtensions: len(f.Extensions) > 0,
			HasMessages:   len(f.Messages) > 0,
			HasServices:   len(f.Services) > 0,
			Enums:         make(orderedEnums, 0, len(f.Enums)),
			Extensions:    make(orderedExtensions, 0, len(f.Extensions)),
			Messages:      make(orderedMessages, 0, len(f.Messages)),
			Services:      make(orderedServices, 0, len(f.Services)),
			Options:       mergeOptions(extractOptions(f.GetOptions()), extensions.Transform(f.OptionExtensions)),
		}

		for _, e := range f.Enums {
			file.Enums = append(file.Enums, parseEnum(e))
		}

		for _, e := range f.Extensions {
			file.Extensions = append(file.Extensions, parseFileExtension(e))
		}

		// Recursively add nested types from messages
		var addFromMessage func(*protokit.Descriptor)
		addFromMessage = func(m *protokit.Descriptor) {
			file.Messages = append(file.Messages, parseMessage(m))
			for _, e := range m.Enums {
				file.Enums = append(file.Enums, parseEnum(e))
			}
			for _, n := range m.Messages {
				addFromMessage(n)
			}
		}
		for _, m := range f.Messages {
			addFromMessage(m)
		}

		for _, s := range f.Services {
			file.Services = append(file.Services, parseService(s))
		}

		sort.Sort(file.Enums)
		sort.Sort(file.Extensions)
		sort.Sort(file.Messages)
		sort.Sort(file.Services)

		files = append(files, file)
	}

	return &Template{Files: files, Scalars: makeScalars()}
}
252567
func (r *Router) Template(t *template.Template) {
	r.Lock()
	defer r.Unlock()
	r.views = template.Must(t.Clone())
}
93526
func (s *TemplateService) CopyTemplate(p *CopyTemplateParams) (*CopyTemplateResponse, error) {
	resp, err := s.cs.newRequest("copyTemplate", p.toURLValues())
	if err != nil {
		return nil, err
	}

	var r CopyTemplateResponse
	if err := json.Unmarshal(resp, &r); err != nil {
		return nil, err
	}

	// If we have a async client, we need to wait for the async result
	if s.cs.async {
		b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
		if err != nil {
			if err == AsyncTimeoutErr {
				return &r, err
			}
			return nil, err
		}

		b, err = getRawValue(b)
		if err != nil {
			return nil, err
		}

		if err := json.Unmarshal(b, &r); err != nil {
			return nil, err
		}
	}

	return &r, nil
}
874257
func WriteTempFile(prefix string, data []byte, mode os.FileMode) (string, error) {
	path := TempPath("", prefix)
	if err := ioutil.WriteFile(path, data, mode); err != nil {
		return "", err
	}
	return path, nil
}
738247
func compileTemplate(ctx context.Context, out string) error {
	dirs := directoryInfo{
		Library: option.Config.BpfDir,
		Runtime: option.Config.StateDir,
		Output:  out,
		State:   out,
	}
	return compileDatapath(ctx, &dirs, option.Config.BPFCompilationDebug, log)
}
304447
func (g *gomplate) runTemplate(t *tplate) error {
	tmpl, err := t.toGoTemplate(g)
	if err != nil {
		return err
	}

	switch t.target.(type) {
	case io.Closer:
		if t.target != os.Stdout {
			// nolint: errcheck
			defer t.target.(io.Closer).Close()
		}
	}
	err = tmpl.Execute(t.target, g.context)
	return err
}
1253985
func Template(p Partial) string {
	
	qb422016 := qt422016.AcquireByteBuffer()
	
	WriteTemplate(qb422016, p)
	
	qs422016 := string(qb422016.B)
	
	qt422016.ReleaseByteBuffer(qb422016)
	
	return qs422016


}
537026
func ExecuteTemplate(tmpl ExecutableTemplate, data interface{}) string {
	var b bytes.Buffer
	if err := tmpl.Execute(&b, data); err != nil {
		utilLog.Error("ExecuteTemplate: Execute failed", "error", err)
	}
	return b.String()
}
770537
func Template() (c *TemplateController) {
	return &TemplateController{
		List:   templateList,
		New:    templateNew,
		Create: templateCreate,
		Edit:   templateEdit,
		Update: templateUpdate,
		Delete: templateDelete,
	}
}
761433
func (p *Plugin) writeAsTemplate(pr *Process) {
	tmp, err := p.processToTemplate(pr)
	if err != nil {
		p.Log.Errorf("cannot create a template from process: %v", err)
		return
	}
	if p.tReader == nil {
		p.Log.Warnf("process %s should write a new template, but reader (template path) is not defined",
			pr.name)
		return
	}
	if err = p.tReader.WriteTemplate(tmp, template.DefaultMode); err != nil {
		p.Log.Warnf("failed to write template %s: %v", tmp.Name, err)
		return
	}
}
726879
func StreamPageTemplate(qw422016 *qt422016.Writer, p Page) {
	//line templates/basepage.qtpl:12
	qw422016.N().S(`
<html>
	<head>
		<title>`)
	//line templates/basepage.qtpl:15
	p.StreamTitle(qw422016)
	//line templates/basepage.qtpl:15
	qw422016.N().S(`</title>
	</head>
	<body>
		<div>
			<a href="/">return to main page</a>
		</div>
		`)
	//line templates/basepage.qtpl:21
	p.StreamBody(qw422016)
	//line templates/basepage.qtpl:21
	qw422016.N().S(`
	</body>
</html>
`)
//line templates/basepage.qtpl:24
}