Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

middleware src & dest optionally as functions

  • Loading branch information...
commit 934589658c6303813fde5d34f822cbe35953c80a 1 parent 2252437
@adjohnson916 authored
Showing with 15 additions and 6 deletions.
  1. +4 −2 docs/middleware.md
  2. +11 −4 lib/middleware.js
View
6 docs/middleware.md
@@ -10,8 +10,10 @@
#### Options
`force` When __true__ styles will always re-compile
- `src` Source directory used to find .styl files
- `dest` Destination directory used to output .css files
+ `src` Source directory used to find .styl files,
+ a string or function accepting `(path)` of request.
+ `dest` Destination directory used to output .css files,
+ a string or function accepting `(path)` of request,
when undefined defaults to `src`.
`compress` Whether the output .css files should be compressed
`compile` Custom compile function, accepting the arguments
View
15 lib/middleware.js
@@ -29,8 +29,10 @@ var imports = {};
* Options:
*
* `force` Always re-compile
- * `src` Source directory used to find .styl files
- * `dest` Destination directory used to output .css files
+ * `src` Source directory used to find .styl files,
+ * a string or function accepting `(path)` of request.
+ * `dest` Destination directory used to output .css files,
+ * a string or function accepting `(path)` of request,
* when undefined defaults to `src`.
* `compile` Custom compile function, accepting the arguments
* `(str, path)`.
@@ -109,8 +111,13 @@ module.exports = function(options){
if ('GET' != req.method && 'HEAD' != req.method) return next();
var path = url.parse(req.url).pathname;
if (/\.css$/.test(path)) {
- var cssPath = join(dest, path)
- , stylusPath = join(src, path.replace('.css', '.styl'));
+ var cssPath, stylusPath;
+ cssPath = (typeof dest == 'function')
+ ? dest(path)
+ : join(dest, path);
+ stylusPath = (typeof src == 'function')
+ ? src(path)
+ : join(src, path.replace('.css', '.styl'));
// Ignore ENOENT to fall through as 404
function error(err) {
Please sign in to comment.
Something went wrong with that request. Please try again.