platform/packages/jael/angel_jael
2024-10-12 19:17:24 -07:00
..
example Refactor: changing namespace, imports, re-branding 2024-10-12 18:45:27 -07:00
lib Refactor: changing namespace, imports, re-branding 2024-10-12 18:45:27 -07:00
test Refactor: changing namespace, imports, re-branding 2024-10-12 18:45:27 -07: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 Refactor: changing namespace, imports, re-branding 2024-10-12 03:39:20 -07:00
LICENSE Updated Jael to use belatuk_symbol_table 2021-09-13 08:30:02 +08:00
melos_angel3_jael.iml Added melos 2022-03-19 09:37:28 +08:00
pubspec.yaml Refactor: changing namespace, imports, re-branding 2024-10-12 18:45:27 -07:00
README.md Refactor: changing namespace, imports, re-branding 2024-10-12 19:17:24 -07:00

Protevus Jael

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

Protevus 3 support for Jael 3.

Installation

In your pubspec.yaml:

dependencies:
  protevus_jael: ^8.0.0

Usage

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

import 'package:protevus_framework/protevus_framework.dart';
import 'package:protevus_jael/protevus_jael.dart';
import 'package:file/file.dart';

ProtevusConfigurer myPlugin(FileSystem fileSystem) {
    return (Protevus app) async {
        // Connect Jael to your server...
        await app.configure(
        jael(fileSystem.directory('views')),
      );
    };
}

package:protevus_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:

jael(viewsDirectory, cacheViews: false, minified: false);

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:protevus_framework/protevus_framework.dart';
import 'package:protevus_jael/protevus_jael.dart';
import 'package:file/local.dart';
import 'package:logging/logging.dart';

void main() async {
  var app = Protevus();
  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 ProtevusHttpException.notFound());

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

Performance Optimization

For handling large volume of initial requests, consider using jaelTemplatePreload to preload all the JAEL templates into an external cache.


  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),
  );