diff --git a/dist/package/lib/css-url-versioner.js b/dist/package/lib/css-url-versioner.js index 0d26036..9824716 100644 --- a/dist/package/lib/css-url-versioner.js +++ b/dist/package/lib/css-url-versioner.js @@ -158,7 +158,7 @@ CssUrlVersioner.prototype.getTheLastPart = function(quote, numeral, singleQuote, CssUrlVersioner.prototype.insertVersion = function() { var arrayUrl, dot, doubleQuotes, extension, i, len, newRegEx, newString, numeral, patternExt, patternQuotes, patternRightBracket, patternSimbols, patternUrl, quote, singleQuote, theLastPartOfTheRegExp, url; - patternUrl = /url([\(]{1})([\"|\']?)([a-zA-Z0-9\@\.\/_-]+)([\#]?[a-zA-Z0-9_-]+)?([\"|\']?)([\)]{1})/g; + patternUrl = /url([\(]{1})([\"|\']?)([a-zA-Z0-9\@\.\/\s_-]+)([\#]?[a-zA-Z0-9_-]+)?([\"|\']?)([\)]{1})/g; patternQuotes = /(\"|\')/g; patternExt = /(\.{1}[a-zA-Z0-9]{2,4})(\"|\')?/g; patternSimbols = /([\#]{1})/g; diff --git a/dist/package/lib/execute.js b/dist/package/lib/execute.js index 62e013a..70def79 100644 --- a/dist/package/lib/execute.js +++ b/dist/package/lib/execute.js @@ -55,15 +55,15 @@ Execute.prototype.readFile = function() { }; Execute.prototype.validateFlag = function(flag) { - var e; + var e, error; if (flag) { try { this.output = fs.readFileSync(this.pathOutput, { encoding: 'utf8' }).toString().replace(/\n/gi, ''); return true; - } catch (_error) { - e = _error; + } catch (error) { + e = error; } } else { return false; @@ -71,12 +71,12 @@ Execute.prototype.validateFlag = function(flag) { }; Execute.prototype.reset = function() { - var e; + var e, error; try { rimraf(this.pathDone, function() {}); rimraf(this.pathOutput, function() {}); - } catch (_error) { - e = _error; + } catch (error) { + e = error; console.log(e); } this.attempts = 0; diff --git a/package.json b/package.json index 72afe63..c7b7908 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "css-url-versioner", - "version": "1.1.1", + "version": "1.1.2", "description": "A node package for css url versioner", "main": "dist/package/index", "scripts": { diff --git a/source/coffee/package/lib/css-url-versioner.coffee b/source/coffee/package/lib/css-url-versioner.coffee index c47a663..8849673 100644 --- a/source/coffee/package/lib/css-url-versioner.coffee +++ b/source/coffee/package/lib/css-url-versioner.coffee @@ -152,7 +152,7 @@ CssUrlVersioner::getTheLastPart = (quote, numeral, singleQuote, doubleQuotes, pa CssUrlVersioner::insertVersion = () -> - patternUrl = /url([\(]{1})([\"|\']?)([a-zA-Z0-9\@\.\/_-]+)([\#]?[a-zA-Z0-9_-]+)?([\"|\']?)([\)]{1})/g + patternUrl = /url([\(]{1})([\"|\']?)([a-zA-Z0-9\@\.\/\s_-]+)([\#]?[a-zA-Z0-9_-]+)?([\"|\']?)([\)]{1})/g patternQuotes = /(\"|\')/g patternExt = /(\.{1}[a-zA-Z0-9]{2,4})(\"|\')?/g patternSimbols = /([\#]{1})/g diff --git a/source/coffee/test/lib/css-url-versioner.coffee b/source/coffee/test/lib/css-url-versioner.coffee index b6215d3..1262991 100644 --- a/source/coffee/test/lib/css-url-versioner.coffee +++ b/source/coffee/test/lib/css-url-versioner.coffee @@ -77,200 +77,72 @@ describe('cssUrl', () -> ) return ) - + + assertVersioned = (arr, indx) -> + return () -> + instance = cssVersioner({ + content: arr[indx] + }) + + it(arr[indx] + ' should be convert to: ' + arr[indx + 1] + '.', () -> + instance.output.should.be.equal(arr[indx + 1]) + ) describe('Generated versions', () -> queryString = '?v=' + version - withoutQuotes = ['url(sprite.png)', 'url(sprite.png' + queryString + ')', - 'url(fonts/new.eot#ie)', 'url(fonts/new.eot' + queryString + '#ie)', - 'url(img/abc.dfg.png)', 'url(img/abc.dfg.png' + queryString + ')', - 'url(img/klm.nop.png#slug)', 'url(img/klm.nop.png' + queryString + '#slug)'] + withoutQuotes = [ + 'url(sprite.png)', 'url(sprite.png' + queryString + ')', + 'url(fonts/new.eot#ie)', 'url(fonts/new.eot' + queryString + '#ie)', + 'url(img/abc.dfg.png)', 'url(img/abc.dfg.png' + queryString + ')', + 'url(img/klm.nop.png#slug)', 'url(img/klm.nop.png' + queryString + '#slug)', + 'url(file with space.woff)', 'url(file with space.woff' + queryString + ')' + ] describe('Without quotes:', () -> - describe(withoutQuotes[0], () -> - - instance = cssVersioner({ - content: withoutQuotes[0] - }) - - it(withoutQuotes[0] + ' should be convert to: ' + withoutQuotes[1] + '.', () -> - instance.output.should.be.equal(withoutQuotes[1]) - return - ) - return - ) + for i in [0..withoutQuotes.length / 2 - 1] - describe(withoutQuotes[2], () -> - - instance = cssVersioner({ - content: withoutQuotes[2] - }) - - it(withoutQuotes[2] + ' should be convert to: ' + withoutQuotes[3] + '.', () -> - instance.output.should.be.equal(withoutQuotes[3]) - return - ) - return - ) - - describe(withoutQuotes[4], () -> - - instance = cssVersioner({ - content: withoutQuotes[4] - }) - - it(withoutQuotes[4] + ' should be convert to: ' + withoutQuotes[5] + '.', () -> - instance.output.should.be.equal(withoutQuotes[5]) - return - ) - return - ) - - describe(withoutQuotes[6], () -> - - instance = cssVersioner({ - content: withoutQuotes[6] - }) - - it(withoutQuotes[6] + ' should be convert to: ' + withoutQuotes[7] + '.', () -> - instance.output.should.be.equal(withoutQuotes[7]) - return - ) - return - ) + describe(withoutQuotes[i * 2], assertVersioned(withoutQuotes, i * 2)) return ) - withSingleQuotes = ["url('sprite.png')", "url('sprite.png" + queryString + "')", - "url('fonts/new.eot#ie')", "url('fonts/new.eot" + queryString + "#ie')", - "url('img/abc.dfg.png')", "url('img/abc.dfg.png" + queryString + "')", - "url('img/klm.nop.png#slug')", "url('img/klm.nop.png" + queryString + "#slug')"] + withSingleQuotes = [ + "url('sprite.png')", "url('sprite.png" + queryString + "')", + "url('fonts/new.eot#ie')", "url('fonts/new.eot" + queryString + "#ie')", + "url('img/abc.dfg.png')", "url('img/abc.dfg.png" + queryString + "')", + "url('img/klm.nop.png#slug')", "url('img/klm.nop.png" + queryString + "#slug')", + "url('file with space.woff')", "url('file with space.woff" + queryString + "')" + ] describe("With single quotes: '", () -> - describe(withSingleQuotes[0], () -> - - instance = cssVersioner({ - content: withSingleQuotes[0] - }) - - it(withSingleQuotes[0] + ' should be convert to: ' + withSingleQuotes[1] + '.', () -> - instance.output.should.be.equal(withSingleQuotes[1]) - return - ) - return - ) - - describe(withSingleQuotes[2], () -> - - instance = cssVersioner({ - content: withSingleQuotes[2] - }) - - it(withSingleQuotes[2] + ' should be convert to: ' + withSingleQuotes[3] + '.', () -> - instance.output.should.be.equal(withSingleQuotes[3]) - return - ) - return - ) - - describe(withSingleQuotes[4], () -> - - instance = cssVersioner({ - content: withSingleQuotes[4] - }) - - it(withSingleQuotes[4] + ' should be convert to: ' + withSingleQuotes[5] + '.', () -> - instance.output.should.be.equal(withSingleQuotes[5]) - return - ) - return - ) + for i in [0..withSingleQuotes.length / 2 - 1] - describe(withSingleQuotes[6], () -> - - instance = cssVersioner({ - content: withSingleQuotes[6] - }) - - it(withSingleQuotes[6] + ' should be convert to: ' + withSingleQuotes[7] + '.', () -> - instance.output.should.be.equal(withSingleQuotes[7]) - return - ) - return - ) + describe(withSingleQuotes[i * 2], assertVersioned(withSingleQuotes, i * 2)) return ) - withDoubleQuotes = ['url("sprite.png")', 'url("sprite.png' + queryString + '")', - 'url("fonts/new.eot#ie")', 'url("fonts/new.eot' + queryString + '#ie")', - 'url("img/abc.dfg.png")', 'url("img/abc.dfg.png' + queryString + '")', - 'url("img/klm.nop.png#slug")', 'url("img/klm.nop.png' + queryString + '#slug")'] - - - describe('With double quotes: "', () -> + withDoubleQuotes = [ + 'url("sprite.png")', 'url("sprite.png' + queryString + '")', + 'url("fonts/new.eot#ie")', 'url("fonts/new.eot' + queryString + '#ie")', + 'url("img/abc.dfg.png")', 'url("img/abc.dfg.png' + queryString + '")', + 'url("img/klm.nop.png#slug")', 'url("img/klm.nop.png' + queryString + '#slug")', + 'url("file with space.woff")', 'url("file with space.woff' + queryString + '")' + ] - describe(withDoubleQuotes[0], () -> - - instance = cssVersioner({ - content: withDoubleQuotes[0] - }) - - it(withDoubleQuotes[0] + ' should be convert to: ' + withDoubleQuotes[1] + '.', () -> - instance.output.should.be.equal(withDoubleQuotes[1]) - return - ) - return - ) - - describe(withDoubleQuotes[2], () -> - - instance = cssVersioner({ - content: withDoubleQuotes[2] - }) - - it(withDoubleQuotes[2] + ' should be convert to: ' + withDoubleQuotes[3] + '.', () -> - instance.output.should.be.equal(withDoubleQuotes[3]) - return - ) - return - ) - - describe(withDoubleQuotes[4], () -> - - instance = cssVersioner({ - content: withDoubleQuotes[4] - }) - - it(withDoubleQuotes[4] + ' should be convert to: ' + withDoubleQuotes[5] + '.', () -> - instance.output.should.be.equal(withDoubleQuotes[5]) - return - ) - return - ) - - describe(withDoubleQuotes[6], () -> + describe('With double quotes: "', () -> - instance = cssVersioner({ - content: withDoubleQuotes[6] - }) + for i in [0..withDoubleQuotes.length / 2 - 1] - it(withDoubleQuotes[6] + ' should be convert to: ' + withDoubleQuotes[7] + '.', () -> - instance.output.should.be.equal(withDoubleQuotes[7]) - return - ) - return - ) + describe(withDoubleQuotes[i * 2], assertVersioned(withDoubleQuotes, i * 2)) return ) - return ) diff --git a/test/lib/css-url-versioner.js b/test/lib/css-url-versioner.js index ffd051d..0e991e8 100644 --- a/test/lib/css-url-versioner.js +++ b/test/lib/css-url-versioner.js @@ -22,7 +22,7 @@ mainInstance = cssVersioner({ }); describe('cssUrl', function() { - var options; + var assertVersioned, options; options = {}; beforeEach(function() {}); describe('Extend', function() { @@ -62,125 +62,40 @@ describe('cssUrl', function() { mainInstance.queryString.should.be.equal(queryString); }); }); + assertVersioned = function(arr, indx) { + return function() { + var instance; + instance = cssVersioner({ + content: arr[indx] + }); + return it(arr[indx] + ' should be convert to: ' + arr[indx + 1] + '.', function() { + return instance.output.should.be.equal(arr[indx + 1]); + }); + }; + }; describe('Generated versions', function() { var queryString, withDoubleQuotes, withSingleQuotes, withoutQuotes; queryString = '?v=' + version; - withoutQuotes = ['url(sprite.png)', 'url(sprite.png' + queryString + ')', 'url(fonts/new.eot#ie)', 'url(fonts/new.eot' + queryString + '#ie)', 'url(img/abc.dfg.png)', 'url(img/abc.dfg.png' + queryString + ')', 'url(img/klm.nop.png#slug)', 'url(img/klm.nop.png' + queryString + '#slug)']; + withoutQuotes = ['url(sprite.png)', 'url(sprite.png' + queryString + ')', 'url(fonts/new.eot#ie)', 'url(fonts/new.eot' + queryString + '#ie)', 'url(img/abc.dfg.png)', 'url(img/abc.dfg.png' + queryString + ')', 'url(img/klm.nop.png#slug)', 'url(img/klm.nop.png' + queryString + '#slug)', 'url(file with space.woff)', 'url(file with space.woff' + queryString + ')']; describe('Without quotes:', function() { - describe(withoutQuotes[0], function() { - var instance; - instance = cssVersioner({ - content: withoutQuotes[0] - }); - it(withoutQuotes[0] + ' should be convert to: ' + withoutQuotes[1] + '.', function() { - instance.output.should.be.equal(withoutQuotes[1]); - }); - }); - describe(withoutQuotes[2], function() { - var instance; - instance = cssVersioner({ - content: withoutQuotes[2] - }); - it(withoutQuotes[2] + ' should be convert to: ' + withoutQuotes[3] + '.', function() { - instance.output.should.be.equal(withoutQuotes[3]); - }); - }); - describe(withoutQuotes[4], function() { - var instance; - instance = cssVersioner({ - content: withoutQuotes[4] - }); - it(withoutQuotes[4] + ' should be convert to: ' + withoutQuotes[5] + '.', function() { - instance.output.should.be.equal(withoutQuotes[5]); - }); - }); - describe(withoutQuotes[6], function() { - var instance; - instance = cssVersioner({ - content: withoutQuotes[6] - }); - it(withoutQuotes[6] + ' should be convert to: ' + withoutQuotes[7] + '.', function() { - instance.output.should.be.equal(withoutQuotes[7]); - }); - }); + var i, j, ref; + for (i = j = 0, ref = withoutQuotes.length / 2 - 1; 0 <= ref ? j <= ref : j >= ref; i = 0 <= ref ? ++j : --j) { + describe(withoutQuotes[i * 2], assertVersioned(withoutQuotes, i * 2)); + } }); - withSingleQuotes = ["url('sprite.png')", "url('sprite.png" + queryString + "')", "url('fonts/new.eot#ie')", "url('fonts/new.eot" + queryString + "#ie')", "url('img/abc.dfg.png')", "url('img/abc.dfg.png" + queryString + "')", "url('img/klm.nop.png#slug')", "url('img/klm.nop.png" + queryString + "#slug')"]; + withSingleQuotes = ["url('sprite.png')", "url('sprite.png" + queryString + "')", "url('fonts/new.eot#ie')", "url('fonts/new.eot" + queryString + "#ie')", "url('img/abc.dfg.png')", "url('img/abc.dfg.png" + queryString + "')", "url('img/klm.nop.png#slug')", "url('img/klm.nop.png" + queryString + "#slug')", "url('file with space.woff')", "url('file with space.woff" + queryString + "')"]; describe("With single quotes: '", function() { - describe(withSingleQuotes[0], function() { - var instance; - instance = cssVersioner({ - content: withSingleQuotes[0] - }); - it(withSingleQuotes[0] + ' should be convert to: ' + withSingleQuotes[1] + '.', function() { - instance.output.should.be.equal(withSingleQuotes[1]); - }); - }); - describe(withSingleQuotes[2], function() { - var instance; - instance = cssVersioner({ - content: withSingleQuotes[2] - }); - it(withSingleQuotes[2] + ' should be convert to: ' + withSingleQuotes[3] + '.', function() { - instance.output.should.be.equal(withSingleQuotes[3]); - }); - }); - describe(withSingleQuotes[4], function() { - var instance; - instance = cssVersioner({ - content: withSingleQuotes[4] - }); - it(withSingleQuotes[4] + ' should be convert to: ' + withSingleQuotes[5] + '.', function() { - instance.output.should.be.equal(withSingleQuotes[5]); - }); - }); - describe(withSingleQuotes[6], function() { - var instance; - instance = cssVersioner({ - content: withSingleQuotes[6] - }); - it(withSingleQuotes[6] + ' should be convert to: ' + withSingleQuotes[7] + '.', function() { - instance.output.should.be.equal(withSingleQuotes[7]); - }); - }); + var i, j, ref; + for (i = j = 0, ref = withSingleQuotes.length / 2 - 1; 0 <= ref ? j <= ref : j >= ref; i = 0 <= ref ? ++j : --j) { + describe(withSingleQuotes[i * 2], assertVersioned(withSingleQuotes, i * 2)); + } }); - withDoubleQuotes = ['url("sprite.png")', 'url("sprite.png' + queryString + '")', 'url("fonts/new.eot#ie")', 'url("fonts/new.eot' + queryString + '#ie")', 'url("img/abc.dfg.png")', 'url("img/abc.dfg.png' + queryString + '")', 'url("img/klm.nop.png#slug")', 'url("img/klm.nop.png' + queryString + '#slug")']; + withDoubleQuotes = ['url("sprite.png")', 'url("sprite.png' + queryString + '")', 'url("fonts/new.eot#ie")', 'url("fonts/new.eot' + queryString + '#ie")', 'url("img/abc.dfg.png")', 'url("img/abc.dfg.png' + queryString + '")', 'url("img/klm.nop.png#slug")', 'url("img/klm.nop.png' + queryString + '#slug")', 'url("file with space.woff")', 'url("file with space.woff' + queryString + '")']; describe('With double quotes: "', function() { - describe(withDoubleQuotes[0], function() { - var instance; - instance = cssVersioner({ - content: withDoubleQuotes[0] - }); - it(withDoubleQuotes[0] + ' should be convert to: ' + withDoubleQuotes[1] + '.', function() { - instance.output.should.be.equal(withDoubleQuotes[1]); - }); - }); - describe(withDoubleQuotes[2], function() { - var instance; - instance = cssVersioner({ - content: withDoubleQuotes[2] - }); - it(withDoubleQuotes[2] + ' should be convert to: ' + withDoubleQuotes[3] + '.', function() { - instance.output.should.be.equal(withDoubleQuotes[3]); - }); - }); - describe(withDoubleQuotes[4], function() { - var instance; - instance = cssVersioner({ - content: withDoubleQuotes[4] - }); - it(withDoubleQuotes[4] + ' should be convert to: ' + withDoubleQuotes[5] + '.', function() { - instance.output.should.be.equal(withDoubleQuotes[5]); - }); - }); - describe(withDoubleQuotes[6], function() { - var instance; - instance = cssVersioner({ - content: withDoubleQuotes[6] - }); - it(withDoubleQuotes[6] + ' should be convert to: ' + withDoubleQuotes[7] + '.', function() { - instance.output.should.be.equal(withDoubleQuotes[7]); - }); - }); + var i, j, ref; + for (i = j = 0, ref = withDoubleQuotes.length / 2 - 1; 0 <= ref ? j <= ref : j >= ref; i = 0 <= ref ? ++j : --j) { + describe(withDoubleQuotes[i * 2], assertVersioned(withDoubleQuotes, i * 2)); + } }); }); });