Permalink
Browse files

Version 0.1.3

  • Loading branch information...
1 parent 15eb9d4 commit 3cc07806db93e195c30daafc682cc89d43e99a28 mihhail-lapushkin committed Jan 29, 2014
Showing with 22 additions and 6 deletions.
  1. +1 −0 README.md
  2. +1 −1 package.json
  3. +20 −5 tasks/css-url-embed.js
View
@@ -82,6 +82,7 @@ cssUrlEmbed: {
## Release History
+ * 2014-01-29      v0.1.3      Fixed handling of URL's with parameters. Improved logging.
* 2013-10-02      v0.1.2      Changed logging a bit.
* 2013-09-17      v0.1.1      Removed dependency on [datauri](https://github.com/heldr/datauri). Now pretty much all MIME types are supported.
* 2013-09-09      v0.1.0      First version.
View
@@ -1,7 +1,7 @@
{
"name": "grunt-css-url-embed",
"description": "Embed URL's as base64 strings inside your stylesheets",
- "version": "0.1.2",
+ "version": "0.1.3",
"homepage": "https://github.com/mihhail-lapushkin/grunt-css-url-embed",
"author": {
"name": "Mihhail Lapushkin",
View
@@ -54,30 +54,45 @@ module.exports = function(grunt) {
}
if (grunt.option('verbose')) {
- grunt.log.writeln('Using "' + baseDir + '" as base directory for local URL\'s');
+ grunt.log.writeln('Using "' + baseDir + '" as base directory for URL\'s');
}
grunt.log.writeln(uniqTargetUrls.length + " embeddable URL" + (uniqTargetUrls.length > 1 ? "'s" : "") + " found");
- extractedUrls.forEach(function(url) {
+ extractedUrls.forEach(function(rawUrl, i) {
+ if (grunt.option('verbose')) {
+ grunt.log.writeln('\n[ #' + (i + 1) + ' ]');
+ }
+
+ var url = rawUrl;
+
+ if (rawUrl.indexOf('?') >= 0) {
+ url = rawUrl.split('?')[0];
+
+ if (grunt.option('verbose')) {
+ grunt.log.writeln('"' + rawUrl + '" trimmed to "' + url + '"');
+ }
+ }
+
var urlFullPath = path.resolve(baseDir + '/' + url);
if (grunt.option('verbose')) {
grunt.log.writeln('"' + url + '" resolved to "' + urlFullPath + '"');
}
if (!grunt.file.exists(urlFullPath)) {
- grunt.log.warn('"' + url + '" seems to be wrong');
+ grunt.log.warn('"' + (grunt.option('verbose') ? urlFullPath : url) + '" not found on disk');
return;
}
var base64Content = fs.readFileSync(urlFullPath, 'base64');
var mimeType = mime.lookup(urlFullPath);
var dataUri = 'data:' + mimeType + ';base64,' + base64Content;
+ var escapedRawUrl = rawUrl.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&');
- source = source.replace(new RegExp(url, 'g'), dataUri);
+ source = source.replace(new RegExp(escapedRawUrl, 'g'), dataUri);
- grunt.log.ok('"' + url + '" embedded');
+ grunt.log.ok('"' + rawUrl + '" embedded');
});
return source;

0 comments on commit 3cc0780

Please sign in to comment.