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

Update README.md to use syntax highlighting. #58

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
175 changes: 93 additions & 82 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,44 +89,52 @@ The type of data you are trying to optimize, 'javascript' and 'css' is built int
There are hooks in the assetManager that allow you to programmaticly alter the source of the files you are grouping.
This can be handy for being able to use custom CSS types in the assetManager or fixing stuff like vendor prefixes in a general fashion.

'preManipulate': {
// Regexp to match user-agents including MSIE.
'MSIE': [
generalManipulation
, msieSpecificManipulation
],
// Matches all (regex start line)
'^': [
generalManipulation
, fixVendorPrefixes
, fixGradients
, replaceImageRefToBase64
]
}
```js
'preManipulate': {
// Regexp to match user-agents including MSIE.
'MSIE': [
generalManipulation
, msieSpecificManipulation
],
// Matches all (regex start line)
'^': [
generalManipulation
, fixVendorPrefixes
, fixGradients
, replaceImageRefToBase64
]
}
```

### postManipulate (array containing functions)
Same as preManipulate but runs after the files are merged and minified.

The functions supplied look like this:

function (file, path, index, isLast, callback) {
if (path.match(/filename\.js/)) {
callback(null, file.replace(/string/mig, 'replaceWithThis'));
} else {
callback(null, file);
}
```js
function (file, path, index, isLast, callback) {
if (path.match(/filename\.js/)) {
callback(null, file.replace(/string/mig, 'replaceWithThis'));
} else {
callback(null, file);
}
}
```

### serveModify (req, res, response, callback)
Allows you do to modify the cached response on a per request basis.

function(req, res, response, callback) {
if (externalVariable) {
// Return empty asset
response.length = 1;
response.contentBuffer = new Buffer(' ');
}
callback(response);
```js
function(req, res, response, callback) {
if (externalVariable) {
// Return empty asset
response.length = 1;
response.contentBuffer = new Buffer(' ');
}
callback(response);
}
```

### stale (boolean)
Incase you want to use the asset manager with optimal performance you can set stale to true.

Expand All @@ -136,60 +144,63 @@ This means that there are no checks for file changes and the cache will therefor
When debug is set to true the files will not be minified, but they will be grouped into one file and modified.

## Example usage
var sys = require('sys');
var fs = require('fs');
var Connect = require('connect');
var assetManager = require('connect-assetmanager');
var assetHandler = require('connect-assetmanager-handlers');

var root = __dirname + '/public';


var Server = module.exports = Connect.createServer();

Server.use('/',
Connect.responseTime()
, Connect.logger()
);

var assetManagerGroups = {
'js': {
'route': /\/static\/js\/[0-9]+\/.*\.js/
, 'path': './public/js/'
, 'dataType': 'javascript'
, 'files': [
'jquery.js'
, 'jquery.client.js'
]
}, 'css': {
'route': /\/static\/css\/[0-9]+\/.*\.css/
, 'path': './public/css/'
, 'dataType': 'css'
, 'files': [
'reset.css'
, 'style.css'

```js
var sys = require('sys');
var fs = require('fs');
var Connect = require('connect');
var assetManager = require('connect-assetmanager');
var assetHandler = require('connect-assetmanager-handlers');

var root = __dirname + '/public';


var Server = module.exports = Connect.createServer();

Server.use('/',
Connect.responseTime()
, Connect.logger()
);

var assetManagerGroups = {
'js': {
'route': /\/static\/js\/[0-9]+\/.*\.js/
, 'path': './public/js/'
, 'dataType': 'javascript'
, 'files': [
'jquery.js'
, 'jquery.client.js'
]
}, 'css': {
'route': /\/static\/css\/[0-9]+\/.*\.css/
, 'path': './public/css/'
, 'dataType': 'css'
, 'files': [
'reset.css'
, 'style.css'
]
, 'preManipulate': {
// Regexp to match user-agents including MSIE.
'MSIE': [
assetHandler.yuiCssOptimize
, assetHandler.fixVendorPrefixes
, assetHandler.fixGradients
, assetHandler.stripDataUrlsPrefix
],
// Matches all (regex start line)
'^': [
assetHandler.yuiCssOptimize
, assetHandler.fixVendorPrefixes
, assetHandler.fixGradients
, assetHandler.replaceImageRefToBase64(root)
]
, 'preManipulate': {
// Regexp to match user-agents including MSIE.
'MSIE': [
assetHandler.yuiCssOptimize
, assetHandler.fixVendorPrefixes
, assetHandler.fixGradients
, assetHandler.stripDataUrlsPrefix
],
// Matches all (regex start line)
'^': [
assetHandler.yuiCssOptimize
, assetHandler.fixVendorPrefixes
, assetHandler.fixGradients
, assetHandler.replaceImageRefToBase64(root)
]
}
}
};

var assetsManagerMiddleware = assetManager(assetManagerGroups);
Server.use('/'
, assetsManagerMiddleware
, Connect.static(root)
);
}
};

var assetsManagerMiddleware = assetManager(assetManagerGroups);
Server.use('/'
, assetsManagerMiddleware
, Connect.static(root)
);
```