mirror of
https://github.com/discourse/discourse.git
synced 2024-12-04 09:53:43 +08:00
4d62c49e20
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).
55 lines
1.4 KiB
JavaScript
55 lines
1.4 KiB
JavaScript
import { getResolverOption } from "discourse-common/resolver";
|
|
import require from "require";
|
|
|
|
export const __DISCOURSE_RAW_TEMPLATES = {};
|
|
|
|
export function addRawTemplate(name, template, opts = {}) {
|
|
// Core templates should never overwrite themes / plugins
|
|
if (opts.core && __DISCOURSE_RAW_TEMPLATES[name]) {
|
|
return;
|
|
}
|
|
__DISCOURSE_RAW_TEMPLATES[name] = template;
|
|
}
|
|
|
|
export function removeRawTemplate(name) {
|
|
delete __DISCOURSE_RAW_TEMPLATES[name];
|
|
}
|
|
|
|
export function findRawTemplate(name) {
|
|
if (getResolverOption("mobileView")) {
|
|
return (
|
|
__DISCOURSE_RAW_TEMPLATES[`javascripts/mobile/${name}`] ||
|
|
__DISCOURSE_RAW_TEMPLATES[`javascripts/${name}`] ||
|
|
__DISCOURSE_RAW_TEMPLATES[`mobile/${name}`] ||
|
|
__DISCOURSE_RAW_TEMPLATES[name]
|
|
);
|
|
}
|
|
|
|
return (
|
|
__DISCOURSE_RAW_TEMPLATES[`javascripts/${name}`] ||
|
|
__DISCOURSE_RAW_TEMPLATES[name]
|
|
);
|
|
}
|
|
|
|
export function buildRawConnectorCache(findOutlets) {
|
|
let result = {};
|
|
findOutlets(
|
|
Object.keys(__DISCOURSE_RAW_TEMPLATES),
|
|
(outletName, resource) => {
|
|
result[outletName] ??= [];
|
|
result[outletName].push({
|
|
template: __DISCOURSE_RAW_TEMPLATES[resource],
|
|
});
|
|
}
|
|
);
|
|
return result;
|
|
}
|
|
|
|
export function eagerLoadRawTemplateModules() {
|
|
for (const key of Object.keys(requirejs.entries)) {
|
|
if (key.includes("/raw-templates/")) {
|
|
require(key);
|
|
}
|
|
}
|
|
}
|