Optimised JAEL output

This commit is contained in:
thomashii 2021-12-23 07:34:41 +08:00
parent 61410f8d9d
commit ab6a4895d0
6 changed files with 21 additions and 16 deletions

View file

@ -1,8 +1,12 @@
# Change Log
## 4.2.3
* Turned on generated HTML minification by default
## 4.2.2
* Set default `cacheViews` to true
* Turned on JAEL template caching by default
## 4.2.1

View file

@ -18,8 +18,7 @@ dependencies:
## Usage
Just like `mustache` and other renderers, configuring Angel to use
Jael is as simple as calling `app.configure`:
Just like `mustache` and other renderers, configuring Angel to use Jael is as simple as calling `app.configure`:
```dart
import 'package:angel3_framework/angel3_framework.dart';
@ -36,10 +35,10 @@ AngelConfigurer myPlugin(FileSystem fileSystem) {
}
```
`package:angel3_jael` supports caching views, to improve server performance. You might not want to enable this in development, so consider setting the flag to `app.isProduction`:
`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`:
```dart
jael(viewsDirectory, cacheViews: app.isProduction);
jael(viewsDirectory, cacheViews: false, minified: false);
```
Keep in mind that this package uses `package:file`, rather than `dart:io`.

View file

@ -19,7 +19,7 @@ AngelConfigurer jael(Directory viewsDirectory,
bool cacheViews = true,
Iterable<Patcher> patch = const [],
bool asDSX = false,
bool minified = false,
bool minified = true,
CodeBuffer Function()? createBuffer}) {
var cache = <String, Document>{};

View file

@ -1,5 +1,5 @@
name: angel3_jael
version: 4.2.2
version: 4.2.3
description: Angel support for the Jael templating engine, similar to Blade or Liquid.
homepage: https://angel3-framework.web.app/
repository: https://github.com/dukefirehawk/angel/tree/master/packages/jael/angel_jael

View file

@ -46,7 +46,7 @@ void main() {
});
await app.configure(
jael(viewsDirectory),
jael(viewsDirectory, minified: false),
);
app.fallback((req, res) => throw AngelHttpException.notFound());

View file

@ -46,7 +46,7 @@ void main() {
});
await app.configure(
jael(viewsDirectory, minified: true),
jael(viewsDirectory, cacheViews: true),
);
app.fallback((req, res) => throw AngelHttpException.notFound());
@ -63,7 +63,7 @@ void main() {
test('can render', () async {
var response = await client.get(Uri.parse('/github/thosakwe'));
print('Body:\n${response.body}');
//print('Body:\n${response.body}');
expect(
html.parse(response.body).outerHtml,
html
@ -74,13 +74,15 @@ void main() {
});
test('can render multiples', () async {
var response = await client.get(Uri.parse('/github/thosakwe'));
response = await client.get(Uri.parse('/github/thosakwe'));
response = await client.get(Uri.parse('/github/thosakwe'));
response = await client.get(Uri.parse('/github/thosakwe'));
response = await client.get(Uri.parse('/github/thosakwe'));
// Load the view template and wait for it to be cached
var response1 = await client.get(Uri.parse('/github/thosakwe'));
print('Body:\n${response.body}');
for (var i = 0; i < 100; i++) {
client.get(Uri.parse('/github/thosakwe'));
}
var response = await client.get(Uri.parse('/github/thosakwe'));
//print('Body:\n${response.body}');
expect(
html.parse(response.body).outerHtml,
html