"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "tpl/internal/go_templates/texttemplate/template.go" between
hugo-0.80.0.tar.gz and hugo-0.81.0.tar.gz

About: Hugo is a static site generator that takes a source directory of Markdown files and templates and uses these as input to create a complete website (written in Go).

template.go  (hugo-0.80.0):template.go  (hugo-0.81.0)
// Copyright 2011 The Go Authors. All rights reserved. // Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package template package template
import ( import (
"github.com/gohugoio/hugo/tpl/internal/go_templates/texttemplate/parse"
"reflect" "reflect"
"sync" "sync"
"github.com/gohugoio/hugo/tpl/internal/go_templates/texttemplate/parse"
) )
// common holds the information shared by related templates. // common holds the information shared by related templates.
type common struct { type common struct {
muTmpl sync.RWMutex // protects tmpl (temporary Hugo-fix)
tmpl map[string]*Template // Map from name to defined templates. tmpl map[string]*Template // Map from name to defined templates.
option option option option
// We use two maps, one for parsing and one for execution. // We use two maps, one for parsing and one for execution.
// This separation makes the API cleaner since it doesn't // This separation makes the API cleaner since it doesn't
// expose reflection to the client. // expose reflection to the client.
muFuncs sync.RWMutex // protects parseFuncs and execFuncs muFuncs sync.RWMutex // protects parseFuncs and execFuncs
parseFuncs FuncMap parseFuncs FuncMap
execFuncs map[string]reflect.Value execFuncs map[string]reflect.Value
} }
skipping to change at line 91 skipping to change at line 93
// associated templates is, so further calls to Parse in the copy will add // associated templates is, so further calls to Parse in the copy will add
// templates to the copy but not to the original. Clone can be used to prepare // templates to the copy but not to the original. Clone can be used to prepare
// common templates and use them with variant definitions for other templates // common templates and use them with variant definitions for other templates
// by adding the variants after the clone is made. // by adding the variants after the clone is made.
func (t *Template) Clone() (*Template, error) { func (t *Template) Clone() (*Template, error) {
nt := t.copy(nil) nt := t.copy(nil)
nt.init() nt.init()
if t.common == nil { if t.common == nil {
return nt, nil return nt, nil
} }
// temporary Hugo-fix
t.muTmpl.RLock()
defer t.muTmpl.RUnlock()
for k, v := range t.tmpl { for k, v := range t.tmpl {
if k == t.name { if k == t.name {
nt.tmpl[t.name] = nt nt.tmpl[t.name] = nt
continue continue
} }
// The associated templates share nt's common structure. // The associated templates share nt's common structure.
tmpl := v.copy(nt.common) tmpl := v.copy(nt.common)
nt.tmpl[k] = tmpl nt.tmpl[k] = tmpl
} }
t.muFuncs.RLock() t.muFuncs.RLock()
skipping to change at line 127 skipping to change at line 132
leftDelim: t.leftDelim, leftDelim: t.leftDelim,
rightDelim: t.rightDelim, rightDelim: t.rightDelim,
} }
} }
// AddParseTree associates the argument parse tree with the template t, giving // AddParseTree associates the argument parse tree with the template t, giving
// it the specified name. If the template has not been defined, this tree become s // it the specified name. If the template has not been defined, this tree become s
// its definition. If it has been defined and already has that name, the existin g // its definition. If it has been defined and already has that name, the existin g
// definition is replaced; otherwise a new template is created, defined, and ret urned. // definition is replaced; otherwise a new template is created, defined, and ret urned.
func (t *Template) AddParseTree(name string, tree *parse.Tree) (*Template, error ) { func (t *Template) AddParseTree(name string, tree *parse.Tree) (*Template, error ) {
// temporary Hugo-fix
t.muTmpl.Lock()
defer t.muTmpl.Unlock()
t.init() t.init()
nt := t nt := t
if name != t.name { if name != t.name {
nt = t.New(name) nt = t.New(name)
} }
// Even if nt == t, we need to install it in the common.tmpl map. // Even if nt == t, we need to install it in the common.tmpl map.
if t.associate(nt, tree) || nt.Tree == nil { if t.associate(nt, tree) || nt.Tree == nil {
nt.Tree = tree nt.Tree = tree
} }
return nt, nil return nt, nil
} }
// Templates returns a slice of defined templates associated with t. // Templates returns a slice of defined templates associated with t.
func (t *Template) Templates() []*Template { func (t *Template) Templates() []*Template {
if t.common == nil { if t.common == nil {
return nil return nil
} }
// Return a slice so we don't expose the map. // Return a slice so we don't expose the map.
// temporary Hugo-fix
t.muTmpl.RLock()
defer t.muTmpl.RUnlock()
m := make([]*Template, 0, len(t.tmpl)) m := make([]*Template, 0, len(t.tmpl))
for _, v := range t.tmpl { for _, v := range t.tmpl {
m = append(m, v) m = append(m, v)
} }
return m return m
} }
// Delims sets the action delimiters to the specified strings, to be used in // Delims sets the action delimiters to the specified strings, to be used in
// subsequent calls to Parse, ParseFiles, or ParseGlob. Nested template // subsequent calls to Parse, ParseFiles, or ParseGlob. Nested template
// definitions will inherit the settings. An empty delimiter stands for the // definitions will inherit the settings. An empty delimiter stands for the
skipping to change at line 185 skipping to change at line 196
addFuncs(t.parseFuncs, funcMap) addFuncs(t.parseFuncs, funcMap)
return t return t
} }
// Lookup returns the template with the given name that is associated with t. // Lookup returns the template with the given name that is associated with t.
// It returns nil if there is no such template or the template has no definition . // It returns nil if there is no such template or the template has no definition .
func (t *Template) Lookup(name string) *Template { func (t *Template) Lookup(name string) *Template {
if t.common == nil { if t.common == nil {
return nil return nil
} }
// temporary Hugo-fix
t.muTmpl.RLock()
defer t.muTmpl.RUnlock()
return t.tmpl[name] return t.tmpl[name]
} }
// Parse parses text as a template body for t. // Parse parses text as a template body for t.
// Named template definitions ({{define ...}} or {{block ...}} statements) in te xt // Named template definitions ({{define ...}} or {{block ...}} statements) in te xt
// define additional templates associated with t and are removed from the // define additional templates associated with t and are removed from the
// definition of t itself. // definition of t itself.
// //
// Templates can be redefined in successive calls to Parse. // Templates can be redefined in successive calls to Parse.
// A template definition with a body containing only white space and comments // A template definition with a body containing only white space and comments
 End of changes. 7 change blocks. 
1 lines changed or deleted 15 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)