Moved Resolver to new File
This commit is contained in:
parent
773823c41f
commit
20f3707fbe
|
@ -23,7 +23,6 @@ Discourse = Ember.Application.createWithMixins({
|
||||||
URL_FIXTURES: {},
|
URL_FIXTURES: {},
|
||||||
|
|
||||||
getURL: function(url) {
|
getURL: function(url) {
|
||||||
|
|
||||||
// If it's a non relative URL, return it.
|
// If it's a non relative URL, return it.
|
||||||
if (url.indexOf('http') === 0) return url;
|
if (url.indexOf('http') === 0) return url;
|
||||||
|
|
||||||
|
@ -34,36 +33,7 @@ Discourse = Ember.Application.createWithMixins({
|
||||||
return u + url;
|
return u + url;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
resolver: Discourse.Resolver,
|
||||||
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;
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
|
|
||||||
titleChanged: function() {
|
titleChanged: function() {
|
||||||
var title = "";
|
var title = "";
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
Loading…
Reference in New Issue