1
package config
2

3
type Inheritable interface {
4
	Inherit() Inheritable
5
}
6

7
// Config holds plexer and parser parameters
8
type Config struct {
9
	Debug bool
10
	// The string marking the beginning of a block. Defaults to '{%'
11
	BlockStartString string
12
	// The string marking the end of a block. Defaults to '%}'.
13
	BlockEndString string
14
	// The string marking the beginning of a print statement. Defaults to '{{'.
15
	VariableStartString string
16
	// The string marking the end of a print statement. Defaults to '}}'.
17
	VariableEndString string
18
	// The string marking the beginning of a comment. Defaults to '{#'.
19
	CommentStartString string
20
	// The string marking the end of a comment. Defaults to '#}'.
21
	CommentEndString string
22
	// If given and a string, this will be used as prefix for line based statements.
23
	// See also Line Statements.
24
	LineStatementPrefix string
25
	// If given and a string, this will be used as prefix for line based comments.
26
	// See also Line Statements.
27
	LineCommentPrefix string
28
	// If this is set to True the first newline after a block is removed (block, not variable tag!).
29
	// Defaults to False.
30
	TrimBlocks bool
31
	// If this is set to True leading spaces and tabs are stripped from the start of a line to a block.
32
	// Defaults to False.
33
	LstripBlocks bool
34
	// The sequence that starts a newline.
35
	// Must be one of '\r', '\n' or '\r\n'.
36
	// The default is '\n' which is a useful default for Linux and OS X systems as well as web applications.
37
	NewlineSequence string
38
	// Preserve the trailing newline when rendering templates.
39
	// The default is False, which causes a single newline,
40
	// if present, to be stripped from the end of the template.
41
	KeepTrailingNewline bool
42
	// If set to True the XML/HTML autoescaping feature is enabled by default.
43
	// For more details about autoescaping see Markup.
44
	// This can also be a callable that is passed the template name
45
	// and has to return True or False depending on autoescape should be enabled by default.
46
	Autoescape bool
47

48
	// Allow extensions to store some config
49
	Ext map[string]Inheritable
50
}
51

52 4
func NewConfig() *Config {
53 4
	return &Config{
54 4
		Debug:               false,
55 4
		BlockStartString:    "{%",
56 4
		BlockEndString:      "%}",
57 4
		VariableStartString: "{{",
58 4
		VariableEndString:   "}}",
59 4
		CommentStartString:  "{#",
60 4
		CommentEndString:    "#}",
61 4
		TrimBlocks:          false,
62 4
		LstripBlocks:        false,
63 4
		NewlineSequence:     "\n",
64 4
		KeepTrailingNewline: false,
65 4
		Autoescape:          false,
66 4
		Ext:                 map[string]Inheritable{},
67 1
	}
68
}
69

70 4
func (cfg *Config) Inherit() *Config {
71 4
	ext := map[string]Inheritable{}
72 4
	for key, cfg := range cfg.Ext {
73 0
		ext[key] = cfg.Inherit()
74 0
	}
75 4
	return &Config{
76 4
		Debug:               cfg.Debug,
77 4
		BlockStartString:    cfg.BlockStartString,
78 4
		BlockEndString:      cfg.BlockEndString,
79 4
		VariableStartString: cfg.VariableStartString,
80 4
		VariableEndString:   cfg.VariableEndString,
81 4
		CommentStartString:  cfg.CommentStartString,
82 4
		CommentEndString:    cfg.CommentEndString,
83 4
		TrimBlocks:          cfg.TrimBlocks,
84 4
		LstripBlocks:        cfg.LstripBlocks,
85 4
		NewlineSequence:     cfg.NewlineSequence,
86 4
		KeepTrailingNewline: cfg.KeepTrailingNewline,
87 4
		Autoescape:          cfg.Autoescape,
88 4
		Ext:                 ext,
89 1
	}
90
}
91

92
// DefaultConfig is a configuration with default values
93
var DefaultConfig = NewConfig()

Read our documentation on viewing source code .

Loading