2021-09-13 00:30:02 +00:00
# Angel3 Jael
2021-09-25 06:32:32 +00:00
![Pub Version (including pre-releases) ](https://img.shields.io/pub/v/angel3_jael?include_prereleases )
2021-05-15 10:45:39 +00:00
[![Null Safety ](https://img.shields.io/badge/null-safety-brightgreen )](https://dart.dev/null-safety)
[![Gitter ](https://img.shields.io/gitter/room/angel_dart/discussion )](https://gitter.im/angel_dart/discussion)
2021-09-25 06:32:32 +00:00
[![License ](https://img.shields.io/github/license/dukefirehawk/angel )](https://github.com/dukefirehawk/angel/tree/master/packages/jael/angel_jael/LICENSE)
2017-10-01 03:14:44 +00:00
2021-09-25 06:32:32 +00:00
[Angel 3 ](https://pub.dev/packages/angel3_framework ) support for [Jael 3 ](https://pub.dev/packages/jael3 ).
2021-05-15 10:45:39 +00:00
2021-09-13 00:30:02 +00:00
## Installation
2017-10-01 03:14:44 +00:00
In your `pubspec.yaml` :
```yaml
dependencies:
2022-04-24 00:55:17 +00:00
angel3_jael: ^6.0.0
2017-10-01 03:14:44 +00:00
```
2021-09-13 00:30:02 +00:00
## Usage
2021-12-22 23:34:41 +00:00
Just like `mustache` and other renderers, configuring Angel to use Jael is as simple as calling `app.configure` :
2017-10-01 03:14:44 +00:00
```dart
2021-05-15 10:45:39 +00:00
import 'package:angel3_framework/angel3_framework.dart';
import 'package:angel3_jael/angel3_jael.dart';
2017-10-01 03:14:44 +00:00
import 'package:file/file.dart';
AngelConfigurer myPlugin(FileSystem fileSystem) {
return (Angel app) async {
// Connect Jael to your server...
await app.configure(
jael(fileSystem.directory('views')),
);
};
}
```
2021-12-22 23:34:41 +00:00
`package:angel3_jael` supports caching views and minified html output by default, to improve performance. You might want to disable them in development, so consider setting these flags to `false` :
2017-10-01 03:14:44 +00:00
2021-09-13 00:30:02 +00:00
```dart
2021-12-22 23:34:41 +00:00
jael(viewsDirectory, cacheViews: false, minified: false);
2017-10-01 03:14:44 +00:00
```
2021-09-13 00:30:02 +00:00
Keep in mind that this package uses `package:file` , rather than `dart:io` .
2017-10-01 03:14:44 +00:00
2021-09-13 00:30:02 +00:00
The following is a basic example of a server setup that can render Jael templates from a directory named `views` :
2017-10-01 03:14:44 +00:00
```dart
2021-05-15 10:45:39 +00:00
import 'package:angel3_framework/angel3_framework.dart';
import 'package:angel3_jael/angel3_jael.dart';
2017-10-01 03:14:44 +00:00
import 'package:file/local.dart';
import 'package:logging/logging.dart';
2021-09-13 00:30:02 +00:00
void main() async {
2021-05-15 10:45:39 +00:00
var app = Angel();
2017-10-01 03:14:44 +00:00
var fileSystem = const LocalFileSystem();
await app.configure(
jael(fileSystem.directory('views')),
);
2018-11-10 21:48:03 +00:00
// Render the contents of views/index.jael
2017-10-01 03:14:44 +00:00
app.get('/', (res) => res.render('index', {'title': 'ESKETTIT'}));
2021-05-15 10:45:39 +00:00
app.use(() => throw AngelHttpException.notFound());
2017-10-01 03:14:44 +00:00
2021-05-15 10:45:39 +00:00
app.logger = Logger('angel')
2017-10-01 03:14:44 +00:00
..onRecord.listen((rec) {
print(rec);
if (rec.error != null) print(rec.error);
if (rec.stackTrace != null) print(rec.stackTrace);
});
var server = await app.startServer(null, 3000);
print('Listening at http://${server.address.address}:${server.port}');
}
2017-10-02 16:12:51 +00:00
```
2017-10-01 03:14:44 +00:00
2021-09-13 00:30:02 +00:00
To apply additional transforms to parsed documents, provide a set of `patch` functions, like in `package:jael3_preprocessor` .
2021-12-25 02:40:30 +00:00
## Performance Optimization
For handling large volume of initial requests, consider using `jaelTemplatePreload` to preload all the JAEL templates
into an external cache.
```dart
var templateDir = fileSystem.directory('views');
// Preload JAEL view templates into cache
var viewCache = < String , Document > {};
jaelTemplatePreload(templateDir, viewCache);
// Inject cache into JAEL renderer
await app.configure(
jael(fileSystem.directory('views'), cache: viewCache),
);
```