Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions compiler.co
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,11 @@ class exports.Compiler extends EventEmitter
*/
matches: (srcDir, pathname) ->
@log LOG.DEBUG, "matches(#srcDir, #pathname)"
path.join srcDir, pathname.replace(@match, @ext) if @match.exec(pathname)

found= @match.exec(pathname)
return if not found
@info.matchIndex= found.index
path.join srcDir, pathname.replace(@match, @ext)

srcValid: (src, cb) ->
fs.stat src, cb

Expand Down Expand Up @@ -352,11 +355,11 @@ class exports.Compiler extends EventEmitter
opts = @options(info_opts)
else if @options or info_opts
opts = {} <<< @options <<< info_opts
args = [text] + (if opts? then [opts] else [])
args = [text, ...opts]

if fn = @compile
fn = @module[fn] if typeof fn is not 'function'
fn.apply this, args + [cb]
fn.apply this, [...args, cb]
else if fn = @compileSync
fn = @module[fn] if typeof fn is not 'function'
try
Expand Down Expand Up @@ -644,6 +647,18 @@ class exports.YamlCompiler extends Compiler
-> super ...


class exports.DustCompiler extends Compiler
id : 'dust'
ext : '.dust'
module : 'dustjs-linkedin'
options : {}
compileSync : (data) ->
path= @info.path
path= path.substring if path[0] == "/" then 1 else 0, @info.matchIndex
@module.compile data, path
-> super ...




# Register Compilers
Expand All @@ -660,6 +675,7 @@ class exports.YamlCompiler extends Compiler
SassRubyCompiler
YamlCompiler
SnocketsCompiler
DustCompiler
].map register


Expand Down Expand Up @@ -723,7 +739,7 @@ helpers.mkdirp = mkdirp = function mkdirp (p, mode=8r0755, cb)
cb or= (->)
p = expand(p)

exists <- path.exists p
exists <- (fs.exists || path.exists) p
return cb null if exists

ps = p.split('/')
Expand Down
38 changes: 29 additions & 9 deletions compiler.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var fs, path, parse, EventEmitter, exec, spawn, Seq, setup, exports, compilers, DEFAULTS, LOG, CompilerMiddleware, register, Compiler, ExternalCompiler, CoffeeScriptCompiler, SnocketsCompiler, CocoCompiler, UglifyCompiler, JadeCompiler, JadeBrowserPrecompiler, StylusCompiler, LessCompiler, SassCompiler, SassRubyCompiler, JisonCompiler, YamlCompiler, 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, SnocketsCompiler, CocoCompiler, UglifyCompiler, JadeCompiler, JadeBrowserPrecompiler, StylusCompiler, LessCompiler, SassCompiler, SassRubyCompiler, JisonCompiler, YamlCompiler, DustCompiler, helpers, expand, extrema, commonPrefix, commonPath, mkdirp, __ref, __slice = [].slice;
fs = require('fs');
path = require('path');
parse = require('url').parse;
Expand Down Expand Up @@ -301,10 +301,14 @@ exports.Compiler = Compiler = (function(superclass){
* @returns {String|String[]|false-y} Resolved source path(s) if compiler matches, false otherwise.
*/
prototype.matches = function(srcDir, pathname){
var found;
this.log(LOG.DEBUG, "matches(" + srcDir + ", " + pathname + ")");
if (this.match.exec(pathname)) {
return path.join(srcDir, pathname.replace(this.match, this.ext));
found = this.match.exec(pathname);
if (!found) {
return;
}
this.info.matchIndex = found.index;
return path.join(srcDir, pathname.replace(this.match, this.ext));
};
prototype.srcValid = function(src, cb){
return fs.stat(src, cb);
Expand Down Expand Up @@ -402,9 +406,7 @@ exports.Compiler = Compiler = (function(superclass){
} else if (this.options || info_opts) {
opts = __import(__import({}, this.options), info_opts);
}
args = [text].concat(opts != null
? [opts]
: []);
args = [text].concat(__slice.call(opts));
if (fn = this.compile) {
if (typeof fn !== 'function') {
fn = this.module[fn];
Expand Down Expand Up @@ -791,7 +793,25 @@ exports.YamlCompiler = YamlCompiler = (function(superclass){
}
return YamlCompiler;
}(Compiler));
[CoffeeScriptCompiler, CocoCompiler, UglifyCompiler, JadeCompiler, JadeBrowserPrecompiler, StylusCompiler, LessCompiler, SassCompiler, JisonCompiler, SassRubyCompiler, YamlCompiler, SnocketsCompiler].map(register);
exports.DustCompiler = DustCompiler = (function(superclass){
DustCompiler.displayName = 'DustCompiler';
var prototype = extend$(DustCompiler, superclass).prototype, constructor = DustCompiler;
prototype.id = 'dust';
prototype.ext = '.dust';
prototype.module = 'dustjs-linkedin';
prototype.options = {};
prototype.compileSync = function(data){
var path;
path = this.info.path;
path = path.substring(path[0] == "/" ? 1 : 0, this.info.matchIndex);
return this.module.compile(data, path);
};
function DustCompiler(){
superclass.apply(this, arguments);
}
return DustCompiler;
}(Compiler));
[CoffeeScriptCompiler, CocoCompiler, UglifyCompiler, JadeCompiler, JadeBrowserPrecompiler, StylusCompiler, LessCompiler, SassCompiler, JisonCompiler, SassRubyCompiler, YamlCompiler, SnocketsCompiler, DustCompiler].map(register);
helpers = exports.helpers = {};
helpers.expand = expand = function(){
var parts, p, home;
Expand Down Expand Up @@ -868,7 +888,7 @@ helpers.mkdirp = mkdirp = (function(){
}
cb || (cb = function(){});
p = expand(p);
return path.exists(p, function(exists){
return (fs.exists || path.exists)(p, function(exists){
var ps, _p;
if (exists) {
return cb(null);
Expand Down Expand Up @@ -904,4 +924,4 @@ function __import(obj, src){
var own = {}.hasOwnProperty;
for (var key in src) if (own.call(src, key)) obj[key] = src[key];
return obj;
}
}