forked from benbjohnson/ego
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathparse.go
More file actions
34 lines (31 loc) · 652 Bytes
/
parse.go
File metadata and controls
34 lines (31 loc) · 652 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package egon
import (
"io"
"os"
)
// Parse parses an Ego template from a reader.
// The path specifies the path name used in the compiled template's pragmas.
func Parse(r io.Reader, path string) (*Template, error) {
s := NewScanner(r, path)
t := &Template{Path: path}
for {
b, err := s.Scan()
if err == io.EOF {
break
} else if err != nil {
return nil, err
}
t.Blocks = append(t.Blocks, b)
}
t.normalize()
return t, nil
}
// ParseFile parses an Ego template from a file.
func ParseFile(path string) (*Template, error) {
f, err := os.Open(path)
if err != nil {
return nil, err
}
defer f.Close()
return Parse(f, path)
}