platform/packages/jael/angel_jael
2021-11-25 08:33:56 +08:00
..
example publish angel_jael 2021-05-15 18:45:39 +08:00
lib Updated jael 2021-11-25 08:33:56 +08:00
test Updated jael 2021-11-25 08:33:56 +08:00
analysis_options.yaml Updated Jael to use belatuk_symbol_table 2021-09-13 08:30:02 +08:00
AUTHORS.md Restore jael to original name 2021-05-15 17:55:55 +08:00
CHANGELOG.md Updated jael 2021-11-25 08:33:56 +08:00
LICENSE Updated Jael to use belatuk_symbol_table 2021-09-13 08:30:02 +08:00
mono_pkg.yaml Restore jael to original name 2021-05-15 17:55:55 +08:00
pubspec.yaml Updated jael 2021-11-25 08:33:56 +08:00
README.md Updated linter to package:lints 2021-09-25 14:32:32 +08:00

Angel3 Jael

Pub Version (including pre-releases) Null Safety Gitter License

Angel 3 support for Jael 3.

Installation

In your pubspec.yaml:

dependencies:
  angel3_jael: ^4.2.0

Usage

Just like mustache and other renderers, configuring Angel to use Jael is as simple as calling app.configure:

import 'package:angel3_framework/angel3_framework.dart';
import 'package:angel3_jael/angel3_jael.dart';
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')),
      );
    };
}

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:

jael(viewsDirectory, cacheViews: app.isProduction);

Keep in mind that this package uses package:file, rather than dart:io.

The following is a basic example of a server setup that can render Jael templates from a directory named views:

import 'package:angel3_framework/angel3_framework.dart';
import 'package:angel3_jael/angel3_jael.dart';
import 'package:file/local.dart';
import 'package:logging/logging.dart';

void main() async {
  var app = Angel();
  var fileSystem = const LocalFileSystem();

  await app.configure(
    jael(fileSystem.directory('views')),
  );

  // Render the contents of views/index.jael
  app.get('/', (res) => res.render('index', {'title': 'ESKETTIT'}));

  app.use(() => throw AngelHttpException.notFound());

  app.logger = Logger('angel')
    ..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}');
}

To apply additional transforms to parsed documents, provide a set of patch functions, like in package:jael3_preprocessor.