Fix resolve errors

This commit is contained in:
Robin Ward 2014-12-11 15:28:49 -05:00
parent 3e408f9caa
commit 1948b41875
2 changed files with 15 additions and 9 deletions

View file

@ -138,7 +138,18 @@ export default Ember.DefaultResolver.extend({
},
findTemplate: function(parsedName) {
return this._super(parsedName) || this.findSlashedTemplate(parsedName) || this.findAdminTemplate(parsedName) || this.findUnderscoredTemplate(parsedName);
var withoutType = parsedName.fullNameWithoutType,
slashedType = withoutType.replace(/\./g, '/'),
decamelized = withoutType.decamelize(),
templates = Ember.TEMPLATES;
return this._super(parsedName) ||
templates[slashedType] ||
templates[withoutType] ||
templates[decamelized.replace(/\./, '/')] ||
templates[decamelized.replace(/\_/, '/')] ||
this.findAdminTemplate(parsedName) ||
this.findUnderscoredTemplate(parsedName);
},
findUnderscoredTemplate: function(parsedName) {
@ -147,12 +158,6 @@ export default Ember.DefaultResolver.extend({
return Ember.TEMPLATES[underscored];
},
// Try to find a template with slash instead of first underscore, e.g. foo_bar_baz => foo/bar_baz
findSlashedTemplate: function(parsedName) {
var decamelized = parsedName.fullNameWithoutType.decamelize();
return Ember.TEMPLATES[decamelized.replace("_", "/")] || Ember.TEMPLATES[decamelized.replace('.', '/')];
},
// Try to find a template within a special admin namespace, e.g. adminEmail => admin/templates/email
// (similar to how discourse lays out templates)
findAdminTemplate: function(parsedName) {
@ -160,7 +165,7 @@ export default Ember.DefaultResolver.extend({
if (decamelized.indexOf('admin') === 0) {
decamelized = decamelized.replace(/^admin\_/, 'admin/templates/');
decamelized = decamelized.replace(/^admin\./, 'admin/templates/');
decamelized = decamelized.replace(/\./, '_');
decamelized = decamelized.replace(/\./g, '_');
var dashed = decamelized.replace(/_/g, '-');
return Ember.TEMPLATES[decamelized] || Ember.TEMPLATES[dashed];
}

View file

@ -4,7 +4,8 @@ var originalTemplates, originalMobileViewFlag;
var resolver = DiscourseResolver.create();
function lookupTemplate(name, expectedTemplate, message) {
var result = resolver.resolveTemplate(resolver.parseName(name));
var parseName = resolver.parseName(name);
var result = resolver.resolveTemplate(parseName);
equal(result, expectedTemplate, message);
}