FIX: Allow raw-view classes to be resolved from themes/plugins (#12685)

FIX: Allow raw-view classes to be resolved from themes/plugins (#12685)

Since cd24eff5d98e74db4afe0257e4d9de1ad2556c5d, 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.

diff --git a/app/assets/javascripts/discourse/app/helpers/raw.js b/app/assets/javascripts/discourse/app/helpers/raw.js
index b34a0fc..c9dd07f 100644
--- a/app/assets/javascripts/discourse/app/helpers/raw.js
+++ b/app/assets/javascripts/discourse/app/helpers/raw.js
@@ -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) {

GitHub sha: da6edc11

This commit appears in #12685 which was approved by OsamaSayegh. It was merged by davidtaylorhq.