// associate installs the new template into the group of templates associated // with t. It is an error to reuse a name except to overwrite an empty // template. The two are already known to share the common structure. // The boolean return value reports wither to store this tree as t.Tree. func (t *Template) associate(new *Template, tree *parse.Tree) (bool, error) { if new.common != t.common { panic("internal error: associate not common") } name := new.name if old := t.tmpl[name]; old != nil { oldIsEmpty := parse.IsEmptyTree(old.Root) newIsEmpty := parse.IsEmptyTree(tree.Root) if newIsEmpty { // Whether old is empty or not, new is empty; no reason to replace old. return false, nil } if !oldIsEmpty { return false, fmt.Errorf("template: redefinition of template %q", name) } } t.tmpl[name] = new return true, nil }
// associate installs the new template into the group of templates associated // with t. The two are already known to share the common structure. // The boolean return value reports whether to store this tree as t.Tree. func (t *Template) associate(new *Template, tree *parse.Tree) (bool, error) { if new.common != t.common { panic("internal error: associate not common") } if t.tmpl[new.name] != nil && parse.IsEmptyTree(tree.Root) { // If a template by that name exists, // don't replace it with an empty template. return false, nil } t.tmpl[new.name] = new return true, nil }