diff --git a/README.md b/README.md index dfa79b6..124eb54 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ asset = new rack.Asset({ Need to serve that asset with a blisteringly fast in memory cache using express? ``` -app.use(asset) +app.use(asset.handle) ``` ### Hash for speed and efficiency @@ -205,7 +205,7 @@ assets = rack.fromConfigFile({ configFile: __dirname + '/rack.json', hostname: 'cdn.example.com' }); -app.use(assets); +app.use(assets.handle); ``` And now all of your server side templates will reference your CDN. Also, if you do happen to hit one of your static urls on the server, then you will be redirected to the CDN. diff --git a/lib/asset.coffee b/lib/asset.coffee index 786e765..a0ec680 100644 --- a/lib/asset.coffee +++ b/lib/asset.coffee @@ -159,7 +159,7 @@ class exports.Asset extends EventEmitter url is @specificUrl or (not @hash? and url is @url) # Used so that an asset can be express middleware - handle: (request, response, next) -> + handle: (request, response, next) => handle = => if @assets? for asset in @assets diff --git a/lib/modules/jade.coffee b/lib/modules/jade.coffee index f42a786..31b09b0 100644 --- a/lib/modules/jade.coffee +++ b/lib/modules/jade.coffee @@ -72,7 +72,7 @@ class exports.JadeAsset extends Asset fileContents = fs.readFileSync path, 'utf8' fileContents = @beforeCompile fileContents if @beforeCompile? try - compiled = jade.compile fileContents, + compiled = jade.compileClient fileContents, client: true, compileDebug: false, filename: path @@ -84,5 +84,3 @@ class exports.JadeAsset extends Asset @hasError = true @emit 'error', error paths - - diff --git a/lib/rack.coffee b/lib/rack.coffee index 4cb1b7c..4a21f47 100644 --- a/lib/rack.coffee +++ b/lib/rack.coffee @@ -76,10 +76,10 @@ class exports.Rack extends EventEmitter , (error) => return @emit 'error', error if error? @emit 'complete' - + # Makes the rack function as express middleware - handle: (request, response, next) -> - response.locals assets: this + handle: (request, response, next) => + response.app.locals.assets = this if request.url.slice(0,11) is '/asset-rack' return @handleAdmin request, response, next if @hasError @@ -199,10 +199,10 @@ class ConfigRack # Setup our options @assetMap = require options.configFile @hostname = options.hostname - + # For hooking up as express middleware - handle: (request, response, next) -> - response.locals assets: this + handle: (request, response, next) => + response.app.locals.assets = this for url, specificUrl of @assetMap if request.path is url or request.path is specificUrl diff --git a/package.json b/package.json index 72629eb..6977dc3 100644 --- a/package.json +++ b/package.json @@ -11,12 +11,12 @@ "async": "~0.2.9", "pkgcloud": "~0.8.12", "less": "~1.4.2", - "jade": "~0.35.0", + "jade": "~1.3.1", "mime": "1.2.11", "nib": "~1.0.1", "stylus": "~0.38.0", "underscore": "~1.5.2", - "coffee-script": "~1.6.3", + "coffee-script": "~1.7.1", "markdown": "~0.5.0", "node-sassy": "~0.0.1" }, @@ -27,7 +27,7 @@ "chai": "1.4.2" }, "scripts": { - "test": "./node_modules/mocha/bin/mocha test/test.coffee", + "test": "./node_modules/mocha/bin/mocha --compilers coffee:coffee-script/register test/test.coffee", "compile": "./node_modules/coffee-script/bin/coffee -o compiled/ -c lib/", "prepublish": "echo $(pwd) > /tmp/.pwd; ./node_modules/coffee-script/bin/coffee -o compiled/ -c lib/;", "postpublish": "rm -rf $(cat /tmp/.pwd)/compiled" diff --git a/switch.js b/switch.js index bb2e815..ab2ff8d 100644 --- a/switch.js +++ b/switch.js @@ -3,6 +3,7 @@ try { module.exports = require('./compiled'); } catch(error) { //require('./node_modules/coffee-script'); - require('coffee-script'); + var CoffeeScript = require('coffee-script'); + CoffeeScript.register(); module.exports = require('./lib'); }