jade-code-gen
Advanced tools
Comparing version 0.0.1 to 0.0.2
38
index.js
@@ -10,3 +10,14 @@ 'use strict'; | ||
var stringify = require('js-stringify'); | ||
var addWith = require('with'); | ||
var INTERNAL_VARIABLES = [ | ||
'jade', | ||
'jade_mixins', | ||
'jade_interp', | ||
'jade_debug_filename', | ||
'jade_debug_line', | ||
'jade_debug_sources', | ||
'buf' | ||
]; | ||
module.exports = generateCode; | ||
@@ -106,3 +117,28 @@ module.exports.CodeGenerator = Compiler; | ||
} | ||
return buildRuntime(this.runtimeFunctionsUsed) + this.buf.join('\n'); | ||
var js = this.buf.join('\n'); | ||
var globals = this.options.globals ? this.options.globals.concat(INTERNAL_VARIABLES) : INTERNAL_VARIABLES; | ||
if (this.options.self) { | ||
js = 'var self = locals || {};' + js; | ||
} else { | ||
js = addWith('locals || {}', js, globals.concat(this.runtimeFunctionsUsed.map(function (name) { return 'jade_' + name; }))); | ||
} | ||
if (this.debug) { | ||
if (this.options.includeSources) { | ||
js = 'var jade_debug_sources = ' + stringify(this.options.includeSources) + ';\n' + js; | ||
} | ||
js = 'var jade_debug_filename, jade_debug_line;' + | ||
'try {' + | ||
js + | ||
'} catch (err) {' + | ||
(this.inlineRuntimeFunctions ? 'jade_rethrow' : 'jade.rethrow') + | ||
'(err, jade_debug_filename, jade_debug_line' + | ||
( | ||
this.options.includeSources | ||
? ', jade_debug_sources[jade_debug_filename]' | ||
: '' | ||
) + | ||
');' + | ||
'}'; | ||
} | ||
return buildRuntime(this.runtimeFunctionsUsed) + 'function ' + (this.options.templateName || 'template') + '(locals) {var buf = [], jade_mixins = {}, jade_interp;' + js + ';return buf.join("");}'; | ||
}, | ||
@@ -109,0 +145,0 @@ |
{ | ||
"name": "jade-code-gen", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Default code-generator for jade. It generates HTML via a JavaScript template function.", | ||
@@ -12,3 +12,4 @@ "keywords": [], | ||
"js-stringify": "^1.0.1", | ||
"void-elements": "^2.0.1" | ||
"void-elements": "^2.0.1", | ||
"with": "^5.0.0" | ||
}, | ||
@@ -15,0 +16,0 @@ "devDependencies": { |
@@ -13,4 +13,17 @@ # jade-code-gen | ||
## Usage | ||
Options: | ||
- pretty (boolean) | ||
- compileDebug (boolean) - defaults to `true` | ||
- doctype (string) | ||
- includeRuntimeFunctions (boolean) | ||
- globals (array of strings) | ||
- self (boolean) | ||
- includeSources (map of filename to source string) | ||
- templateName (string) - defaults to `'template'` | ||
## License | ||
MIT |
24221
691
29
7
+ Addedwith@^5.0.0
+ Addedacorn@3.3.04.0.13(transitive)
+ Addedacorn-globals@3.1.0(transitive)
+ Addedwith@5.1.1(transitive)