Skip to content

Commit

Permalink
0.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ykmnkmi committed Mar 30, 2024
1 parent 686d9dd commit da439f6
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 10 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## unreleased ([diff](https://github.com/ykmnkmi/jinja.dart/compare/c12244e6..be035c5f))
## 0.6.0 ([diff](https://github.com/ykmnkmi/jinja.dart/compare/c12244e6..main))
- bump SDK version to 3.3.0.
- update dependencies.
- internal changes.
Expand All @@ -8,6 +8,7 @@
- `import`
- `from`
- `Template`:
- `Template.fromNode({globals})` argument
- `globals` field
- restored:
- conditional and variable `extends` statement variants
Expand Down Expand Up @@ -35,7 +36,7 @@
- `title`
- changed:
- `Environment`:
- `Environment({modifiers})` from `List<NodeVisitor>` to `List<Node Function(Node)>`
- `Environment({modifiers})` argument type from `List<NodeVisitor>` to `List<Node Function(Node)>`
- `modifiers` type from `List<NodeVisitor>` to `List<Node Function(Node)>`
- `scan(...)` return type from `List<Node>` to `Node`
- `parse(...)` return type from `List<Node>` to `Node`
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ Variables, expressions, control structures and template inheritance.
- `*args` and `**kwargs` arguments support removed
- Auto-escaping and related statements, filters and tests have been removed due to the impossibility of extending `String`.
Use the `escape` filter manually or escape values before passing them to the template.
- _work in progress_

For more information, see `CHANGELOG.md`.

Expand Down
5 changes: 0 additions & 5 deletions lib/loaders.dart
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,4 @@ class FileSystemLoader extends Loader {
return environment.fromString(getSource(path),
path: path, globals: globals);
}

@override
String toString() {
return 'FileSystemLoader(${paths.join(', ')})';
}
}
2 changes: 1 addition & 1 deletion lib/src/environment.dart
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ base class Template {
String render([Map<String, Object?>? data]) {
var buffer = StringBuffer();
renderTo(buffer, data);
return buffer.toString();
return '$buffer';
}

/// If no arguments are given the context will be empty.
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.16
version: 0.6.0
description: >-
Jinja2 template engine for Dart.
Variables, expressions, control structures and template inheritance.
Expand Down
41 changes: 41 additions & 0 deletions test/file_system_loader_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
@TestOn('vm')
library;

import 'dart:convert';
import 'dart:io';

import 'package:jinja/jinja.dart';
import 'package:jinja/loaders.dart';
import 'package:test/test.dart';

void main() {
var pathUri = Directory.current.uri.resolve('test/res/templates');
var paths = <String>[pathUri.path];

group('FileSystemLoader', () {
test('paths', () {
var loader = FileSystemLoader(paths: paths);
var env = Environment(loader: loader);
var tmpl = env.getTemplate('test.html');
expect(tmpl.render().trim(), equals('BAR'));
tmpl = env.getTemplate('foo/test.html');
expect(tmpl.render().trim(), equals('FOO'));
});

test('utf8', () {
var loader = FileSystemLoader(
paths: paths, extensions: <String>{'txt'}, encoding: utf8);
var env = Environment(loader: loader);
var tmpl = env.getTemplate('mojibake.txt');
expect(tmpl.render().trim(), equals('文字化け'));
});

test('iso-8859-1', () {
var loader = FileSystemLoader(
paths: paths, extensions: <String>{'txt'}, encoding: latin1);
var env = Environment(loader: loader);
var tmpl = env.getTemplate('mojibake.txt');
expect(tmpl.render().trim(), equals(\x96\x87\xe5\xad\x97\xe5\x8c\x96\xe3\x81\x91'));
});
});
}
21 changes: 21 additions & 0 deletions test/loader_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
@TestOn('vm || chrome')
library;

import 'package:jinja/jinja.dart';
import 'package:test/test.dart';

MapLoader mapLoader() {
return MapLoader({'justdict.html': 'FOO'});
}

void main() {
group('Loaders', () {
test('MapLoader', () {
var env = Environment(loader: mapLoader());
var tmpl = env.getTemplate('justdict.html');
expect(tmpl.render().trim(), equals('FOO'));
expect(() => env.getTemplate('missing.html'),
throwsA(isA<TemplateNotFound>()));
});
});
}
1 change: 1 addition & 0 deletions test/res/templates/foo/test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FOO
1 change: 1 addition & 0 deletions test/res/templates/mojibake.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
文字化け

0 comments on commit da439f6

Please sign in to comment.