Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Support for Jade 1.x #129

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion lib/asset.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions lib/modules/jade.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -84,5 +84,3 @@ class exports.JadeAsset extends Asset
@hasError = true
@emit 'error', error
paths


12 changes: 6 additions & 6 deletions lib/rack.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand All @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion switch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}