A platform for community discussion. Free, open, simple.
REFACTOR: Remove `Discourse.HighlightJSPath` from globals
Robin Ward5b2c306bb83c
diff --git a/app/assets/javascripts/admin/components/highlighted-code.js b/app/assets/javascripts/admin/components/highlighted-code.jsindex 1c62c4c532f..836ec06c296 100644--- a/app/assets/javascripts/admin/components/highlighted-code.js+++ b/app/assets/javascripts/admin/components/highlighted-code.js@@ -5,7 +5,7 @@ import highlightSyntax from "discourse/lib/highlight-syntax";export default Component.extend({@on("didInsertElement")@observes("code")- _refresh: function() {- highlightSyntax($(this.element), this.siteSettings);+ _refresh() {+ highlightSyntax($(this.element), this.siteSettings, this.session);}});diff --git a/app/assets/javascripts/admin/models/theme.js b/app/assets/javascripts/admin/models/theme.jsindex d3077eb5499..eb2aecfd602 100644--- a/app/assets/javascripts/admin/models/theme.js+++ b/app/assets/javascripts/admin/models/theme.js@@ -313,7 +313,7 @@ const Theme = RestModel.extend({});// TODO: Models shouldn't be updating the DOM- highlightSyntax(undefined, this.siteSettings);+ highlightSyntax(undefined, this.siteSettings, this.session);} else {return this.save({ remote_update: true }).then(() =>this.set("changed", false)diff --git a/app/assets/javascripts/discourse/app/initializers/post-decorations.js b/app/assets/javascripts/discourse/app/initializers/post-decorations.jsindex c906d9f6b78..ce297d71484 100644--- a/app/assets/javascripts/discourse/app/initializers/post-decorations.js+++ b/app/assets/javascripts/discourse/app/initializers/post-decorations.js@@ -9,9 +9,10 @@ export default {initialize(container) {withPluginApi("0.1", api => {const siteSettings = container.lookup("site-settings:main");+ const session = container.lookup("session:main");api.decorateCooked(elem => {- return highlightSyntax(elem, siteSettings);+ return highlightSyntax(elem, siteSettings, session);},{id: "discourse-syntax-highlighting"diff --git a/app/assets/javascripts/discourse/app/lib/highlight-syntax.js b/app/assets/javascripts/discourse/app/lib/highlight-syntax.jsindex cc2a2f36680..cd9724d2fa3 100644--- a/app/assets/javascripts/discourse/app/lib/highlight-syntax.js+++ b/app/assets/javascripts/discourse/app/lib/highlight-syntax.js@@ -3,11 +3,11 @@ let _moreLanguages = [];import loadScript from "discourse/lib/load-script";-export default function highlightSyntax($elem, siteSettings) {+export default function highlightSyntax($elem, siteSettings, session) {const selector = siteSettings.autohighlight_all_code? "pre code": "pre code[class]",- path = Discourse.HighlightJSPath;+ path = session.highlightJsPath;if (!path) {return;diff --git a/app/assets/javascripts/discourse/app/pre-initializers/discourse-bootstrap.js b/app/assets/javascripts/discourse/app/pre-initializers/discourse-bootstrap.jsindex 647cd38cf59..6695428969e 100644--- a/app/assets/javascripts/discourse/app/pre-initializers/discourse-bootstrap.js+++ b/app/assets/javascripts/discourse/app/pre-initializers/discourse-bootstrap.js@@ -96,7 +96,7 @@ export default {.trim() === "dark");- app.HighlightJSPath = setupData.highlightJsPath;+ Session.currentProp("highlightJsPath", setupData.highlightJsPath);Session.currentProp("svgSpritePath", setupData.svgSpritePath);if (isDevelopment()) {diff --git a/test/javascripts/components/highlighted-code-test.js b/test/javascripts/components/highlighted-code-test.jsindex 27cfe5696d3..a5bd5121024 100644--- a/test/javascripts/components/highlighted-code-test.js+++ b/test/javascripts/components/highlighted-code-test.js@@ -8,7 +8,7 @@ componentTest("highlighting code", {template: "{{highlighted-code lang='ruby' code=code}}",beforeEach() {- Discourse.HighlightJSPath =+ this.session.highlightJsPath ="assets/highlightjs/highlight-test-bundle.min.js";this.set("code", "def test; end");},@@ -27,7 +27,7 @@ componentTest("large code blocks are not highlighted", {template: "{{highlighted-code lang='ruby' code=code}}",beforeEach() {- Discourse.HighlightJSPath =+ this.session.highlightJsPath ="assets/highlightjs/highlight-test-bundle.min.js";this.set("code", LONG_CODE_BLOCK);},diff --git a/test/javascripts/helpers/component-test.js b/test/javascripts/helpers/component-test.jsindex 4d5d930f650..b1a82209c6d 100644--- a/test/javascripts/helpers/component-test.js+++ b/test/javascripts/helpers/component-test.js@@ -4,6 +4,7 @@ import { autoLoadModules } from "discourse/initializers/auto-load-modules";import TopicTrackingState from "discourse/models/topic-tracking-state";import User from "discourse/models/user";import Site from "discourse/models/site";+import Session from "discourse/models/session";import { currentSettings } from "helpers/site-settings";export default function(name, opts) {@@ -15,16 +16,21 @@ export default function(name, opts) {test(name, function(assert) {this.site = Site.current();+ this.session = Session.current();this.registry.register("site-settings:main", currentSettings(), {instantiate: false});this.registry.register("capabilities:main", EmberObject);this.registry.register("site:main", this.site, { instantiate: false });+ this.registry.register("session:main", this.session, {+ instantiate: false+ });this.registry.injection("component", "siteSettings", "site-settings:main");this.registry.injection("component", "appEvents", "service:app-events");this.registry.injection("component", "capabilities", "capabilities:main");this.registry.injection("component", "site", "site:main");+ this.registry.injection("component", "session", "session:main");this.siteSettings = currentSettings();autoLoadModules(this.container, this.registry);