Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

refactor at2x

  • Loading branch information...
commit f4c2022fa203b7eba0aaa195c379df183077cb8b 1 parent 91524d1
@tj tj authored
Showing with 15 additions and 10 deletions.
  1. +15 −8 lib/plugins/at2x.js
  2. +0 −2  test/rework.js
View
23 lib/plugins/at2x.js
@@ -29,20 +29,18 @@ var utils = require('../utils')
*/
module.exports = function(vendors) {
- var prefix = function(value) {
+ function prefix(value) {
return '(' + vendors.map(function(vendor) {
return vendor + value;
}).join(' or ') + ')';
- };
+ }
- var visit = function(rules, style, media) {
+ function visit(rules, style, media) {
rules.forEach(function(rule){
if (rule.media) return visit(rule.rules, style, rule.media);
if (!rule.declarations) return;
- rule.declarations.filter(function(decl) {
- return (decl.property == 'background' || decl.property == 'background-image') && ~decl.value.indexOf('url(');
- }).forEach(function(decl){
+ rule.declarations.filter(backgroundWithURL).forEach(function(decl){
// parse url
var i = decl.value.indexOf('url(');
var url = stripQuotes(decl.value.slice(i + 4, decl.value.indexOf(')', i)));
@@ -72,7 +70,16 @@ module.exports = function(vendors) {
return function(style, rework) {
vendors = vendors || rework.prefixes;
-
visit(style.rules, style);
};
-};
+};
+
+/**
+ * Filter background[-image] with url().
+ */
+
+function backgroundWithURL(decl) {
+ return ('background' == decl.property
+ || 'background-image' == decl.property)
+ && ~decl.value.indexOf('url(');
+}
View
2  test/rework.js
@@ -34,9 +34,7 @@ describe('rework', function(){
.toString()
.should.equal(fixture('at2x.out'));
})
- })
- describe('.at2x.complex()', function(){
it('should add vendor prefixed device-pixel-ratio rules', function(){
rework(fixture('at2x-complex'))
.use(rework.at2x(vendors))
Please sign in to comment.
Something went wrong with that request. Please try again.