Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix issue #643: yeoman build not updating revved image references in css

  • Loading branch information...
commit b38b905009e12214fe6a0e8236d088c3ee2b3dce 1 parent 448968e
@roparz roparz authored
Showing with 17 additions and 7 deletions.
  1. +6 −5 cli/tasks/usemin.js
  2. +11 −2 cli/test/test-usemin.js
View
11 cli/tasks/usemin.js
@@ -171,7 +171,7 @@ module.exports = function(grunt) {
// actual replacement of revved assets
if(!!grunt.task._helpers['usemin:post:' + name]) {
- content = grunt.helper('usemin:post:' + name, content);
+ content = grunt.helper('usemin:post:' + name, content, p);
}
// write the new content to disk
@@ -350,10 +350,10 @@ module.exports = function(grunt) {
return content;
});
- grunt.registerHelper('usemin:post:css', function(content) {
+ grunt.registerHelper('usemin:post:css', function(content, srcPath) {
grunt.log.verbose.writeln('Update the CSS with background imgs, case there is some inline style');
- content = grunt.helper('replace', content, /url\(\s*['"]?([^'"\)]+)['"]?\s*\)/gm);
+ content = grunt.helper('replace', content, /url\(\s*['"]?([^'"\)]+)['"]?\s*\)/gm, srcPath);
return content;
});
@@ -363,7 +363,7 @@ module.exports = function(grunt) {
// regexp should capture the assets relative filepath, it is then compared to
// the list of files on the filesystem to guess the actual revision of a file
//
- grunt.registerHelper('replace', function(content, regexp) {
+ grunt.registerHelper('replace', function(content, regexp, srcPath) {
return content.replace(regexp, function(match, src) {
//do not touch external files or the root
if ( src.match(/\/\//) || src.match(/^\/$/)) {
@@ -377,12 +377,13 @@ module.exports = function(grunt) {
var basename = path.basename(src);
var dirname = path.dirname(src);
+ var normalizedDirname = path.normalize([path.dirname(srcPath), dirname].join('/'));
// XXX files won't change, the filepath should filter the original list
// of cached files (we need to treat the filename collision -- i.e. 2 files with same names
// in different subdirectories)
var filepaths = grunt.file.expand(path.join('**/*') + basename);
- var filepath = filepaths.filter(function(f) { return dirname === path.dirname(f);})[0];
+ var filepath = filepaths.filter(function(f) { return normalizedDirname === path.dirname(f); })[0];
// not a file in temp, skip it
if ( !filepath ) {
View
13 cli/test/test-usemin.js
@@ -16,7 +16,7 @@ describe('usemin', function() {
it("should take into account path", function() {
usemin.call(grunt,grunt);
- // Let's prepare our context: in index.html we do have references
+ // Let's prepare our context: in index.html we do have references
// to images/test.png and images/misc/test.png.
// Usemin's replace is supposed to change this by files
// found on the filesystem matching the same path, but
@@ -48,6 +48,15 @@ describe('usemin', function() {
});
});
+ describe('usemin:post:css', function() {
+ it("should replace img urls in css file", function() {
+ var content = 'url(../images/test.png)';
+ var awaited = 'url(../images/23012.test.png)';
+ var changed = grunt.helper('usemin:post:css', content, 'css/23012.main.css');
+ assert.ok( changed == awaited );
+ });
+ });
+
describe('usemin:post:html', function() {
before(function() {
usemin.call(grunt,grunt);
@@ -55,7 +64,7 @@ describe('usemin', function() {
grunt.file.mkdir('images');
grunt.file.mkdir('css');
});
-
+
it('should skip external file', function() {
grunt.file.write('images/23012.foo.png', "foo");
var content = '<img src="//css/main.css">';
Please sign in to comment.
Something went wrong with that request. Please try again.