diff --git a/compiler.co b/compiler.co index ed14a96..d247af3 100644 --- a/compiler.co +++ b/compiler.co @@ -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 @@ -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 @@ -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 @@ -660,6 +675,7 @@ class exports.YamlCompiler extends Compiler SassRubyCompiler YamlCompiler SnocketsCompiler + DustCompiler ].map register @@ -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('/') diff --git a/compiler.js b/compiler.js index f34b859..820eb76 100644 --- a/compiler.js +++ b/compiler.js @@ -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; @@ -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); @@ -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]; @@ -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; @@ -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); @@ -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; -} \ No newline at end of file +}