Don't try injecting into the Resolver. Use options instead.

This commit is contained in:
Robin Ward 2016-11-03 14:15:26 -04:00
parent c8282e4ca1
commit e18ae34493
3 changed files with 14 additions and 7 deletions

View File

@ -9,6 +9,13 @@ var LOADING_WHITELIST = ['badges', 'userActivity', 'userPrivateMessages', 'admin
var _dummyRoute;
var _loadingView;
const _options = {};
export function setResolverOption(name, value) {
_options[name] = value;
}
function loadingResolver(cb) {
return function(parsedName) {
var fullNameWithoutType = parsedName.fullNameWithoutType;
@ -158,14 +165,14 @@ export function buildResolver(baseName) {
},
findPluginMobileTemplate(parsedName) {
if (this.mobileView) {
if (_options.mobileView) {
var pluginParsedName = this.parseName(parsedName.fullName.replace("template:", "template:javascripts/mobile/"));
return this.findTemplate(pluginParsedName);
}
},
findMobileTemplate(parsedName) {
if (this.mobileView) {
if (_options.mobileView) {
var mobileParsedName = this.parseName(parsedName.fullName.replace("template:", "template:mobile/"));
return this.findTemplate(mobileParsedName);
}

View File

@ -1,18 +1,18 @@
import Mobile from 'discourse/lib/mobile';
import { setResolverOption } from 'discourse-common/resolver';
// Initializes the `Mobile` helper object.
export default {
name: 'mobile',
after: 'inject-objects',
initialize(container, app) {
initialize(container) {
Mobile.init();
const site = container.lookup('site:main');
site.set('mobileView', Mobile.mobileView);
site.set('isMobileDevice', Mobile.isMobileDevice);
// This is a bit weird but you can't seem to inject into the resolver?
app.registry.resolver.__resolver__.mobileView = Mobile.mobileView;
setResolverOption('mobileView', Mobile.mobileView);
}
};

View File

@ -1,4 +1,4 @@
import { buildResolver } from 'discourse-common/resolver';
import { setResolverOption, buildResolver } from 'discourse-common/resolver';
let originalTemplates;
let resolver;
@ -92,7 +92,7 @@ test("resolves mobile templates to 'mobile/' namespace", function() {
"baz"
]);
resolver.mobileView = true;
setResolverOption('mobileView', true);
lookupTemplate("template:foo", "mobile/foo", "finding mobile version even if normal one is not present");
lookupTemplate("template:bar", "mobile/bar", "preferring mobile version when both mobile and normal versions are present");