Home | History | Annotate | Download | only in template

Lines Matching defs:Template

5 package template
13 "text/template"
14 "text/template/parse"
17 // Template is a specialized Template from "text/template" that produces a safe
19 type Template struct {
22 // We could embed the text/template field, but it's safer not to because
24 // template's in sync.
25 text *template.Template
26 // The underlying template's parse tree, updated to be HTML-safe.
32 var escapeOK = fmt.Errorf("template escaped correctly")
37 set map[string]*Template
43 func (t *Template) Templates() []*Template {
48 m := make([]*Template, 0, len(ns.set))
55 // Option sets options for the template. Options are described by
73 func (t *Template) Option(opt ...string) *Template {
80 func (t *Template) checkCanParse() error {
87 return fmt.Errorf("html/template: cannot Parse after Execute")
93 func (t *Template) escape() error {
99 return fmt.Errorf("template: %q is an incomplete or empty template", t.Name())
110 // Execute applies a parsed template to the specified data object,
112 // If an error occurs executing the template or writing its output,
115 // A template may be executed safely in parallel.
116 func (t *Template) Execute(wr io.Writer, data interface{}) error {
123 // ExecuteTemplate applies the template associated with t that has the given
125 // If an error occurs executing the template or writing its output,
128 // A template may be executed safely in parallel.
129 func (t *Template) ExecuteTemplate(wr io.Writer, name string, data interface{}) error {
137 // lookupAndEscapeTemplate guarantees that the template with the given name
139 // template.
140 func (t *Template) lookupAndEscapeTemplate(name string) (tmpl *Template, err error) {
146 return nil, fmt.Errorf("html/template: %q is undefined", name)
152 return nil, fmt.Errorf("html/template: %q is an incomplete template", name)
155 panic("html/template internal error: template escaping out of sync")
166 func (t *Template) DefinedTemplates() string {
170 // Parse parses text as a template body for t.
171 // Named template definitions ({{define ...}} or {{block ...}} statements) in text
176 // before the first use of Execute on t or any associated template.
177 // A template definition with a body containing only white space and comments
178 // is considered empty and will not replace an existing template's body.
179 // This allows using Parse to add new named template definitions without
180 // overwriting the main template body.
181 func (t *Template) Parse(text string) (*Template, error) {
193 // The template.Template set has been updated; update ours.
208 // AddParseTree creates a new template with the name and parse tree
211 // It returns an error if t or any associated template has already been executed.
212 func (t *Template) AddParseTree(name string, tree *parse.Tree) (*Template, error) {
223 ret := &Template{
233 // Clone returns a duplicate of the template, including all associated
241 func (t *Template) Clone() (*Template, error) {
245 return nil, fmt.Errorf("html/template: cannot Clone %q after it has executed", t.Name())
251 ret := &Template{
256 set: make(map[string]*Template),
264 return nil, fmt.Errorf("html/template: cannot Clone %q after it has executed", t.Name())
267 ret.set[name] = &Template{
274 // Return the template associated with the name of this template.
278 // New allocates a new HTML template with the given name.
279 func New(name string) *Template {
280 tmpl := &Template{
282 template.New(name),
285 set: make(map[string]*Template),
292 // New allocates a new HTML template associated with the given one
294 // allows one template to invoke another with a {{template}} action.
295 func (t *Template) New(name string) *Template {
302 func (t *Template) new(name string) *Template {
303 tmpl := &Template{
313 // Name returns the name of the template.
314 func (t *Template) Name() string {
323 // as FuncMap in "text/template", copied here so clients need not import
324 // "text/template".
327 // Funcs adds the elements of the argument map to the template's function map.
330 // value is the template, so calls can be chained.
331 func (t *Template) Funcs(funcMap FuncMap) *Template {
332 t.text.Funcs(template.FuncMap(funcMap))
337 // subsequent calls to Parse, ParseFiles, or ParseGlob. Nested template
340 // The return value is the template, so calls can be chained.
341 func (t *Template) Delims(left, right string) *Template {
346 // Lookup returns the template with the given name that is associated with t,
347 // or nil if there is no such template.
348 func (t *Template) Lookup(name string) *Template {
354 // Must is a helper that wraps a call to a function returning (*Template, error)
357 // var t = template.Must(template.New("name").Parse("html"))
358 func Must(t *Template, err error) *Template {
365 // ParseFiles creates a new Template and parses the template definitions from
366 // the named files. The returned template's name will have the (base) name and
368 // If an error occurs, parsing stops and the returned *Template is nil.
372 // For instance, ParseFiles("a/foo", "b/foo") stores "b/foo" as the template
374 func ParseFiles(filenames ...string) (*Template, error) {
379 // t. If an error occurs, parsing stops and the returned template is nil;
385 // ParseFiles returns an error if t or any associated template has already been executed.
386 func (t *Template) ParseFiles(filenames ...string) (*Template, error) {
391 // template is nil, it is created from the first file.
392 func parseFiles(t *Template, filenames ...string) (*Template, error) {
399 return nil, fmt.Errorf("html/template: no files named in call to ParseFiles")
408 // First template becomes return value if not already defined,
413 // works. Otherwise we create a new template associated with t.
414 var tmpl *Template
431 // ParseGlob creates a new Template and parses the template definitions from the
433 // returned template will have the (base) name and (parsed) contents of the
439 func ParseGlob(pattern string) (*Template, error) {
443 // ParseGlob parses the template definitions in the files identified by the
452 // ParseGlob returns an error if t or any associated template has already been executed.
453 func (t *Template) ParseGlob(pattern string) (*Template, error) {
458 func parseGlob(t *Template, pattern string) (*Template, error) {
467 return nil, fmt.Errorf("html/template: pattern matches no files: %#q", pattern)
476 return template.IsTrue(val)