Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adds JadeBrowserPrecompiler to render .jade.js template-functions as …

…files.
  • Loading branch information...
commit faf992816d3cb345ab1531c45f43e47819b32875 1 parent e1bc8b1
@dsc authored
Showing with 59 additions and 3 deletions.
  1. +28 −1 compiler.co
  2. +31 −2 compiler.js
View
29 compiler.co
@@ -518,11 +518,37 @@ class exports.JadeCompiler extends Compiler
match : /\.html?$/i
ext : '.jade'
module : 'jade'
- options : (opts={}) -> { pretty:true, filename:@info.src } <<< opts
+ options : (opts={}) -> { +pretty, filename:@info.src } <<< opts
compile : 'render'
-> super ...
+class exports.JadeBrowserPrecompiler extends Compiler
+ id : 'jade-browser'
+ match : /\.jade(?:\.mod)?(\.min)?\.js$/i
+ ext : '.jade'
+ destExt : '.jade.js'
+ module : 'jade'
+
+ options : (opts={}) ->
+ # Turning on options.compileDebug is +40% (bytes) to the templater function
+ { +pretty, +client, -compileDebug, filename:@info.src } <<< opts
+
+ -> super ...
+ compileSync : (text, options={}) ->
+ template_fn = @module.compile text, options
+ # Convert "anonymous" named function statement to function expression
+ template = String template_fn .replace /^function anonymous\(/, 'function \('
+
+ """
+ var template = #template;
+ if (typeof module != 'undefined') {
+ module.exports = exports = template;
+ }
+ """
+
+
+
### CSS Compilers
@@ -605,6 +631,7 @@ class exports.JisonCompiler extends Compiler
CocoCompiler
UglifyCompiler
JadeCompiler
+ JadeBrowserPrecompiler
StylusCompiler
LessCompiler
SassCompiler
View
33 compiler.js
@@ -1,4 +1,4 @@
-var fs, path, parse, EventEmitter, exec, spawn, Seq, setup, exports, compilers, DEFAULTS, LOG, CompilerMiddleware, register, Compiler, ExternalCompiler, CoffeeScriptCompiler, CocoCompiler, UglifyCompiler, JadeCompiler, StylusCompiler, LessCompiler, SassCompiler, SassRubyCompiler, JisonCompiler, helpers, expand, extrema, commonPrefix, commonPath, mkdirp, _ref, __slice = [].slice;
+var fs, path, parse, EventEmitter, exec, spawn, Seq, setup, exports, compilers, DEFAULTS, LOG, CompilerMiddleware, register, Compiler, ExternalCompiler, CoffeeScriptCompiler, CocoCompiler, UglifyCompiler, JadeCompiler, JadeBrowserPrecompiler, StylusCompiler, LessCompiler, SassCompiler, SassRubyCompiler, JisonCompiler, helpers, expand, extrema, commonPrefix, commonPath, mkdirp, _ref, __slice = [].slice;
fs = require('fs');
path = require('path');
parse = require('url').parse;
@@ -632,6 +632,35 @@ exports.JadeCompiler = JadeCompiler = (function(superclass){
}
return JadeCompiler;
}(Compiler));
+exports.JadeBrowserPrecompiler = JadeBrowserPrecompiler = (function(superclass){
+ JadeBrowserPrecompiler.displayName = 'JadeBrowserPrecompiler';
+ var prototype = __extend(JadeBrowserPrecompiler, superclass).prototype, constructor = JadeBrowserPrecompiler;
+ prototype.id = 'jade-browser';
+ prototype.match = /\.jade(?:\.mod)?(\.min)?\.js$/i;
+ prototype.ext = '.jade';
+ prototype.destExt = '.jade.js';
+ prototype.module = 'jade';
+ prototype.options = function(opts){
+ opts == null && (opts = {});
+ return __import({
+ pretty: true,
+ client: true,
+ compileDebug: false,
+ filename: this.info.src
+ }, opts);
+ };
+ function JadeBrowserPrecompiler(){
+ superclass.apply(this, arguments);
+ }
+ prototype.compileSync = function(text, options){
+ var template_fn, template;
+ options == null && (options = {});
+ template_fn = this.module.compile(text, options);
+ template = String(template_fn).replace(/^function anonymous\(/, 'function (');
+ return "var template = " + template + ";\nif (typeof module != 'undefined') {\n module.exports = exports = template;\n}";
+ };
+ return JadeBrowserPrecompiler;
+}(Compiler));
exports.StylusCompiler = StylusCompiler = (function(superclass){
StylusCompiler.displayName = 'StylusCompiler';
var prototype = __extend(StylusCompiler, superclass).prototype, constructor = StylusCompiler;
@@ -726,7 +755,7 @@ exports.JisonCompiler = JisonCompiler = (function(superclass){
};
return JisonCompiler;
}(Compiler));
-[CoffeeScriptCompiler, CocoCompiler, UglifyCompiler, JadeCompiler, StylusCompiler, LessCompiler, SassCompiler, JisonCompiler, SassRubyCompiler].map(register);
+[CoffeeScriptCompiler, CocoCompiler, UglifyCompiler, JadeCompiler, JadeBrowserPrecompiler, StylusCompiler, LessCompiler, SassCompiler, JisonCompiler, SassRubyCompiler].map(register);
helpers = exports.helpers = {};
helpers.expand = expand = function(){
var parts, p, home;
Please sign in to comment.
Something went wrong with that request. Please try again.