Skip to content

Commit

Permalink
Added filename support to filter function so stylus imports can work
Browse files Browse the repository at this point in the history
  • Loading branch information
Qard committed May 10, 2012
1 parent ae8674b commit 8761a9c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
19 changes: 17 additions & 2 deletions lib/index.js
Expand Up @@ -131,8 +131,9 @@ Crsh.stylus = function () {
var self = this;
this.addType('css', 'styl')

return function (file, next) {
return function (file, filename, next) {
stylus(file)
.set('filename', filename)
.set('paths', self.path)
.set('compress', isProd)
.set('filename', 'style.styl')
Expand Down Expand Up @@ -274,6 +275,7 @@ Crsh.prototype.remove = function (f) {
return this
}


/**
* Applies input filters to file map
*/
Expand All @@ -284,11 +286,23 @@ Crsh.prototype.applyInputFilters = function (files, cb) {
var filters = this.list.map(function (file) {
var fn = self.findFilter(path.extname(file))
return function (next) {
// Convert buffers to strings
files[file] = files[file].toString()
fn(files[file], function (err, data) {

// Create dynamic arg list
var args = [files[file]]

// Add filename, if callback accepts it
(fn.length === 3) && args.push(file)

// Add receiver function
args.push(function (err, data) {
err || (files[file] = data)
next(err)
})

// Execute
fn.apply(null, args)
}
})

Expand All @@ -313,6 +327,7 @@ Crsh.prototype.compile = function (cb) {
Files.load(list, function (err, files) {
if (err) cb(err)

// Run through matching input filters
self.applyInputFilters(files, function (err, filteredFiles) {
if (err) { return cb(err) }

Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -2,7 +2,7 @@
"author": "Stephen Belanger <admin@stephenbelanger.com> (http://stephenbelanger.com)",
"name": "crsh",
"description": "crsh your javascript and css into tiny blocks.",
"version": "0.2.1",
"version": "0.2.3",
"repository": {
"url": "git://github.com/Qard/crsh.git"
},
Expand Down

0 comments on commit 8761a9c

Please sign in to comment.