From e1e0757b6409665e6cbf1663aec50cacfe634a07 Mon Sep 17 00:00:00 2001 From: Sid Azad Date: Tue, 9 Sep 2014 16:21:46 -0400 Subject: [PATCH 1/3] Added convertToAbsolute for absolute paths Added convertToAbsolute for instances when images are not being relocated to the same directory as the CSS. --- index.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 284a944..5ffa0b5 100644 --- a/index.js +++ b/index.js @@ -21,7 +21,9 @@ var rebaseUrls = function(css, options) { if (process.platform === 'win32') { p = p.replace(/\\/g, '/'); } - + if (options.convertToAbsolute) { + p = "/" + p; + } return p; })) .toString(); @@ -30,11 +32,13 @@ var rebaseUrls = function(css, options) { module.exports = function(options) { options = options || {}; var root = options.root || '.'; + var convertToAbsolute = options.convertToAbsolute || false; return through.obj(function(file, enc, cb) { var css = rebaseUrls(file.contents.toString(), { currentDir: path.dirname(file.path), - root: path.join(file.cwd, root) + root: path.join(file.cwd, root), + convertToAbsolute: convertToAbsolute }); file.contents = new Buffer(css); From b801c8992287e81146422ac7dd35e0f7021815fe Mon Sep 17 00:00:00 2001 From: Sid Azad Date: Tue, 9 Sep 2014 16:26:21 -0400 Subject: [PATCH 2/3] documentation for convertToAbsolute --- README.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/README.md b/README.md index 5d2b82b..4275762 100644 --- a/README.md +++ b/README.md @@ -74,4 +74,28 @@ production. I want this final file for the css above: } ``` +## Using the 'convertToAbsolute' option + +This option will prefix the rebased relative URL with a forward slash to convert it into an absolute path. This is to accomodate situations where the CSS files are being transferred into another directory (such as a temp directory for generated files) but the images aren't being relocated. + +By default the option is turned off. + +### Example + +```javascript +var gulp = require('gulp'); +var rebaseUrls = require('gulp-css-rebase-urls'); + +gulp.task('default', function () { + gulp.src('css/**/*.css') + .pipe(rebaseUrls({ + convertToAbsolute: true, + })) + .pipe(concat('style.css')) // <-- just an example + .pipe(gulp.dest('./build/')); +}); +``` + + + Pull requests and use cases welcome. From 2056d902c64ec2ea93fa3551a8528ec103bd77ed Mon Sep 17 00:00:00 2001 From: Sid Azad Date: Tue, 9 Sep 2014 16:27:30 -0400 Subject: [PATCH 3/3] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4275762..8b45039 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,7 @@ production. I want this final file for the css above: ## Using the 'convertToAbsolute' option -This option will prefix the rebased relative URL with a forward slash to convert it into an absolute path. This is to accomodate situations where the CSS files are being transferred into another directory (such as a temp directory for generated files) but the images aren't being relocated. +This option will prefix the rebased relative URL with a forward slash to convert it into an absolute path. This is to accommodate situations where the CSS files are being transferred into another directory (such as a temp directory for generated files) but the images aren't being relocated. By default the option is turned off.