...

Source file src/github.com/noirbizarre/gonja/config/config.go

Documentation: github.com/noirbizarre/gonja/config

     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  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  // DefaultConfig is a configuration with default values
    93  var DefaultConfig = NewConfig()
    94  

View as plain text