REFACTOR: Add themeSettings to the helperContext to avoid a global

This commit is contained in:
Robin Ward 2020-08-14 13:31:43 -04:00
parent 8ac85f54fb
commit 41fd7a8b72
4 changed files with 7 additions and 10 deletions

View File

@ -46,10 +46,8 @@ export function registerHelpers(registry) {
} }
let _helperContext; let _helperContext;
export function createHelperContext(siteSettings) { export function createHelperContext(ctx) {
_helperContext = { _helperContext = ctx;
siteSettings
};
} }
// This can be used by a helper to get the SiteSettings. Note you should not // This can be used by a helper to get the SiteSettings. Note you should not

View File

@ -1,5 +1,5 @@
import I18n from "I18n"; import I18n from "I18n";
import { registerUnbound } from "discourse-common/lib/helpers"; import { helperContext, registerUnbound } from "discourse-common/lib/helpers";
import deprecated from "discourse-common/lib/deprecated"; import deprecated from "discourse-common/lib/deprecated";
registerUnbound("theme-i18n", (themeId, key, params) => { registerUnbound("theme-i18n", (themeId, key, params) => {
@ -18,7 +18,5 @@ registerUnbound("theme-setting", (themeId, key, hash) => {
{ since: "v2.2.0.beta8", dropFrom: "v2.3.0" } { since: "v2.2.0.beta8", dropFrom: "v2.3.0" }
); );
} }
return Discourse.__container__ return helperContext().themeSettings.getSetting(themeId, key);
.lookup("service:theme-settings")
.getSetting(themeId, key);
}); });

View File

@ -16,7 +16,8 @@ export function autoLoadModules(container, registry) {
} }
}); });
let siteSettings = container.lookup("site-settings:main"); let siteSettings = container.lookup("site-settings:main");
createHelperContext(siteSettings); let themeSettings = container.lookup("service:theme-settings");
createHelperContext({ siteSettings, themeSettings });
registerHelpers(registry); registerHelpers(registry);
registerRawHelpers(RawHandlebars, Handlebars); registerRawHelpers(RawHandlebars, Handlebars);
} }

View File

@ -164,7 +164,7 @@ QUnit.testStart(function(ctx) {
Session.resetCurrent(); Session.resetCurrent();
User.resetCurrent(); User.resetCurrent();
resetSite(settings); resetSite(settings);
createHelperContext(settings); createHelperContext({ siteSettings: settings });
_DiscourseURL.redirectedTo = null; _DiscourseURL.redirectedTo = null;
_DiscourseURL.redirectTo = function(url) { _DiscourseURL.redirectTo = function(url) {