REFACTOR: Remove `Discourse.HighlightJSPath` from globals
Instead we use the session, and pass that along where necessary.
This commit is contained in:
parent
3745f2bb86
commit
5b2c306bb8
|
@ -5,7 +5,7 @@ import highlightSyntax from "discourse/lib/highlight-syntax";
|
||||||
export default Component.extend({
|
export default Component.extend({
|
||||||
@on("didInsertElement")
|
@on("didInsertElement")
|
||||||
@observes("code")
|
@observes("code")
|
||||||
_refresh: function() {
|
_refresh() {
|
||||||
highlightSyntax($(this.element), this.siteSettings);
|
highlightSyntax($(this.element), this.siteSettings, this.session);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -313,7 +313,7 @@ const Theme = RestModel.extend({
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
// TODO: Models shouldn't be updating the DOM
|
// TODO: Models shouldn't be updating the DOM
|
||||||
highlightSyntax(undefined, this.siteSettings);
|
highlightSyntax(undefined, this.siteSettings, this.session);
|
||||||
} else {
|
} else {
|
||||||
return this.save({ remote_update: true }).then(() =>
|
return this.save({ remote_update: true }).then(() =>
|
||||||
this.set("changed", false)
|
this.set("changed", false)
|
||||||
|
|
|
@ -9,9 +9,10 @@ export default {
|
||||||
initialize(container) {
|
initialize(container) {
|
||||||
withPluginApi("0.1", api => {
|
withPluginApi("0.1", api => {
|
||||||
const siteSettings = container.lookup("site-settings:main");
|
const siteSettings = container.lookup("site-settings:main");
|
||||||
|
const session = container.lookup("session:main");
|
||||||
api.decorateCooked(
|
api.decorateCooked(
|
||||||
elem => {
|
elem => {
|
||||||
return highlightSyntax(elem, siteSettings);
|
return highlightSyntax(elem, siteSettings, session);
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: "discourse-syntax-highlighting"
|
id: "discourse-syntax-highlighting"
|
||||||
|
|
|
@ -3,11 +3,11 @@ let _moreLanguages = [];
|
||||||
|
|
||||||
import loadScript from "discourse/lib/load-script";
|
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
|
const selector = siteSettings.autohighlight_all_code
|
||||||
? "pre code"
|
? "pre code"
|
||||||
: "pre code[class]",
|
: "pre code[class]",
|
||||||
path = Discourse.HighlightJSPath;
|
path = session.highlightJsPath;
|
||||||
|
|
||||||
if (!path) {
|
if (!path) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -96,7 +96,7 @@ export default {
|
||||||
.trim() === "dark"
|
.trim() === "dark"
|
||||||
);
|
);
|
||||||
|
|
||||||
app.HighlightJSPath = setupData.highlightJsPath;
|
Session.currentProp("highlightJsPath", setupData.highlightJsPath);
|
||||||
Session.currentProp("svgSpritePath", setupData.svgSpritePath);
|
Session.currentProp("svgSpritePath", setupData.svgSpritePath);
|
||||||
|
|
||||||
if (isDevelopment()) {
|
if (isDevelopment()) {
|
||||||
|
|
|
@ -8,7 +8,7 @@ componentTest("highlighting code", {
|
||||||
template: "{{highlighted-code lang='ruby' code=code}}",
|
template: "{{highlighted-code lang='ruby' code=code}}",
|
||||||
|
|
||||||
beforeEach() {
|
beforeEach() {
|
||||||
Discourse.HighlightJSPath =
|
this.session.highlightJsPath =
|
||||||
"assets/highlightjs/highlight-test-bundle.min.js";
|
"assets/highlightjs/highlight-test-bundle.min.js";
|
||||||
this.set("code", "def test; end");
|
this.set("code", "def test; end");
|
||||||
},
|
},
|
||||||
|
@ -27,7 +27,7 @@ componentTest("large code blocks are not highlighted", {
|
||||||
template: "{{highlighted-code lang='ruby' code=code}}",
|
template: "{{highlighted-code lang='ruby' code=code}}",
|
||||||
|
|
||||||
beforeEach() {
|
beforeEach() {
|
||||||
Discourse.HighlightJSPath =
|
this.session.highlightJsPath =
|
||||||
"assets/highlightjs/highlight-test-bundle.min.js";
|
"assets/highlightjs/highlight-test-bundle.min.js";
|
||||||
this.set("code", LONG_CODE_BLOCK);
|
this.set("code", LONG_CODE_BLOCK);
|
||||||
},
|
},
|
||||||
|
|
|
@ -4,6 +4,7 @@ import { autoLoadModules } from "discourse/initializers/auto-load-modules";
|
||||||
import TopicTrackingState from "discourse/models/topic-tracking-state";
|
import TopicTrackingState from "discourse/models/topic-tracking-state";
|
||||||
import User from "discourse/models/user";
|
import User from "discourse/models/user";
|
||||||
import Site from "discourse/models/site";
|
import Site from "discourse/models/site";
|
||||||
|
import Session from "discourse/models/session";
|
||||||
import { currentSettings } from "helpers/site-settings";
|
import { currentSettings } from "helpers/site-settings";
|
||||||
|
|
||||||
export default function(name, opts) {
|
export default function(name, opts) {
|
||||||
|
@ -15,16 +16,21 @@ export default function(name, opts) {
|
||||||
|
|
||||||
test(name, function(assert) {
|
test(name, function(assert) {
|
||||||
this.site = Site.current();
|
this.site = Site.current();
|
||||||
|
this.session = Session.current();
|
||||||
|
|
||||||
this.registry.register("site-settings:main", currentSettings(), {
|
this.registry.register("site-settings:main", currentSettings(), {
|
||||||
instantiate: false
|
instantiate: false
|
||||||
});
|
});
|
||||||
this.registry.register("capabilities:main", EmberObject);
|
this.registry.register("capabilities:main", EmberObject);
|
||||||
this.registry.register("site:main", this.site, { instantiate: false });
|
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", "siteSettings", "site-settings:main");
|
||||||
this.registry.injection("component", "appEvents", "service:app-events");
|
this.registry.injection("component", "appEvents", "service:app-events");
|
||||||
this.registry.injection("component", "capabilities", "capabilities:main");
|
this.registry.injection("component", "capabilities", "capabilities:main");
|
||||||
this.registry.injection("component", "site", "site:main");
|
this.registry.injection("component", "site", "site:main");
|
||||||
|
this.registry.injection("component", "session", "session:main");
|
||||||
|
|
||||||
this.siteSettings = currentSettings();
|
this.siteSettings = currentSettings();
|
||||||
autoLoadModules(this.container, this.registry);
|
autoLoadModules(this.container, this.registry);
|
||||||
|
|
Loading…
Reference in New Issue