mirror of
https://github.com/discourse/discourse.git
synced 2025-02-16 18:24:52 -06:00
DEV: move raw handlebars to /raw-templates/ (#22574)
The primary motivation is to simplify `eagerLoadRawTemplateModules` which curently introspects the module dependencies (the `imports` at runtime). This is no longer supported in Embroider as the AMD shims do not have any dependencies (since it's managed internally with webpack).
This commit is contained in:
parent
380890d28b
commit
4d62c49e20
@ -1,4 +1,5 @@
|
||||
import { getResolverOption } from "discourse-common/resolver";
|
||||
import require from "require";
|
||||
|
||||
export const __DISCOURSE_RAW_TEMPLATES = {};
|
||||
|
||||
@ -45,11 +46,8 @@ export function buildRawConnectorCache(findOutlets) {
|
||||
}
|
||||
|
||||
export function eagerLoadRawTemplateModules() {
|
||||
for (const [key, value] of Object.entries(requirejs.entries)) {
|
||||
if (
|
||||
key.includes("/templates/") &&
|
||||
value.deps.includes("discourse-common/lib/raw-templates")
|
||||
) {
|
||||
for (const key of Object.keys(requirejs.entries)) {
|
||||
if (key.includes("/raw-templates/")) {
|
||||
require(key);
|
||||
}
|
||||
}
|
||||
|
@ -141,9 +141,9 @@ TemplateCompiler.prototype.processString = function (string, relativePath) {
|
||||
if (pluginName) {
|
||||
filename = relativePath
|
||||
.replace(`discourse/plugins/${pluginName}/`, "")
|
||||
.replace(/^(discourse\/)?templates\//, "javascripts/");
|
||||
.replace(/^(discourse\/)?raw-templates\//, "javascripts/");
|
||||
} else {
|
||||
filename = relativePath.replace(/^templates\//, "");
|
||||
filename = relativePath.replace(/^raw-templates\//, "");
|
||||
}
|
||||
|
||||
filename = filename.replace(/\.hbr$/, "");
|
||||
|
@ -15,9 +15,16 @@ function fixLegacyExtensions(tree) {
|
||||
getDestinationPath: function (relativePath) {
|
||||
if (relativePath.endsWith(".es6")) {
|
||||
return relativePath.slice(0, -4);
|
||||
} else if (relativePath.endsWith(".raw.hbs")) {
|
||||
return relativePath.replace(".raw.hbs", ".hbr");
|
||||
} else if (relativePath.includes("/templates/")) {
|
||||
if (relativePath.endsWith(".raw.hbs")) {
|
||||
relativePath = relativePath.replace(".raw.hbs", ".hbr");
|
||||
}
|
||||
|
||||
if (relativePath.endsWith(".hbr")) {
|
||||
return relativePath.replace("/templates/", "/raw-templates/");
|
||||
}
|
||||
}
|
||||
|
||||
return relativePath;
|
||||
},
|
||||
});
|
||||
|
@ -97,8 +97,14 @@ class ThemeJavascriptCompiler
|
||||
tree.transform_keys! do |filename|
|
||||
if filename.ends_with? ".js.es6"
|
||||
filename.sub(/\.js\.es6\z/, ".js")
|
||||
elsif filename.ends_with? ".raw.hbs"
|
||||
filename.sub(/\.raw\.hbs\z/, ".hbr")
|
||||
elsif filename.include? "/templates/"
|
||||
filename = filename.sub(/\.raw\.hbs\z/, ".hbr") if filename.ends_with? ".raw.hbs"
|
||||
|
||||
if filename.ends_with? ".hbr"
|
||||
filename.sub(%r{/templates/}, "/raw-templates/")
|
||||
else
|
||||
filename
|
||||
end
|
||||
else
|
||||
filename
|
||||
end
|
||||
@ -168,7 +174,7 @@ class ThemeJavascriptCompiler
|
||||
elsif extension == "hbs"
|
||||
append_ember_template(module_name, content)
|
||||
elsif extension == "hbr"
|
||||
append_raw_template(module_name.sub("discourse/templates/", ""), content)
|
||||
append_raw_template(module_name.sub("discourse/raw-templates/", ""), content)
|
||||
else
|
||||
append_js_error(filename, "unknown file extension '#{extension}' (#{filename})")
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user