Environment constructor
Environment({
- String commentStart = '{#',
- String commentEnd = '#}',
- String variableStart = '{{',
- String variableEnd = '}}',
- String blockStart = '{%',
- String blockEnd = '%}',
- String? lineCommentPrefix,
- String? lineStatementPrefix,
- bool leftStripBlocks = false,
- bool trimBlocks = false,
- String newLine = '\n',
- bool keepTrailingNewLine = false,
- bool optimize = true,
- Function finalize = defaults.finalize,
- Loader? loader,
- bool autoReload = true,
- Map<
String, Object?> ? globals, - Map<
String, Function> ? filters, - Map<
String, Function> ? tests, - List<
Node Function(Node)> ? modifiers, - Map<
String, Template> ? templates, - Random? random,
- AttributeGetter? getAttribute,
- ItemGetter getItem = defaults.getItem,
The core component of Jinja 2 is the Environment.
Implementation
Environment({
this.commentStart = '{#',
this.commentEnd = '#}',
this.variableStart = '{{',
this.variableEnd = '}}',
this.blockStart = '{%',
this.blockEnd = '%}',
this.lineCommentPrefix,
this.lineStatementPrefix,
this.leftStripBlocks = false,
this.trimBlocks = false,
this.newLine = '\n',
this.keepTrailingNewLine = false,
this.optimize = true,
Function finalize = defaults.finalize,
this.loader,
this.autoReload = true,
Map<String, Object?>? globals,
Map<String, Function>? filters,
Map<String, Function>? tests,
List<Node Function(Node)>? modifiers,
Map<String, Template>? templates,
Random? random,
AttributeGetter? getAttribute,
this.getItem = defaults.getItem,
}) : finalize = wrapFinalizer(finalize),
globals = HashMap<String, Object?>.of(defaults.globals),
filters = HashMap<String, Function>.of(defaults.filters),
tests = HashMap<String, Function>.of(defaults.tests),
modifiers = <Node Function(Node)>[],
templates = HashMap<String, Template>(),
random = random ?? Random(),
getAttribute = wrapGetAttribute(getAttribute, getItem) {
if (newLine != '\r' && newLine != '\n' && newLine != '\r\n') {
// TODO(environment): add error message
throw ArgumentError.value(newLine, 'newLine');
}
if (globals != null) {
this.globals.addAll(globals);
}
if (filters != null) {
this.filters.addAll(filters);
}
if (tests != null) {
this.tests.addAll(tests);
}
if (modifiers != null) {
this.modifiers.addAll(modifiers);
}
if (templates != null) {
this.templates.addAll(templates);
}
}