Environment constructor

Environment({
  1. String commentStart = '{#',
  2. String commentEnd = '#}',
  3. String variableStart = '{{',
  4. String variableEnd = '}}',
  5. String blockStart = '{%',
  6. String blockEnd = '%}',
  7. String? lineCommentPrefix,
  8. String? lineStatementPrefix,
  9. bool leftStripBlocks = false,
  10. bool trimBlocks = false,
  11. String newLine = '\n',
  12. bool keepTrailingNewLine = false,
  13. bool optimize = true,
  14. Function finalize = defaults.finalize,
  15. Loader? loader,
  16. bool autoReload = true,
  17. Map<String, Object?>? globals,
  18. Map<String, Function>? filters,
  19. Map<String, Function>? tests,
  20. List<Node Function(Node)>? modifiers,
  21. Map<String, Template>? templates,
  22. Random? random,
  23. AttributeGetter? getAttribute,
  24. 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);
  }
}