2021-06-26 10:34:23 +00:00
|
|
|
import 'package:angel3_framework/angel3_framework.dart';
|
2019-01-29 18:06:58 +00:00
|
|
|
import 'package:jinja/jinja.dart';
|
|
|
|
|
|
|
|
/// Configures an Angel server to use Jinja2 to render templates.
|
|
|
|
///
|
|
|
|
/// By default, templates are loaded from the filesystem;
|
|
|
|
/// pass your own [createLoader] callback to override this.
|
|
|
|
///
|
|
|
|
/// All options other than [createLoader] are passed to either [FileSystemLoader]
|
|
|
|
/// or [Environment].
|
|
|
|
AngelConfigurer jinja({
|
2021-06-20 12:37:20 +00:00
|
|
|
Set<String> ext = const {'html'},
|
2019-01-29 18:06:58 +00:00
|
|
|
String path = 'lib/src/templates',
|
|
|
|
bool followLinks = true,
|
2021-06-20 12:37:20 +00:00
|
|
|
String blockStart = '{%',
|
|
|
|
String blockEnd = '%}',
|
2019-01-29 18:06:58 +00:00
|
|
|
String varOpen = '{{',
|
|
|
|
String varClose = '}}',
|
2021-06-20 12:37:20 +00:00
|
|
|
String commentStart = '{#',
|
|
|
|
String commentEnd = '#}',
|
2019-01-29 18:06:58 +00:00
|
|
|
defaultValue,
|
2021-06-20 12:37:20 +00:00
|
|
|
//bool autoReload = true,
|
2019-01-29 18:06:58 +00:00
|
|
|
Map<String, Function> filters = const <String, Function>{},
|
|
|
|
Map<String, Function> tests = const <String, Function>{},
|
2021-06-20 12:37:20 +00:00
|
|
|
Loader Function()? createLoader,
|
2019-01-29 18:06:58 +00:00
|
|
|
}) {
|
|
|
|
return (app) {
|
|
|
|
createLoader ??= () {
|
|
|
|
return FileSystemLoader(
|
2021-06-20 12:37:20 +00:00
|
|
|
extensions: ext,
|
2019-01-29 18:06:58 +00:00
|
|
|
path: path,
|
|
|
|
followLinks: followLinks,
|
|
|
|
);
|
|
|
|
};
|
|
|
|
var env = Environment(
|
2021-06-20 12:37:20 +00:00
|
|
|
loader: createLoader!(),
|
|
|
|
blockStart: blockStart,
|
|
|
|
blockEnd: blockEnd,
|
|
|
|
variableStart: varOpen,
|
|
|
|
variableEnd: varClose,
|
|
|
|
commentStart: commentStart,
|
|
|
|
commentEnd: commentEnd,
|
2021-02-14 05:22:25 +00:00
|
|
|
//defaultValue: defaultValue,
|
2021-06-20 12:37:20 +00:00
|
|
|
//autoReload: autoReload,
|
2019-01-29 18:06:58 +00:00
|
|
|
filters: filters,
|
|
|
|
tests: tests,
|
|
|
|
);
|
|
|
|
|
|
|
|
app.viewGenerator = (path, [values]) {
|
2021-12-02 06:49:18 +00:00
|
|
|
return env.getTemplate(path).render.renderMap(values) as String;
|
2019-01-29 18:06:58 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|