Compare commits
2 commits
Author | SHA1 | Date | |
---|---|---|---|
7c8ffa33c0 | |||
7e7f721002 |
2 changed files with 18 additions and 1 deletions
10
Makefile
Normal file
10
Makefile
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
all: fmt vet test
|
||||||
|
|
||||||
|
fmt:
|
||||||
|
go fmt ./...
|
||||||
|
|
||||||
|
vet:
|
||||||
|
go vet ./...
|
||||||
|
|
||||||
|
test:
|
||||||
|
go test -vet=off ./...
|
|
@ -23,6 +23,7 @@ type Collection struct {
|
||||||
type Options struct {
|
type Options struct {
|
||||||
// Files from shared collections will be available in every main template.
|
// Files from shared collections will be available in every main template.
|
||||||
SharedCollections []Collection
|
SharedCollections []Collection
|
||||||
|
FuncMap template.FuncMap
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load templates from specified directories with default options.
|
// Load templates from specified directories with default options.
|
||||||
|
@ -38,6 +39,7 @@ func LoadWithOptions(
|
||||||
options Options,
|
options Options,
|
||||||
) (map[string]*template.Template, error) {
|
) (map[string]*template.Template, error) {
|
||||||
sharedTemplate := template.New("")
|
sharedTemplate := template.New("")
|
||||||
|
|
||||||
for _, stp := range options.SharedCollections {
|
for _, stp := range options.SharedCollections {
|
||||||
files, err := getFiles(stp.RootDir, stp.Prefix)
|
files, err := getFiles(stp.RootDir, stp.Prefix)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -45,7 +47,12 @@ func LoadWithOptions(
|
||||||
}
|
}
|
||||||
|
|
||||||
for name, contents := range files {
|
for name, contents := range files {
|
||||||
sharedTemplate, err = sharedTemplate.New(name).Parse(contents)
|
sharedTemplate = sharedTemplate.New(name)
|
||||||
|
if options.FuncMap != nil {
|
||||||
|
sharedTemplate = sharedTemplate.Funcs(options.FuncMap)
|
||||||
|
}
|
||||||
|
|
||||||
|
sharedTemplate, err = sharedTemplate.Parse(contents)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue