Permalink
Browse files

upgrades, enhancements, and fixes

- upgrade autoprefixer to v1.0.x
- autoprefixer bails when fed any arg but a string,
  now this plugin guards against this
- better tests and test structure
- tested with the latest version of stylus
  • Loading branch information...
1 parent 06a3453 commit df3d5a7b09ea763f6895f848ca3b349199e4e3d5 Jeff Escalante committed Feb 18, 2014
View
@@ -1,13 +1,29 @@
-var autoprefixer = require('autoprefixer');
+var ap = require('autoprefixer');
+
+/**
+ * Returns a stylus function that autoprefixes css.
+ *
+ * - Grabs any arguments passed, filters down to only string
+ * args, as anything other than a string crashes autoprefixer
+ * - Returns a function for stylus to use
+ * - This function uses the `end` event, and runs autoprefixer on
+ * the css, applying any arguments if present
+ *
+ * @return {Function} - stylus plugin function
+ */
module.exports = function() {
var args = Array.prototype.slice.call(arguments);
+ args = args.filter(function(i){ return typeof i === 'string' });
return function(style){
- this.on('end', function(err, css){
- if (args) return autoprefixer.apply(this, args).compile(css);
- autoprefixer.compile(css);
+ style = this || style;
+
+ style.on('end', function(err, css){
+ if (args.length) { return ap.apply(ap, args).process(css).css; }
+ return ap.process(css).css;
});
+
}
}
View
@@ -11,7 +11,8 @@
"mocha": "*",
"should": "*",
"stylus": "*",
- "coffee-script": "*"
+ "coffee-script": "*",
+ "css-parse": "~1.7.0"
},
"author": "Jeff Escalante",
"main": "index.js",
@@ -22,6 +23,6 @@
"node": ">=0.8.0"
},
"dependencies": {
- "autoprefixer": "0.8.x"
+ "autoprefixer": "1.0.x"
}
}
@@ -1,4 +1,4 @@
p {
-webkit-transition: all 1s ease;
transition: all 1s ease;
-}
+}
File renamed without changes.
@@ -1,3 +1,3 @@
p {
transition: all 1s ease;
-}
+}
@@ -0,0 +1,2 @@
+p
+ transition: all 1s ease
View
@@ -1,2 +1,2 @@
--reporter spec
---compilers coffee:coffee-script
+--compilers coffee:coffee-script/register
View
@@ -3,21 +3,25 @@ fs = require 'fs'
path = require 'path'
autoprefixer = require '../index'
stylus = require 'stylus'
+parse = require 'css-parse'
+test_path = path.join(__dirname, 'fixtures')
+
+match_expected = (file, args, done) ->
+ stylus(fs.readFileSync(path.join(test_path, file), 'utf8'))
+ .use(autoprefixer.apply(autoprefixer, args))
+ .render (err, css) ->
+ if err then return done(err)
+ expected = fs.readFileSync(path.join(test_path, file.replace('.styl', '.css')), 'utf8')
+ parse(css).should.eql(parse(expected))
+ done()
describe 'basic', ->
- it 'works', (done) ->
- contents = fs.readFileSync(path.join(__dirname, 'basic/example.styl'), 'utf8')
- expected = fs.readFileSync(path.join(__dirname, 'basic/expected.css'), 'utf8')
+ it "works", (done) ->
+ match_expected('basic.styl', null, done)
- stylus(contents).use(autoprefixer()).render (err, out) =>
- should.equal(out, expected)
- done()
+ it "doesn't bail when given whack arguments", (done) ->
+ match_expected('basic.styl', [{}], done)
- it 'takes browser options', (done) ->
- contents = fs.readFileSync(path.join(__dirname, 'basic/example.styl'), 'utf8')
- expected = fs.readFileSync(path.join(__dirname, 'basic/expected2.css'), 'utf8')
-
- stylus(contents).use(autoprefixer('ie 7', 'ie 8')).render (err, out) =>
- should.equal(out, expected)
- done()
+ it "takes browser options", (done) ->
+ match_expected('browser.styl', ['ie 7', 'ie 8'], done)

0 comments on commit df3d5a7

Please sign in to comment.