Snippets Groups Projects
Commit a077fc8d authored by Jeffrey Johnson's avatar Jeffrey Johnson
Browse files

Merge pull request #1104 from cspanring/fix-grunt-replace

fixes regex in replace grunt task
parents 6600ed0e e725bc81
No related merge requests found
......@@ -121,23 +121,38 @@ module.exports = function(grunt) {
}
},
// replace image paths in CSS to match lib/img/
/*!
* change image paths in CSS to match url('../lib/img/image.png')
* regex should cover following url patterns:
* /url\("?images\//g url("images/animated-overlay.gif")
* url(images/ui-bg_flat_75_ffffff_40x100.png)
* /url\('(?!(images|\.))/g url('select2.png')
* url('spinner.gif')
* /url\((?!('|"))/g url(select2x2.png)
* must not change url('../img/switch.png')
* /url\('\.\.\/images\//g url('../images/back_enabled.png')
* must not change alpha(opacity=25)
*
* TODO: write testcase
* var urls = ['url("images/animated-overlay.gif")', 'url(images/ui-bg_flat_75_ffffff_40x100.png)', "url('select2.png')", "url('spinner.gif')", "url(select2x2.png)", "url('../img/switch.png')", "url('../images/back_enabled.png')", "alpha(opacity=25)"],
* urlsClean = [];
* urls.forEach(function(elem) {
* var urlClean = elem.replace(/url\((("?images\/)|('(?!(images|\.)))|(?!('|"))|('\.\.\/images\/))/g, 'url(\'../img/').replace(/(png|gif|jpg)?(\)|'\)|"\))/g, '$1\')');
* urlsClean.push(urlClean);
* });
* console.log(urlsClean);
*/
replace: {
development: {
src: ['lib/css/*.css'],
overwrite: true,
replacements: [{
from: /url\('(?!\.)/g,
from: /url\((("?images\/)|('(?!(images|\.)))|(?!('|"))|('\.\.\/images\/))/g,
to: 'url(\'../img/'
}, {
from: /url\((?!\')/g,
to: 'url(\'../img/'
}, {
from: /..\/images\//g,
to: '../img/'
}, {
from: /(png|gif|jpg)(?=\))/g,
to: '$1\''
from: /(png|gif|jpg)+(\)|'\)|"\))/g,
to: '$1\')'
}]
}
},
......
This diff is collapsed.
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment