jaded 0.1.6 copy "jaded: ^0.1.6" to clipboard
jaded: ^0.1.6 copied to clipboard

outdatedDart 1 only

Port of node.js popular Jade view engine for Dart.

jaded #

Port of the excellent Jade view engine in Dart.

Now feature complete with the original jade view engine, please refer to their detailed documentation to learn about Jade's features and syntax.

Although the aim was to have a high-fidelity port, the major syntactical difference compared with the original Jade (in JavaScript) is that the compiler only emits and executes Dart code, so any embedded code in views must be valid Dart (i.e. instead of JavaScript).

Installing via Pub #

Add this to your package's pubspec.yaml file:

dependencies:
  jaded: 0.1.5

Public API #

Compile a function at runtime #

import "package:jaded/jaded.dart" as jade;

var renderAsync = jade.compile('string of jade', { //Optional Compiler Defaults:    
  Map locals,
  String filename,
  String basedir,
  String doctype,
  bool pretty:false,
  bool compileDebug:false,
  bool debug:false,
  bool colons:false,
  bool autoSemicolons:true  
});

renderAsync(locals)
  .then((html) => print(html));

Compile a Directory #

Add a pre-build step and use renderDirectory to statically compile all views into a single jade.views.dart file containing a Map of all compiled Jade views, e.g:

import "dart:io";
import "package:jaded/jaded.dart" as jade;

var jadeTemplates = jade.renderDirectory('.');
new File('jade.views.dart').writeAsString(jadeTemplates);

Writes to jade.views.dart snippet:

Map<String,Function> JADE_TEMPLATES = {
  './index.jade': ([Map locals]){
     ...
  },
  './dir/page.jade': ([Map locals]){
    ...
  },
}

Usage:

import "jade.views.dart";

var render = JADE_TEMPLATES['./index.jade'];
var html = render({'title': 'Hello Jade!'});

Options #

  • locals Local variable object
  • filename Used in exceptions, and required when using includes
  • basedir The basedir where views start from
  • doctype What doctype to use
  • pretty Add pretty-indentation whitespace to output (false by default)
  • debug Outputs tokens and function body generated
  • compileDebug When false no debug instrumentation is compiled
  • autoSemicolons Auto add missing semicolons at the end of new lines (true by default)

Web Frameworks #

Current Status #

All tests in jade.test.dart are now passing.

All integration test cases in /test/cases that doesn't make use of an external DSL library are passing, specifically:

filters.coffeescript.jade
filters.less.jade
filters.markdown.jade
filters.stylus.jade
include-filter-stylus.jade
include-filter.jade  //markdown

When they become available support for external Web DSL's can be added to transformers.dart in the same way as done inside Jade's feature-rich transformers.js.

Missing eval #

Jade relies on eval'ing code-gen to work which is a limitation in Dart that lacks eval.
To get around this when compiling on the fly, we're currently wrapping the code-gen Dart inside an Isolate and writing it out to a file then immediately reading it back in with spawnUri and invoking the new code asynchronously in the runCompiledDartInIsolate() method.

Although this works, it forces us to have an async API to convert jade to html at runtime. When Dart offers a sync API for evaluating Dart code we'll convert it back to a sync API.

Pre-compilation of views #

The alternative is to pre-compile all views with renderDirectory() out to a static file at design time. The Dart Editor build.dart build system can be used to trigger the background compilation of .jade views when it detects a .jade file was saved or deleted. This is the approach the Express web framework takes with its express_build.dart helper.


Contributors #

2
likes
0
pub points
4%
popularity

Publisher

verified publishercheney-enterprises.com

Port of node.js popular Jade view engine for Dart.

Repository (GitHub)
View/report issues

Documentation

Documentation

License

unknown (LICENSE)

Dependencies

character_parser, node_shims

More

Packages that depend on jaded