Merge pull request #32 from dukefirehawk/feature/update-jael

Optimised JAEL output
This commit is contained in:
Thomas Hii 2021-12-23 07:37:39 +08:00 committed by GitHub
commit d8336d26b5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 21 additions and 16 deletions

View file

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

View file

@ -18,8 +18,7 @@ dependencies:
## Usage ## Usage
Just like `mustache` and other renderers, configuring Angel to use Just like `mustache` and other renderers, configuring Angel to use Jael is as simple as calling `app.configure`:
Jael is as simple as calling `app.configure`:
```dart ```dart
import 'package:angel3_framework/angel3_framework.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 ```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`. 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, bool cacheViews = true,
Iterable<Patcher> patch = const [], Iterable<Patcher> patch = const [],
bool asDSX = false, bool asDSX = false,
bool minified = false, bool minified = true,
CodeBuffer Function()? createBuffer}) { CodeBuffer Function()? createBuffer}) {
var cache = <String, Document>{}; var cache = <String, Document>{};

View file

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

View file

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

View file

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