asset-wrap
Advanced tools
Comparing version 0.1.1 to 0.1.2
{ | ||
"name": "asset-wrap", | ||
"description": "Asset management framework for nodejs", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"author": "Bryant Williams <b.n.williams@gmail.com>", | ||
@@ -12,2 +12,3 @@ "repository": {"type": "git", "url": "git://github.com/scien/asset-wrap.git"}, | ||
"nib": "0.9.1", | ||
"node-uuid": "1.4.0", | ||
"sass": "0.5.0", | ||
@@ -14,0 +15,0 @@ "snockets": "1.3.8", |
148
README.md
Asset-Wrap is a simple asset manager for node. | ||
## Goals | ||
1. build at anytime (server start or on any callback) | ||
2. support stylus, less, and sass to build your css | ||
3. support snockets to build your javascript | ||
1. build at anytime (server start or on any route) | ||
2. support stylus, less, and sass | ||
3. support snockets for coffee-script/coffeecup | ||
4. use async whenever possible | ||
5. support cluster | ||
6. easily extendible (just add another module) | ||
7. TODO: watch for file changes | ||
@@ -19,4 +21,6 @@ ## Install | ||
All assets require at a minimum two parameters | ||
All assets require at a minimum one parameter | ||
* `src`: the path to your source file | ||
Most of the time you'll always want to include the `dst` parameter. It defaults to `src` if not provided | ||
* `dst`: the location to serve your file from (with md5 appended). also the cache key | ||
@@ -36,73 +40,95 @@ | ||
## Examples | ||
### Use as Middleware | ||
### Use as Middleware with ZappaJS | ||
``` | ||
wrap = require 'asset-wrap' | ||
assets = wrap.AssetWrap [ | ||
new wrap.Stylus { | ||
src: "#{__dirname}/path/to/app.styl" | ||
dst: '/css/app.css' | ||
compress: true | ||
} | ||
new wrap.Snockets { | ||
src: "#{__dirname}/path/to/app.coffee" | ||
dst: '/js/app.js' | ||
compress: false | ||
} | ||
] | ||
require('zappajs') -> | ||
wrap = require '../lib/index' | ||
assets = new wrap.Assets [ | ||
new wrap.Snockets { | ||
src: 'assets/hello.coffee' | ||
dst: '/js/hello.js' | ||
compress: true | ||
} | ||
new wrap.Stylus { | ||
src: 'assets/hello.styl' | ||
dst: '/css/hello.css' | ||
compress: true | ||
} | ||
] | ||
@use assets.middleware | ||
assets.on 'complete', () -> | ||
console.log 'assets compiled' | ||
@get '/': -> | ||
@render index: { | ||
assets: assets | ||
} | ||
app.configure () -> | ||
app.use assets.middleware | ||
@view index: -> | ||
head -> | ||
text @assets.tag '/css/hello.css' | ||
text @assets.tag '/js/hello.js' | ||
body -> | ||
a href: @assets.url '/css/hello.css', -> | ||
'View CSS' | ||
pre -> | ||
@assets.data '/css/hello.css' | ||
a href: @assets.url '/js/hello.js', -> | ||
'View Javascript' | ||
pre -> | ||
@assets.data '/js/hello.js' | ||
``` | ||
@get '/': -> | ||
@render index: { | ||
assets: assets | ||
} | ||
@view index: -> | ||
head -> | ||
@assets.tag '/css/app.css' | ||
@assets.tag '/js/app.js' | ||
### Generate Asset Dynamically | ||
``` | ||
require('zappajs') -> | ||
wrap = require '../lib/index' | ||
### Single Asset Dynamically | ||
@get '/': -> | ||
new wrap.Snockets { | ||
src: 'assets/hello.coffee' | ||
dst: '/js/hello.js' | ||
compress: true | ||
}, (asset) => | ||
@response.setHeader 'ContentType', asset.type | ||
@response.send asset.data | ||
``` | ||
wrap = require '../src/wrap' | ||
asset = new wrap.Snockets { | ||
src: "#{__dirname}/test.coffee" | ||
dst: '/js/app.js' | ||
} | ||
asset.on 'complete', () -> | ||
console.log asset.url | ||
asset.wrap() | ||
``` | ||
### Single Asset Dynamically Shortcut | ||
### Generate Asset Dynamically With Cluster | ||
``` | ||
asset = new wrap.Snockets { | ||
src: "#{__dirname}/test.coffee" | ||
dst: '/js/app.js' | ||
}, (asset) -> | ||
console.log asset.url | ||
``` | ||
cluster = require 'cluster' | ||
os = require 'os' | ||
### Wrap Single Asset with Zappa | ||
if cluster.isMaster | ||
# Fork workers | ||
cluster.fork() for i in os.cpus() | ||
cluster.on 'exit', (worker, code, signal) -> | ||
console.log "worker #{worker.process.pid} died" | ||
else | ||
# Workers can share any TCP connection | ||
require('zappajs') -> | ||
wrap = require '../lib/index' | ||
@get '/js/hello.js': -> | ||
new wrap.Snockets { | ||
src: 'assets/hello.coffee' | ||
dst: '/js/hello.js' | ||
compress: true | ||
}, (asset) => | ||
@response.setHeader 'ContentType', asset.type | ||
@response.send asset.data | ||
@get '/': -> | ||
@render 'index': {layout: no} | ||
@view index: -> | ||
body -> | ||
div -> | ||
a href: '/js/hello.js', -> | ||
'View Javascript' | ||
``` | ||
@get '/js/app.js': -> | ||
new wrap.Snockets { | ||
url: '/js/app.js' | ||
src: "#{__dirname}/path/to/app.coffee" | ||
}, (asset) => | ||
@response.setHeader 'Content-Type', 'text/javascript' | ||
@response.write asset.data | ||
``` | ||
# Credit | ||
Much inspiration from the other asset management tools out there. | ||
* Brad Carleton's asset-rack | ||
* Trevor Burnham's connect-assets | ||
* the Rails Asset Pipeline | ||
* Mathias Pettersson's connect-assetmanager | ||
* Brad Carleton's [asset-rack](https://github.com/techpines/asset-rack) | ||
* Trevor Burnham's [connect-assets](https://github.com/TrevorBurnham/connect-assets) | ||
* the [Rails Asset Pipeline](http://guides.rubyonrails.org/asset_pipeline.html) | ||
* Mathias Pettersson's [connect-assetmanager](https://github.com/mape/connect-assetmanager) | ||
@@ -109,0 +135,0 @@ # License |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
18549
30
141
8
+ Addednode-uuid@1.4.0
+ Addednode-uuid@1.4.0(transitive)