Skip to content

Commit

Permalink
rebuild
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Jul 15, 2011
1 parent 2822402 commit 7548d10
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 21 deletions.
46 changes: 26 additions & 20 deletions jade.js
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,16 @@ exports.Parser = Parser;

exports.nodes = require('./nodes');

/**
* Runtime helpers.
*/

exports.helpers = {
attrs: attrs
, escape: escape
, rethrow: rethrow
};

/**
* Render the given attributes object.
*
Expand Down Expand Up @@ -798,16 +808,13 @@ function rethrow(err, str, filename, lineno){

function parse(str, options){
var filename = options.filename
, helpers = ''
, inline = false !== options.inline
, inlined = '';

if (options.helpers !== 'inline') {
jadeHelpers = {
attrs: attrs,
escape: escape
}
helpers = 'var attrs = jadeHelpers.attrs, escape = jadeHelpers.escape;\n';
if (inline) {
inlined = attrs.toString() + '\n' + escape.toString() + '\n';
} else {
helpers = attrs.toString() + '\n' + escape.toString() + '\n';
inlined = 'var attrs = jade.attrs, escape = jade.escape;\n';
}

try {
Expand All @@ -826,7 +833,7 @@ function parse(str, options){

try {
return ''
+ helpers
+ inlined
+ 'var buf = [];\n'
+ (options.self
? 'var self = locals || {}, __ = __ || locals.__;\n' + js
Expand All @@ -846,8 +853,9 @@ function parse(str, options){
* Compile a `Function` representation of the given jade `str`.
*
* Options:
* - `compileDebug` Include/exclude debug helpers such as attrs, escape and rethrow, defaults to true
* - `helpers` Include helpers as `inline` or get from temporary `global` variables, defaults to `global`
*
* - `compileDebug` when `false` debugging code is stripped from the compiled template
* - `inline` when `false` helpers are not inlined
*
* @param {String} str
* @param {Options} options
Expand All @@ -858,26 +866,24 @@ function parse(str, options){
exports.compile = function(str, options){
var options = options || {}
, input = JSON.stringify(str)
, inline = false !== options.inline
, filename = options.filename
? JSON.stringify(options.filename)
: 'undefined'
, fn = []
, helpers = '';
, inlined = ''
, fn;

if (options.helpers !== 'inline') {
jadeHelpers = {
rethrow: rethrow
};
helpers = 'var rethrow = jadeHelpers.rethrow;';
if (inline) {
inlined = rethrow.toString();
} else {
helpers = rethrow.toString();
inlined = 'var rethrow = jade.rethrow;';
}

if (options.compileDebug !== false) {
// Reduce closure madness by injecting some locals
fn = [
'var __ = { lineno: 1, input: ' + input + ', filename: ' + filename + ' };'
, helpers
, inlined
, 'try {'
, parse(String(str), options || {})
, '} catch (err) {'
Expand Down
Loading

0 comments on commit 7548d10

Please sign in to comment.