The project I am currently working on has been worked on by various coders with different backgrounds. One of my recent achievements was writing a clean Capistrano recipe to minimize CSS and JS files. Now, the challenge ahead is figuring out how to identify and rewrite various URL patterns scattered throughout our CSS codebase before they are pushed live.
url('../../images/
url(../images/
url("../../../images/
url(images/
For example:
.test{background:url('/images/test.jpg') no-repeat top left}.pouet{background:url("../../images/bg.png")}
It's important to note that some URLs have quotation marks while others do not. My goal is to transform them into:
.test{background:url('http://www.cdnImages.com/images/test.jpg') no-repeat top left}.pouet{background:url("http://www.cdnImages.com/images/bg.png")}
All instances must be replaced with my CDN URL accurately without room for error.
I have devised a regex pattern that suits my requirements: rubular permalink
Initially, I attempted using the sed command like this:
sed '/url([^\/](.*?)images/http:\/\/www.cdnImages.com' myFile.css
However, it did not yield the desired results.
Further research led me to try this approach:
find #{current_release}/public/static/css/ -name '*.css' | xargs sed -i 's@url\([^\/](.*?)images|static\/@#{images_cdn}@g'
Although the regular expression seems to capture the correct output (see here), there appears to be an issue somewhere in the implementation.
Any suggestions or ideas? Thank you.