Comparing version 0.0.5 to 0.0.6
@@ -9,4 +9,3 @@ | ||
var path = require('path'), | ||
url = require('url'), | ||
index = -1; | ||
url = require('url'); | ||
@@ -23,11 +22,11 @@ // url(../../foo.png) | ||
var getBase = function(base) { | ||
var getBase = function(base, state) { | ||
if (base instanceof Array) { | ||
var length = base.length; | ||
if (index === length - 1) { | ||
index = 0; | ||
if (state.index === length - 1) { | ||
state.index = 0; | ||
} else { | ||
index++; | ||
state.index++; | ||
} | ||
return base[index]; | ||
return base[state.index]; | ||
} else { | ||
@@ -38,3 +37,3 @@ return base; | ||
var normalize = function(options, str, m) { | ||
var normalize = function(options, str, m, state) { | ||
var top, resolved, relative, URI, | ||
@@ -50,3 +49,3 @@ quote, item, baseItem = m[0]; | ||
if (!item.match(/^https?:\/\//) && (item.indexOf('.') > -1)) { | ||
URI = url.parse(getBase(options.base), false, true); | ||
URI = url.parse(getBase(options.base, state), false, true); | ||
top = path.dirname(options.path); | ||
@@ -75,3 +74,6 @@ resolved = path.resolve(top, item); | ||
var items = str.match(REGEX_FIND); | ||
var items = str.match(REGEX_FIND), | ||
state = { | ||
index: -1 | ||
}; | ||
@@ -81,3 +83,3 @@ if (Array.isArray(items)) { | ||
var m = matcher.match(REGEX_PARSE); | ||
str = normalize(options, str, m); | ||
str = normalize(options, str, m, state); | ||
}); | ||
@@ -84,0 +86,0 @@ } |
@@ -5,3 +5,3 @@ { | ||
"author": "Dav Glass <davglass@gmail.com>", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"main": "./lib/index.js", | ||
@@ -8,0 +8,0 @@ "devDependencies": { |
@@ -73,1 +73,2 @@ CSS Relative URL Processor | ||
* `/path/to` for absolute paths where it uses the domain and protocol from the css file that contains the images. | ||
* `['server1.com/path/to', 'server2.com/path/to', etc]` an array of hosts to loop through and alternate in the file. |
@@ -487,2 +487,105 @@ /*jslint maxlen: 500 */ | ||
} | ||
}, | ||
'multiple base with chaining calls': { | ||
topic: function() { | ||
var callback = this.callback, | ||
str = '.yui-test-cssprocessor {\n'; | ||
str += ' background: url(bar.gif);\n'; | ||
str += '};\n'; | ||
str += '.yui-test-cssprocessor2 {\n'; | ||
str += ' background: url(bar.gif);\n'; | ||
str += '};\n'; | ||
cssproc.parse({ | ||
root: '/home/yui/src/', | ||
path: '/home/yui/src/file.css', | ||
base: [ | ||
'https://foobar.com/build/', | ||
'https://barfoo.com/build/' | ||
] | ||
}, str, function (err, firstBlob) { | ||
var str = firstBlob; | ||
str += '.yui-test-cssprocessor {\n'; | ||
str += ' background: url(foo.gif);\n'; | ||
str += '};\n'; | ||
str += '.yui-test-cssprocessor2 {\n'; | ||
str += ' background: url(foo.gif);\n'; | ||
str += '};\n'; | ||
str += '.yui-test-cssprocessor3 {\n'; | ||
str += ' background: url(foo.gif);\n'; | ||
str += '};\n'; | ||
str += '.yui-test-cssprocessor4 {\n'; | ||
str += ' background: url(foo.gif);\n'; | ||
str += '};\n'; | ||
cssproc.parse({ | ||
root: '/home/yui/src/', | ||
path: '/home/yui/src/another.css', | ||
base: [ | ||
'//xyz.com/build/', | ||
'//abc.com/build/' | ||
] | ||
}, str, callback); | ||
}); | ||
}, | ||
'and should not mix the index for multiple domains': function(topic) { | ||
var str = '.yui-test-cssprocessor {\n'; | ||
str += ' background: url(https://foobar.com/build/bar.gif);\n'; | ||
str += '};\n'; | ||
str += '.yui-test-cssprocessor2 {\n'; | ||
str += ' background: url(https://barfoo.com/build/bar.gif);\n'; | ||
str += '};\n'; | ||
str += '.yui-test-cssprocessor {\n'; | ||
str += ' background: url(//xyz.com/build/foo.gif);\n'; | ||
str += '};\n'; | ||
str += '.yui-test-cssprocessor2 {\n'; | ||
str += ' background: url(//abc.com/build/foo.gif);\n'; | ||
str += '};\n'; | ||
str += '.yui-test-cssprocessor3 {\n'; | ||
str += ' background: url(//xyz.com/build/foo.gif);\n'; | ||
str += '};\n'; | ||
str += '.yui-test-cssprocessor4 {\n'; | ||
str += ' background: url(//abc.com/build/foo.gif);\n'; | ||
str += '};\n'; | ||
assert.equal(str, topic); | ||
}, | ||
'and parse another chunk with multi domains': { | ||
topic: function() { | ||
var str = '.yui-test-cssprocessor {\n'; | ||
str += ' background: url(foo.gif);\n'; | ||
str += '};\n'; | ||
str += '.yui-test-cssprocessor2 {\n'; | ||
str += ' background: url(foo.gif);\n'; | ||
str += '};\n'; | ||
str += '.yui-test-cssprocessor3 {\n'; | ||
str += ' background: url(foo.gif);\n'; | ||
str += '};\n'; | ||
str += '.yui-test-cssprocessor4 {\n'; | ||
str += ' background: url(foo.gif);\n'; | ||
str += '};\n'; | ||
cssproc.parse({ | ||
root: '/home/yui/src/', | ||
path: '/home/yui/src/another.css', | ||
base: [ | ||
'//xyz.com/build/', | ||
'//abc.com/build/', | ||
'//asd.com/build/', | ||
'//qwe.com/build/' | ||
] | ||
}, str, this.callback); | ||
}, | ||
'and should restart the index to -1': function(topic) { | ||
var str = '.yui-test-cssprocessor {\n'; | ||
str += ' background: url(//xyz.com/build/foo.gif);\n'; | ||
str += '};\n'; | ||
str += '.yui-test-cssprocessor2 {\n'; | ||
str += ' background: url(//abc.com/build/foo.gif);\n'; | ||
str += '};\n'; | ||
str += '.yui-test-cssprocessor3 {\n'; | ||
str += ' background: url(//asd.com/build/foo.gif);\n'; | ||
str += '};\n'; | ||
str += '.yui-test-cssprocessor4 {\n'; | ||
str += ' background: url(//qwe.com/build/foo.gif);\n'; | ||
str += '};\n'; | ||
assert.equal(str, topic); | ||
} | ||
} | ||
} | ||
@@ -489,0 +592,0 @@ }; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
35360
725
74