From 3eacee2f7317dc1fbf438f38999f06ac03902e59 Mon Sep 17 00:00:00 2001 From: rektide Date: Tue, 24 Jul 2012 09:22:23 -0400 Subject: [PATCH 1/4] Mark head as incompatible with Coco 0.7.6. --- package.co | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.co b/package.co index ba487cc..e4619b5 100644 --- a/package.co +++ b/package.co @@ -11,7 +11,7 @@ dependencies : # 'seq' : '>= 0.3.5' devDependencies : 'express' : '>= 2.5.8' - 'coco' : '>= 0.7.0' + 'coco' : '>= 0.7.0 < 0.7.6' 'coffee-script' : '>= 1.2.0' 'jade' : '>= 0.20.3' 'stylus' : '>= 0.24.0' diff --git a/package.json b/package.json index 9b687fd..3903308 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ }, "devDependencies": { "express": ">= 2.5.8", - "coco": ">= 0.7.0", + "coco": ">= 0.7.0 < 0.7.6", "coffee-script": ">= 1.2.0", "jade": ">= 0.20.3", "stylus": ">= 0.24.0", From f96dbbe4b573369a649a8372f15c91da3d2eabd5 Mon Sep 17 00:00:00 2001 From: rektide Date: Tue, 24 Jul 2012 09:30:39 -0400 Subject: [PATCH 2/4] Use array splats instead of concatenation, allowing for Coco 0.7.6+ compatibility. --- compiler.co | 4 ++-- compiler.js | 6 ++---- package.co | 2 +- package.json | 2 +- 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/compiler.co b/compiler.co index ed14a96..3a983f4 100644 --- a/compiler.co +++ b/compiler.co @@ -352,11 +352,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 diff --git a/compiler.js b/compiler.js index f34b859..7231a04 100644 --- a/compiler.js +++ b/compiler.js @@ -402,9 +402,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]; @@ -904,4 +902,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 +} diff --git a/package.co b/package.co index e4619b5..ba487cc 100644 --- a/package.co +++ b/package.co @@ -11,7 +11,7 @@ dependencies : # 'seq' : '>= 0.3.5' devDependencies : 'express' : '>= 2.5.8' - 'coco' : '>= 0.7.0 < 0.7.6' + 'coco' : '>= 0.7.0' 'coffee-script' : '>= 1.2.0' 'jade' : '>= 0.20.3' 'stylus' : '>= 0.24.0' diff --git a/package.json b/package.json index 3903308..9b687fd 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ }, "devDependencies": { "express": ">= 2.5.8", - "coco": ">= 0.7.0 < 0.7.6", + "coco": ">= 0.7.0", "coffee-script": ">= 1.2.0", "jade": ">= 0.20.3", "stylus": ">= 0.24.0", From 57ca095a16cb5e58f684a30c4a9f1d612d9e5083 Mon Sep 17 00:00:00 2001 From: rektide Date: Tue, 24 Jul 2012 09:38:06 -0400 Subject: [PATCH 3/4] path.exists is deprecated, now is fs.exists. leave a fallback, but default to using fs. --- compiler.co | 2 +- compiler.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler.co b/compiler.co index 3a983f4..781068b 100644 --- a/compiler.co +++ b/compiler.co @@ -723,7 +723,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 7231a04..61f4764 100644 --- a/compiler.js +++ b/compiler.js @@ -866,7 +866,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); From 206c35b4693f4a91449ccea9d91336fdcb89424b Mon Sep 17 00:00:00 2001 From: rektide Date: Tue, 24 Jul 2012 09:47:35 -0400 Subject: [PATCH 4/4] Dust.js template compiler support. --- compiler.co | 20 ++++++++++++++++++-- compiler.js | 30 ++++++++++++++++++++++++++---- 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/compiler.co b/compiler.co index 781068b..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 @@ -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 diff --git a/compiler.js b/compiler.js index 61f4764..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); @@ -789,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;