platform/angel_jael
2018-12-10 12:45:16 -05:00
..
example remove undeveloped pkgs 2018-12-10 12:45:16 -05:00
lib angel_jael@2.0.0 2018-11-10 16:48:03 -05:00
test angel_jael@2.0.0 2018-11-10 16:48:03 -05:00
.gitignore Use Renderer.errorDocument 2018-04-03 11:34:52 -04:00
analysis_options.yaml Dart 2 update for pkg:jael 2018-11-02 20:16:03 -04:00
CHANGELOG.md angel_jael@2.0.0 2018-11-10 16:48:03 -05:00
LICENSE Pre-processor needs work 2017-09-30 01:27:31 -04:00
mono_pkg.yaml Dart 2 update for pkg:jael 2018-11-02 20:16:03 -04:00
pubspec.yaml preproc 2.0.1 2018-11-12 17:03:23 -05:00
README.md angel_jael@2.0.0 2018-11-10 16:48:03 -05:00

jael

Pub build status

Angel support for Jael.

Installation

In your pubspec.yaml:

dependencies:
  angel_jael: ^1.0.0-alpha

Usage

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

import 'package:angel_framework/angel_framework.dart';
import 'package:angel_jael/angel_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:angel_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:angel_framework/angel_framework.dart';
import 'package:angel_jael/angel_jael.dart';
import 'package:file/local.dart';
import 'package:logging/logging.dart';

main() async {
  var app = new 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 new AngelHttpException.notFound());

  app.logger = new 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:jael_preprocessor.