Skip to content

Commit

Permalink
Update dist/.
Browse files Browse the repository at this point in the history
  • Loading branch information
rwjblue committed Jun 11, 2015
1 parent b9375f5 commit 3c915c3
Show file tree
Hide file tree
Showing 7 changed files with 188 additions and 24 deletions.
2 changes: 1 addition & 1 deletion dist/ember-resolver-spade.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/ember-resolver-tests.js

Large diffs are not rendered by default.

52 changes: 45 additions & 7 deletions dist/ember-resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ define("ember/resolver",

function resolveOther(parsedName) {
/*jshint validthis:true */

// Temporarily disabling podModulePrefix deprecation
/*
if (!this._deprecatedPodModulePrefix) {
Expand All @@ -115,23 +115,22 @@ define("ember/resolver",
var normalizedModuleName = this.findModuleName(parsedName);

if (normalizedModuleName) {
var module = require(normalizedModuleName, null, null, true /* force sync */);
var defaultExport = this._extractDefaultExport(normalizedModuleName, parsedName);

if (module && module['default']) { module = module['default']; }

if (module === undefined) {
if (defaultExport === undefined) {
throw new Error(" Expected to find: '" + parsedName.fullName + "' within '" + normalizedModuleName + "' but got 'undefined'. Did you forget to `export default` within '" + normalizedModuleName + "'?");
}

if (this.shouldWrapInClassFactory(module, parsedName)) {
module = classFactory(module);
defaultExport = classFactory(defaultExport);
}

return module;
return defaultExport;
} else {
return this._super(parsedName);
}
}

// Ember.DefaultResolver docs:
// https://github.com/emberjs/ember.js/blob/master/packages/ember-application/lib/system/resolver.js
var Resolver = Ember.DefaultResolver.extend({
Expand Down Expand Up @@ -337,6 +336,45 @@ define("ember/resolver",
}

Ember.Logger.info(symbol, parsedName.fullName, padding, description);
},

eachForType: function(type, callback) {
var moduleEntries = requirejs.entries;

for (var moduleName in moduleEntries) {
var fullname = this.translateToContainerFullname(type, moduleName);

if (fullname) {
callback(fullname, this._extractDefaultExport(moduleName));
}
}
},

translateToContainerFullname: function(type, moduleName) {
var prefix = this.prefix({ type: type });
var pluralizedType = this.pluralize(type);
var nonPodRegExp = new RegExp('^' + prefix + '/' + pluralizedType + '/(.+)$');
var podRegExp = new RegExp('^' + prefix + '/(.+)/' + type + '$');
var matches;


if ((matches = moduleName.match(podRegExp))) {
return type + ':' + matches[1];
}

if ((matches = moduleName.match(nonPodRegExp))) {
return type + ':' + matches[1];
}
},

_extractDefaultExport: function(normalizedModuleName) {
var module = require(normalizedModuleName, null, null, true /* force sync */);

if (module && module['default']) {
module = module['default'];
}

return module;
}
});

Expand Down
2 changes: 1 addition & 1 deletion dist/ember-resolver.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 45 additions & 7 deletions dist/ember-resolver.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ define("ember/resolver",

function resolveOther(parsedName) {
/*jshint validthis:true */

// Temporarily disabling podModulePrefix deprecation
/*
if (!this._deprecatedPodModulePrefix) {
Expand All @@ -115,23 +115,22 @@ define("ember/resolver",
var normalizedModuleName = this.findModuleName(parsedName);

if (normalizedModuleName) {
var module = require(normalizedModuleName, null, null, true /* force sync */);
var defaultExport = this._extractDefaultExport(normalizedModuleName, parsedName);

if (module && module['default']) { module = module['default']; }

if (module === undefined) {
if (defaultExport === undefined) {
throw new Error(" Expected to find: '" + parsedName.fullName + "' within '" + normalizedModuleName + "' but got 'undefined'. Did you forget to `export default` within '" + normalizedModuleName + "'?");
}

if (this.shouldWrapInClassFactory(module, parsedName)) {
module = classFactory(module);
defaultExport = classFactory(defaultExport);
}

return module;
return defaultExport;
} else {
return this._super(parsedName);
}
}

// Ember.DefaultResolver docs:
// https://github.com/emberjs/ember.js/blob/master/packages/ember-application/lib/system/resolver.js
var Resolver = Ember.DefaultResolver.extend({
Expand Down Expand Up @@ -337,6 +336,45 @@ define("ember/resolver",
}

Ember.Logger.info(symbol, parsedName.fullName, padding, description);
},

eachForType: function(type, callback) {
var moduleEntries = requirejs.entries;

for (var moduleName in moduleEntries) {
var fullname = this.translateToContainerFullname(type, moduleName);

if (fullname) {
callback(fullname, this._extractDefaultExport(moduleName));
}
}
},

translateToContainerFullname: function(type, moduleName) {
var prefix = this.prefix({ type: type });
var pluralizedType = this.pluralize(type);
var nonPodRegExp = new RegExp('^' + prefix + '/' + pluralizedType + '/(.+)$');
var podRegExp = new RegExp('^' + prefix + '/(.+)/' + type + '$');
var matches;


if ((matches = moduleName.match(podRegExp))) {
return type + ':' + matches[1];
}

if ((matches = moduleName.match(nonPodRegExp))) {
return type + ':' + matches[1];
}
},

_extractDefaultExport: function(normalizedModuleName) {
var module = require(normalizedModuleName, null, null, true /* force sync */);

if (module && module['default']) {
module = module['default'];
}

return module;
}
});

Expand Down
50 changes: 50 additions & 0 deletions dist/modules/ember-resolver-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,56 @@ test("can lookup templates via Ember.TEMPLATES", function() {
ok(template, 'template should resolve');
});

test('it provides eachForType which invokes the callback for each item found', function() {

function orange() { }
define('appkit/fruits/orange', [], function() {
return { default: orange };
});

function apple() { }
define('appkit/fruits/apple', [], function() {
return {default: apple };
});

function other() {}
define('appkit/stuffs/other', [], function() {
return { default: other };
});

var items = {};
resolver.eachForType('fruit', function(item, factory) {
items[item] = factory;
});

deepEqual(items, {
'fruit:apple': apple,
'fruit:orange': orange
});
});

test('eachForType can find both pod and non-pod factories', function() {
function orange() { }
define('appkit/fruits/orange', [], function() {
return { default: orange };
});

function lemon() { }
define('appkit/lemon/fruit', [], function() {
return { default: lemon };
});

var items = {};
resolver.eachForType('fruit', function(item, factory) {
items[item] = factory;
});

deepEqual(items, {
'fruit:orange': orange,
'fruit:lemon': lemon
});
});

module("Logging", {
setup: function() {
originalLog = Ember.Logger.info;
Expand Down
Loading

0 comments on commit 3c915c3

Please sign in to comment.