This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/ember/resolver.js
2013-07-26 15:04:29 -04:00

42 lines
1.4 KiB
JavaScript

/**
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;
}
});