mirror of
https://github.com/golang/go
synced 2024-11-25 05:47:57 -07:00
exp/template: make Set.ParseFile etc resolve functions in the Set
Fixes #2114 R=r CC=golang-dev https://golang.org/cl/4823056
This commit is contained in:
parent
db9229def8
commit
ca68b2810d
@ -35,6 +35,17 @@ func (t *Template) ParseFile(filename string) os.Error {
|
|||||||
return t.Parse(string(b))
|
return t.Parse(string(b))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ParseFileInSet is the same as ParseFile except that function bindings
|
||||||
|
// are checked against those in the set and the template is added
|
||||||
|
// to the set.
|
||||||
|
func (t *Template) ParseFileInSet(filename string, set *Set) os.Error {
|
||||||
|
b, err := ioutil.ReadFile(filename)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return t.ParseInSet(string(b), set)
|
||||||
|
}
|
||||||
|
|
||||||
// MustParseFile reads the template definition from a file and parses it to
|
// MustParseFile reads the template definition from a file and parses it to
|
||||||
// construct an internal representation of the template for execution.
|
// construct an internal representation of the template for execution.
|
||||||
// It panics if the file cannot be read or the template cannot be parsed.
|
// It panics if the file cannot be read or the template cannot be parsed.
|
||||||
@ -52,6 +63,15 @@ func ParseFile(filename string) (*Template, os.Error) {
|
|||||||
return t, t.ParseFile(filename)
|
return t, t.ParseFile(filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ParseFileInSet creates a new Template and parses the template
|
||||||
|
// definition from the named file. The template name is the base name
|
||||||
|
// of the file. It also adds the template to the set. Function bindings are
|
||||||
|
//checked against those in the set.
|
||||||
|
func ParseFileInSet(filename string, set *Set) (*Template, os.Error) {
|
||||||
|
t := New(filepath.Base(filename))
|
||||||
|
return t, t.ParseFileInSet(filename, set)
|
||||||
|
}
|
||||||
|
|
||||||
// MustParseFile creates a new Template and parses the template definition
|
// MustParseFile creates a new Template and parses the template definition
|
||||||
// from the named file. The template name is the base name of the file.
|
// from the named file. The template name is the base name of the file.
|
||||||
// It panics if the file cannot be read or the template cannot be parsed.
|
// It panics if the file cannot be read or the template cannot be parsed.
|
||||||
@ -179,13 +199,10 @@ func MustParseSetFiles(pattern string) *Set {
|
|||||||
// encountered.
|
// encountered.
|
||||||
func (s *Set) ParseTemplateFile(filenames ...string) os.Error {
|
func (s *Set) ParseTemplateFile(filenames ...string) os.Error {
|
||||||
for _, filename := range filenames {
|
for _, filename := range filenames {
|
||||||
t, err := ParseFile(filename)
|
_, err := ParseFileInSet(filename, s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := s.add(t); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -216,13 +233,10 @@ func (s *Set) ParseTemplateFiles(pattern string) os.Error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, filename := range filenames {
|
for _, filename := range filenames {
|
||||||
t, err := ParseFile(filename)
|
_, err := ParseFileInSet(filename, s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := s.add(t); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user