-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate.go
More file actions
53 lines (43 loc) · 804 Bytes
/
template.go
File metadata and controls
53 lines (43 loc) · 804 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package got
import (
"regexp"
"strings"
)
var commentRe = regexp.MustCompile(`^\s*<!--(.*?)-->`)
type Template interface {
Theme() string
Path() string
Name() string
Content() string
}
type tmpl struct {
theme string
path string
name string
content string
}
func newTemplate(theme, name, content string) *tmpl {
p := name
if comment := commentRe.FindStringSubmatch(content); len(comment) > 0 {
content = commentRe.ReplaceAllString(content, "")
p = strings.TrimSpace(comment[1])
}
return &tmpl{
theme: theme,
name: name,
path: p,
content: content,
}
}
func (t *tmpl) Theme() string {
return t.theme
}
func (t *tmpl) Path() string {
return t.path
}
func (t *tmpl) Name() string {
return t.name
}
func (t *tmpl) Content() string {
return t.content
}