Home | History | Annotate | Download | only in template

Lines Matching full: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
42 func (t *Template) Templates() []*Template {
47 m := make([]*Template, 0, len(ns.set))
54 // Option sets options for the template. Options are described by
72 func (t *Template) Option(opt ...string) *Template {
78 func (t *Template) escape() error {
83 return fmt.Errorf("template: %q is an incomplete or empty template%s", t.Name(), t.text.DefinedTemplates())
94 // Execute applies a parsed template to the specified data object,
96 // If an error occurs executing the template or writing its output,
99 // A template may be executed safely in parallel.
100 func (t *Template) Execute(wr io.Writer, data interface{}) error {
107 // ExecuteTemplate applies the template associated with t that has the given
109 // If an error occurs executing the template or writing its output,
112 // A template may be executed safely in parallel.
113 func (t *Template) ExecuteTemplate(wr io.Writer, name string, data interface{}) error {
121 // lookupAndEscapeTemplate guarantees that the template with the given name
123 // template.
124 func (t *Template) lookupAndEscapeTemplate(name string) (tmpl *Template, err error) {
129 return nil, fmt.Errorf("html/template: %q is undefined", name)
135 return nil, fmt.Errorf("html/template: %q is an incomplete template", name)
138 panic("html/template internal error: template escaping out of sync")
146 // Parse parses a string into a template. Nested template definitions
147 // will be associated with the top-level template t. Parse may be
149 // with t. It is an error if a resulting template is non-empty (contains
150 // content other than template definitions) and would replace a
151 // non-empty template with the same name. (In multiple calls to Parse
152 // with the same receiver template, only one call can contain text
153 // other than space, comments, and template definitions.)
154 func (t *Template) Parse(src string) (*Template, error) {
164 // The template.Template set has been updated; update ours.
173 // Restore our record of this text/template to its unescaped original state.
181 // AddParseTree creates a new template with the name and parse tree
185 func (t *Template) AddParseTree(name string, tree *parse.Tree) (*Template, error) {
189 return nil, fmt.Errorf("html/template: cannot AddParseTree to %q after it has executed", t.Name())
195 ret := &Template{
205 // Clone returns a duplicate of the template, including all associated
213 func (t *Template) Clone() (*Template, error) {
217 return nil, fmt.Errorf("html/template: cannot Clone %q after it has executed", t.Name())
223 ret := &Template{
228 set: make(map[string]*Template),
235 return nil, fmt.Errorf("html/template: cannot Clone %q after it has executed", t.Name())
238 ret.set[name] = &Template{
248 // New allocates a new HTML template with the given name.
249 func New(name string) *Template {
250 tmpl := &Template{
252 template.New(name),
255 set: make(map[string]*Template),
262 // New allocates a new HTML template associated with the given one
264 // allows one template to invoke another with a {{template}} action.
265 func (t *Template) New(name string) *Template {
272 func (t *Template) new(name string) *Template {
273 tmpl := &Template{
283 // Name returns the name of the template.
284 func (t *Template) Name() string {
293 // as FuncMap in "text/template", copied here so clients need not import
294 // "text/template".
297 // Funcs adds the elements of the argument map to the template's function map.
300 // value is the template, so calls can be chained.
301 func (t *Template) Funcs(funcMap FuncMap) *Template {
302 t.text.Funcs(template.FuncMap(funcMap))
307 // subsequent calls to Parse, ParseFiles, or ParseGlob. Nested template
310 // The return value is the template, so calls can be chained.
311 func (t *Template) Delims(left, right string) *Template {
316 // Lookup returns the template with the given name that is associated with t,
317 // or nil if there is no such template.
318 func (t *Template) Lookup(name string) *Template {
324 // Must is a helper that wraps a call to a function returning (*Template, error)
327 // var t = template.Must(template.New("name").Parse("html"))
328 func Must(t *Template, err error) *Template {
335 // ParseFiles creates a new Template and parses the template definitions from
336 // the named files. The returned template's name will have the (base) name and
338 // If an error occurs, parsing stops and the returned *Template is nil.
339 func ParseFiles(filenames ...string) (*Template, error) {
344 // t. If an error occurs, parsing stops and the returned template is nil;
346 func (t *Template) ParseFiles(filenames ...string) (*Template, error) {
351 // template is nil, it is created from the first file.
352 func parseFiles(t *Template, filenames ...string) (*Template, error) {
355 return nil, fmt.Errorf("html/template: no files named in call to ParseFiles")
364 // First template becomes return value if not already defined,
369 // works. Otherwise we create a new template associated with t.
370 var tmpl *Template
387 // ParseGlob creates a new Template and parses the template definitions from the
389 // returned template will have the (base) name and (parsed) contents of the
392 func ParseGlob(pattern string) (*Template, error) {
396 // ParseGlob parses the template definitions in the files identified by the
401 func (t *Template) ParseGlob(pattern string) (*Template, error) {
406 func parseGlob(t *Template, pattern string) (*Template, error) {
412 return nil, fmt.Errorf("html/template: pattern matches no files: %#q", pattern)