Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add defaultBase for setting base for groups #1954

Merged
merged 7 commits into from
Sep 25, 2014
Merged
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
8 changes: 7 additions & 1 deletion src/loader/js/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -1006,12 +1006,18 @@ Y.Loader.prototype = {
*/
addGroup: function(o, name) {
var mods = o.modules,
self = this, i, v;
self = this,
defaultBase = o.defaultBase || Y.config.defaultBase,
i, v;

name = name || o.name;
o.name = name;
self.groups[name] = o;

if (!o.base && defaultBase && o.root) {
o.base = defaultBase + o.root;
}

if (o.patterns) {
for (i in o.patterns) {
if (o.patterns.hasOwnProperty(i)) {
Expand Down
73 changes: 73 additions & 0 deletions src/loader/tests/unit/assets/loader-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,79 @@ YUI.add('loader-tests', function(Y) {
Assert.isTrue((out.js[0].indexOf('node-base-debug.js') > 0), 'node-base-debug was not found');
Assert.isTrue((out.js[0].indexOf('node-core-debug.js') === -1), 'node-core-debug was found');
},
'test defaultBase with groups': function() {
testY.applyConfig({
defaultBase: 'http://mycdn.com/path/to/',
comboBase: 'http://mycdn.com/path/to/combo?',
root: 'yui-3.1.5.0/'
});
var loader = new testY.Loader({
groups: {
test1: {
root: 'zip/',
modules: {
foo: {
filter: 'min'
},
bar: {
filter: 'min'
}
}
},
test2: {
root: 'zap/',
modules: {
baz: {
filter: 'min'
}
}

}
},
require: ['foo', 'bar', 'baz']
});
var out = loader.resolve(true);
Assert.areSame(3, out.js.length, "Loader should not have combined URLs.");
Assert.areSame("http://mycdn.com/path/to/zip/foo/foo-min.js", out.js[0], "The url should be ");
Assert.areSame("http://mycdn.com/path/to/zip/bar/bar-min.js", out.js[1], "The url should be ");
Assert.areSame("http://mycdn.com/path/to/zap/baz/baz-min.js", out.js[2], "The url should be ");
},
'test base should take precedence over defaultBase': function() {
var loader = new testY.Loader({
groups: {
test1: {
defaultBase: 'http://mycdn.com/path/to/',
base: 'http://basecdn.com/path/to/base/',
root: 'zip/',
modules: {
foo: {
filter: 'min'
},
bar: {
filter: 'min'
}
}
},
test2: {
defaultBase: 'http://mycdn.com/path/to/',
base: 'http://basecdn.com/path/to/base/',
root: 'zap/',
modules: {
baz: {
filter: 'min'
}
}

}
},
require: ['foo', 'bar', 'baz']
});
var out = loader.resolve(true);
Assert.areSame(3, out.js.length, "Loader should not have combined URLs.");
Assert.areSame("http://basecdn.com/path/to/base/foo/foo-min.js", out.js[0], "The url should be ");
Assert.areSame("http://basecdn.com/path/to/base/bar/bar-min.js", out.js[1], "The url should be ");
Assert.areSame("http://basecdn.com/path/to/base/baz/baz-min.js", out.js[2], "The url should be ");
},
test_group_filters: function() {
var test = this;

Expand Down
6 changes: 4 additions & 2 deletions src/yui/js/yui.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ proto = {
mods: {}, // flat module map
versions: {}, // version module map
base: BASE,
cdn: BASE + VERSION + '/build/',
cdn: BASE + VERSION + '/',
// bootstrapped: false,
_idx: 0,
_used: {},
Expand Down Expand Up @@ -496,7 +496,9 @@ proto = {

Y.config.lang = Y.config.lang || 'en-US';

Y.config.base = YUI.config.base || Y.Env.getBase(Y.Env._BASE_RE);
Y.config.base = YUI.config.base ||
(YUI.config.defaultBase && YUI.config.root && YUI.config.defaultBase + YUI.config.root) ||
Y.Env.getBase(Y.Env._BASE_RE);

if (!filter || (!('mindebug').indexOf(filter))) {
filter = 'min';
Expand Down