...
1 package config
2
3 type Inheritable interface {
4 Inherit() Inheritable
5 }
6
7
8 type Config struct {
9 Debug bool
10
11 BlockStartString string
12
13 BlockEndString string
14
15 VariableStartString string
16
17 VariableEndString string
18
19 CommentStartString string
20
21 CommentEndString string
22
23
24 LineStatementPrefix string
25
26
27 LineCommentPrefix string
28
29
30 TrimBlocks bool
31
32
33 LstripBlocks bool
34
35
36
37 NewlineSequence string
38
39
40
41 KeepTrailingNewline bool
42
43
44
45
46 Autoescape bool
47
48
49 Ext map[string]Inheritable
50 }
51
52 func NewConfig() *Config {
53 return &Config{
54 Debug: false,
55 BlockStartString: "{%",
56 BlockEndString: "%}",
57 VariableStartString: "{{",
58 VariableEndString: "}}",
59 CommentStartString: "{#",
60 CommentEndString: "#}",
61 TrimBlocks: false,
62 LstripBlocks: false,
63 NewlineSequence: "\n",
64 KeepTrailingNewline: false,
65 Autoescape: false,
66 Ext: map[string]Inheritable{},
67 }
68 }
69
70 func (cfg *Config) Inherit() *Config {
71 ext := map[string]Inheritable{}
72 for key, cfg := range cfg.Ext {
73 ext[key] = cfg.Inherit()
74 }
75 return &Config{
76 Debug: cfg.Debug,
77 BlockStartString: cfg.BlockStartString,
78 BlockEndString: cfg.BlockEndString,
79 VariableStartString: cfg.VariableStartString,
80 VariableEndString: cfg.VariableEndString,
81 CommentStartString: cfg.CommentStartString,
82 CommentEndString: cfg.CommentEndString,
83 TrimBlocks: cfg.TrimBlocks,
84 LstripBlocks: cfg.LstripBlocks,
85 NewlineSequence: cfg.NewlineSequence,
86 KeepTrailingNewline: cfg.KeepTrailingNewline,
87 Autoescape: cfg.Autoescape,
88 Ext: ext,
89 }
90 }
91
92
93 var DefaultConfig = NewConfig()
94
View as plain text