FIX: Allow raw-view classes to be resolved from themes/plugins (#12685)
Since cd24eff5d9
, theme modules are now prefixed with the theme id. Therefore themes which defined raw-view classes will be broken
This commit updates the `raw` helper to use the resolver for looking up the view class. This automatically takes care of trying theme/plugin paths in addition to core paths.
This commit is contained in:
parent
27eff709c4
commit
da6edc117c
|
@ -2,6 +2,20 @@ import { helperContext, registerUnbound } from "discourse-common/lib/helpers";
|
||||||
import { findRawTemplate } from "discourse-common/lib/raw-templates";
|
import { findRawTemplate } from "discourse-common/lib/raw-templates";
|
||||||
import { htmlSafe } from "@ember/template";
|
import { htmlSafe } from "@ember/template";
|
||||||
import { RUNTIME_OPTIONS } from "discourse-common/lib/raw-handlebars-helpers";
|
import { RUNTIME_OPTIONS } from "discourse-common/lib/raw-handlebars-helpers";
|
||||||
|
import { buildResolver } from "discourse-common/resolver";
|
||||||
|
|
||||||
|
let resolver;
|
||||||
|
|
||||||
|
function lookupView(templateName) {
|
||||||
|
if (!resolver) {
|
||||||
|
resolver = buildResolver("discourse").create();
|
||||||
|
}
|
||||||
|
|
||||||
|
return resolver.customResolve({
|
||||||
|
type: "raw-view",
|
||||||
|
fullNameWithoutType: templateName,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function renderRaw(ctx, template, templateName, params) {
|
function renderRaw(ctx, template, templateName, params) {
|
||||||
params = jQuery.extend({}, params);
|
params = jQuery.extend({}, params);
|
||||||
|
@ -9,12 +23,10 @@ function renderRaw(ctx, template, templateName, params) {
|
||||||
|
|
||||||
let context = helperContext();
|
let context = helperContext();
|
||||||
if (!params.view) {
|
if (!params.view) {
|
||||||
const module = `discourse/raw-views/${templateName}`;
|
const viewClass = lookupView(templateName);
|
||||||
if (requirejs.entries[module]) {
|
|
||||||
const viewClass = requirejs(module, null, null, true);
|
if (viewClass) {
|
||||||
if (viewClass && viewClass.default) {
|
params.view = viewClass.create(params, context);
|
||||||
params.view = viewClass.default.create(params, context);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!params.view) {
|
if (!params.view) {
|
||||||
|
|
Loading…
Reference in New Issue