-
Notifications
You must be signed in to change notification settings - Fork 0
/
ace.go
50 lines (38 loc) · 1.09 KB
/
ace.go
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import (
"html/template"
"path/filepath"
"strings"
"github.com/yosssi/ace"
)
// AceProcessor - provides ace library support.
type AceProcessor struct {
BaseDir string
}
func (p AceProcessor) compile(tpl *TemplateWriter) error {
funcMap := template.FuncMap{}
var siteName = filepathToSitename(tpl.src)
funcMap = template.FuncMap{
"current_template": func() string { return tpl.src },
// "copy": func(rel string) string { return siteName },
"copy": func(rel string) string { return helperCopyFile(rel, siteName) },
}
_, filename := filepath.Split(trimExt(tpl.src))
t, err := ace.Load(filename, "", &ace.Options{
FuncMap: funcMap,
DynamicReload: true,
BaseDir: p.BaseDir})
if err != nil {
return err
}
err = t.Execute(tpl.writer, nil)
return err
}
func (p AceProcessor) dstfile(filename string) string {
return aceOutputFilePath(filename)
}
func aceOutputFilePath(from string) string {
toMake := strings.Replace(from, "sites", "public", 1)
toMake = strings.Replace(toMake, "ace", "html", 1)
return strings.Replace(toMake, "pages/", "", 1)
}