-
Notifications
You must be signed in to change notification settings - Fork 13
/
haml.go
41 lines (34 loc) · 1.34 KB
/
haml.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
// The gohaml package contains a HAML parser similar to the one found at http://www.haml-lang.com.
//
//You can find the specifics about this implementation at http://github.com/realistschuckle/gohaml.
package gohaml
/*
Engine provides the template interpretation functionality to convert a HAML template into its
corresponding tag-based representation.
Available options are:
engine.Options["autoclose"] = true|false, default true
The Options field contains the values to modify the way that the engine produces the markup.
The Indentation field contains the string used by the engine to perform indentation.
The IncludeCallback field contains the callback invoked by the gohaml engine to process other files
included through the %include extension.
*/
type Engine struct {
Autoclose bool
Indentation string
IncludeCallback func(string, map[string]interface{}) string
ast *tree
}
// NewEngine returns a new Engine with the given input.
func NewEngine(input string) (engine *Engine, err error) {
var output *tree
output, err = parser.parse(input)
if err == nil {
engine = &Engine{true, "\t", nil, output}
}
return
}
// Render interprets the HAML supplied to the NewEngine method.
func (self *Engine) Render(scope map[string]interface{}) (output string) {
output = self.ast.resolve(scope, self.Indentation, self.Autoclose)
return
}