Skip to content

Commit

Permalink
Sync 0.6.0-dev.16
Browse files Browse the repository at this point in the history
  • Loading branch information
ykmnkmi committed Mar 11, 2024
1 parent be035c5 commit 686d9dd
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 46 deletions.
1 change: 0 additions & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ jobs:
run: dart analyze --fatal-infos --fatal-warnings .

- name: Run WEB Tests
if: matrix.sdk != '3.0.0'
run: |
dart test --platform chrome
Expand Down
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## 0.6.0-dev.15
## unreleased ([diff](https://github.com/ykmnkmi/jinja.dart/compare/c12244e6..be035c5f))
- bump SDK version to 3.3.0.
- update dependencies.
- internal changes.
Expand All @@ -7,6 +7,11 @@
- statements:
- `import`
- `from`
- `Template`:
- `globals` field
- restored:
- conditional and variable `extends` statement variants
- choice, ignore missing and variable `include` statement variants
- changed:
- `Environment`:
- `Environment.lex()` return from `List<Token>` to `Iterable<Token>`
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,13 @@ See also examples with [conduit][conduit_example] and
- `Template` class:
- `generate` method
- `stream` method
- Relative template Paths
- Async Support
- Expressions
- Dart Methods and Properties
- `!`/`?.`
- `!.`/`?.`
- Loaders
- PackageLoader (VM, sync?) 🤔
- PackageLoader (VM)
- ...
- List of Global Functions
- `lipsum`
Expand Down
79 changes: 43 additions & 36 deletions lib/src/environment.dart
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,11 @@ base class Environment {

/// Get an attribute of an object.
///
/// If `getAttribute` is not passed to the [Environment], the item is
/// returned.
/// If `getAttribute` is not passed to the [Environment], [getItem] is used
/// instead.
final AttributeGetter getAttribute;

/// Get an item of an object.
/// Get an item from an object.
final ItemGetter getItem;

@override
Expand All @@ -242,7 +242,7 @@ base class Environment {
);
}

/// The lexer for this environment.
/// The [Lexer] for this environment.
Lexer get lexer {
return Lexer.cached(this);
}
Expand Down Expand Up @@ -359,8 +359,12 @@ base class Environment {
body = body.accept(const Optimizer(), Context(this));
}

body = body.accept(RuntimeCompiler(), null);
return Template.fromNode(this, path: path, globals: globals, body: body);
return Template.fromNode(
this,
path: path,
globals: globals,
body: body.accept(RuntimeCompiler(), null),
);
}

/// Load a template by name with `loader` and return a [Template].
Expand Down Expand Up @@ -399,7 +403,7 @@ base class Environment {
try {
return getTemplate(template);
} on TemplateNotFound {
// pass
// ignore
}
}
}
Expand All @@ -409,8 +413,7 @@ base class Environment {

/// Returns a list of templates for this environment.
///
/// This requires that the loader supports the loader's
/// [Loader.listTemplates] method.
/// If the [loader] is not specified a [StateError] is thrown.
List<String> listTemplates() {
if (loader case var loader?) {
return loader.listTemplates();
Expand Down Expand Up @@ -438,8 +441,8 @@ base class Environment {
};
}

// TODO(environment): add error message
throw ArgumentError.value(function, 'finalize');
// Dart doesn't support union types, so we have to throw an error here.
throw TypeError();
}

/// @nodoc
Expand Down Expand Up @@ -495,34 +498,38 @@ base class Template {
AttributeGetter? getAttribute,
ItemGetter getItem = defaults.getItem,
}) {
environment ??= Environment(
commentStart: commentStart,
commentEnd: commentEnd,
variableStart: variableStatr,
variableEnd: variableEnd,
blockStart: blockStart,
blockEnd: blockEnd,
lineCommentPrefix: lineCommentPrefix,
lineStatementPrefix: lineStatementPrefix,
leftStripBlocks: leftStripBlocks,
trimBlocks: trimBlocks,
newLine: newLine,
keepTrailingNewLine: keepTrailingNewLine,
optimize: optimize,
finalize: finalize,
autoReload: false,
globals: globals,
filters: filters,
tests: tests,
modifiers: modifiers,
random: random,
getAttribute: getAttribute,
getItem: getItem,
);
if (environment == null) {
return Environment(
commentStart: commentStart,
commentEnd: commentEnd,
variableStart: variableStatr,
variableEnd: variableEnd,
blockStart: blockStart,
blockEnd: blockEnd,
lineCommentPrefix: lineCommentPrefix,
lineStatementPrefix: lineStatementPrefix,
leftStripBlocks: leftStripBlocks,
trimBlocks: trimBlocks,
newLine: newLine,
keepTrailingNewLine: keepTrailingNewLine,
optimize: optimize,
finalize: finalize,
autoReload: false,
globals: globals,
filters: filters,
tests: tests,
modifiers: modifiers,
random: random,
getAttribute: getAttribute,
getItem: getItem,
).fromString(source, path: path);
}

return environment.fromString(source, path: path);
return environment.fromString(source, path: path, globals: globals);
}

/// This is used internally by the [Environment.fromString] to create
/// templates from parsed sources.
@internal
Template.fromNode(
this.environment, {
Expand Down
10 changes: 5 additions & 5 deletions lib/src/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ List<Object?> list(Object? value) {
/// Creates an [Iterable] of [int]s that iterates from `start` to `stop` by `step`.
Iterable<int> range(int startOrStop, [int? stop, int step = 1]) sync* {
if (step == 0) {
// TODO(error): add message
throw ArgumentError.value(step, 'step');
// TODO(utils): add message
throw ArgumentError.value(step, 'step', "Step can't be zero.");
}

int start;
Expand All @@ -119,12 +119,12 @@ Iterable<int> range(int startOrStop, [int? stop, int step = 1]) sync* {
start = startOrStop;
}

if (step < 0) {
for (var i = start; i >= stop; i += step) {
if (step > 0) {
for (var i = start; i < stop; i += step) {
yield i;
}
} else {
for (var i = start; i < stop; i += step) {
for (var i = start; i >= stop; i += step) {
yield i;
}
}
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: jinja
version: 0.6.0-dev.15
version: 0.6.0-dev.16
description: >-
Jinja2 template engine for Dart.
Variables, expressions, control structures and template inheritance.
Expand Down

0 comments on commit 686d9dd

Please sign in to comment.