Skip to content
This repository has been archived by the owner on Apr 20, 2018. It is now read-only.

include support for baseURL configuration #613

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions lib/revvedfinder.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ var _ = require('lodash');
// - a hash mapping files with their revved versions
// - a function that will return a list of file matching a given pattern (for example grunt.file.expand)
//
var RevvedFinder = module.exports = function (locator) {
var RevvedFinder = module.exports = function (locator, baseURL) {
if (_.isFunction(locator)) {
debug('using function locator');
this.expandfn = locator;
} else {
debug('using file locator %s', locator);
this.mapping = locator;
}
this.baseURL = baseURL || '';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

drop the || '' part

};

var regexpQuote = function (str) {
Expand Down Expand Up @@ -196,10 +197,12 @@ RevvedFinder.prototype.find = function find(ofile, searchDirs) {
// filename = [dirname, filename].join('/');
// }

if (absolute) {
if (absolute && this.baseURL) {
filepath = prefix.substring(1) + filepath; // ignore the first slash
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should not ignore the first slash unless the baseUrl ends with a slash

} else if (absolute) {
filepath = prefix + filepath;
}

debug('Let\'s return %s', filepath);
return filepath;
return this.baseURL + filepath;
};
3 changes: 2 additions & 1 deletion tasks/usemin.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ module.exports = function (grunt) {

// var locator = options.revmap ? grunt.file.readJSON(options.revmap) : function (p) { return grunt.file.expand({filter: 'isFile'}, p); };
var locator = getLocator(grunt, options);
var revvedfinder = new RevvedFinder(locator);
var baseURL = options.baseURL || '';
var revvedfinder = new RevvedFinder(locator, baseURL);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var revvedfinder = new RevvedFinder(locator, options.baseURL);

If options.baseUrl is not defined it will pass in a undefined (falsey value)

var handler = new FileProcessor(type, patterns, revvedfinder, function (msg) {
grunt.verbose.writeln(msg);
}, blockReplacements);
Expand Down
16 changes: 14 additions & 2 deletions test/test-revvedfinder.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,13 @@ describe('RevvedFinder', function () {
var file = rf.find('../../images/misc/test.png', ['temp/foo', 'dist/bar']);
assert.equal(file, '../../images/misc/test.34546.png');
});

it('should return the corresponding file prepended with a base URL', function () {
var rf = new RevvedFinder(helpers.normalize({
'dist/images/misc/test.png': 'dist/images/misc/test.34546.png'
}), '/static/');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a test without a trailing slash

var file = rf.find('images/misc/test.png', ['temp', 'dist']);
assert.equal(file, '/static/images/misc/test.34546.png');
});
});
describe('absolute paths', function () {
it('should return the corresponding file', function () {
Expand All @@ -233,8 +239,14 @@ describe('RevvedFinder', function () {
var file = rf.find('/images/misc/test.png', ['temp', 'dist']);
assert.equal(file, '/images/misc/test.34546.png');
});
it('should return the corresponding file prepended with a base URL', function () {
var rf = new RevvedFinder(helpers.normalize({
'dist/images/misc/test.png': 'dist/images/misc/test.34546.png'
}), '/static/');
var file = rf.find('/images/misc/test.png', ['temp', 'dist']);
assert.equal(file, '/static/images/misc/test.34546.png');
});
});
});

});
});