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:
David Taylor 2021-04-13 15:05:46 +01:00 committed by GitHub
parent 27eff709c4
commit da6edc117c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,6 +2,20 @@ import { helperContext, registerUnbound } from "discourse-common/lib/helpers";
import { findRawTemplate } from "discourse-common/lib/raw-templates";
import { htmlSafe } from "@ember/template";
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) {
params = jQuery.extend({}, params);
@ -9,12 +23,10 @@ function renderRaw(ctx, template, templateName, params) {
let context = helperContext();
if (!params.view) {
const module = `discourse/raw-views/${templateName}`;
if (requirejs.entries[module]) {
const viewClass = requirejs(module, null, null, true);
if (viewClass && viewClass.default) {
params.view = viewClass.default.create(params, context);
}
const viewClass = lookupView(templateName);
if (viewClass) {
params.view = viewClass.create(params, context);
}
if (!params.view) {