Moved Resolver to new File

This commit is contained in:
Robin Ward 2013-07-26 15:04:29 -04:00
parent 773823c41f
commit 20f3707fbe
2 changed files with 43 additions and 31 deletions

View File

@ -23,7 +23,6 @@ Discourse = Ember.Application.createWithMixins({
URL_FIXTURES: {},
getURL: function(url) {
// If it's a non relative URL, return it.
if (url.indexOf('http') === 0) return url;
@ -34,36 +33,7 @@ Discourse = Ember.Application.createWithMixins({
return u + url;
},
/**
This custom resolver allows us to find admin templates without calling .render
even though our path formats are slightly different than what ember prefers.
*/
resolver: Ember.DefaultResolver.extend({
resolveTemplate: function(parsedName) {
var resolvedTemplate = this._super(parsedName);
if (resolvedTemplate) { return resolvedTemplate; }
var decamelized = parsedName.fullNameWithoutType.decamelize();
// See if we can find it with slashes instead of underscores
var slashed = decamelized.replace("_", "/");
resolvedTemplate = Ember.TEMPLATES[slashed];
if (resolvedTemplate) { return resolvedTemplate; }
// If we can't find a template, check to see if it's similar to how discourse
// lays out templates like: adminEmail => admin/templates/email
if (parsedName.fullNameWithoutType.indexOf('admin') === 0) {
decamelized = decamelized.replace(/^admin\_/, 'admin/templates/');
decamelized = decamelized.replace(/^admin\./, 'admin/templates/');
decamelized = decamelized.replace(/\./, '_');
resolvedTemplate = Ember.TEMPLATES[decamelized];
if (resolvedTemplate) { return resolvedTemplate; }
}
return Ember.TEMPLATES.not_found;
}
}),
resolver: Discourse.Resolver,
titleChanged: function() {
var title = "";

View File

@ -0,0 +1,42 @@
/**
A custom resolver to allow template names in the format we like.
@class Resolver
@extends Ember.DefaultResolver
@namespace Discourse
@module Discourse
**/
Discourse.Resolver = Ember.DefaultResolver.extend({
/**
Attaches a view and wires up the container properly
@method resolveTemplate
@param {String} parsedName the name of the template we want to resolve
@returns {Template} the template (if found)
**/
resolveTemplate: function(parsedName) {
var resolvedTemplate = this._super(parsedName);
if (resolvedTemplate) { return resolvedTemplate; }
var decamelized = parsedName.fullNameWithoutType.decamelize();
// See if we can find it with slashes instead of underscores
var slashed = decamelized.replace("_", "/");
resolvedTemplate = Ember.TEMPLATES[slashed];
if (resolvedTemplate) { return resolvedTemplate; }
// If we can't find a template, check to see if it's similar to how discourse
// lays out templates like: adminEmail => admin/templates/email
if (parsedName.fullNameWithoutType.indexOf('admin') === 0) {
decamelized = decamelized.replace(/^admin\_/, 'admin/templates/');
decamelized = decamelized.replace(/^admin\./, 'admin/templates/');
decamelized = decamelized.replace(/\./, '_');
resolvedTemplate = Ember.TEMPLATES[decamelized];
if (resolvedTemplate) { return resolvedTemplate; }
}
return Ember.TEMPLATES.not_found;
}
});