From 1948b41875db7e560f23f0655b63512b1748a255 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Thu, 11 Dec 2014 15:28:49 -0500 Subject: [PATCH] Fix resolve errors --- .../discourse/ember/resolver.js.es6 | 21 ++++++++++++------- test/javascripts/ember/resolver-test.js.es6 | 3 ++- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/app/assets/javascripts/discourse/ember/resolver.js.es6 b/app/assets/javascripts/discourse/ember/resolver.js.es6 index f4de49eacc4..7976de86bf1 100644 --- a/app/assets/javascripts/discourse/ember/resolver.js.es6 +++ b/app/assets/javascripts/discourse/ember/resolver.js.es6 @@ -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]; } diff --git a/test/javascripts/ember/resolver-test.js.es6 b/test/javascripts/ember/resolver-test.js.es6 index 4ca9ca5c470..14ed9709492 100644 --- a/test/javascripts/ember/resolver-test.js.es6 +++ b/test/javascripts/ember/resolver-test.js.es6 @@ -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); }