DEV: Support colocation under `/admin` namespace in themes/plugins (#19353)
This commit is contained in:
parent
f2d0832618
commit
566793208e
|
@ -3,12 +3,12 @@ const ColocatedTemplateProcessor = require("ember-cli-htmlbars/lib/colocated-bro
|
|||
module.exports = class DiscoursePluginColocatedTemplateProcessor extends (
|
||||
ColocatedTemplateProcessor
|
||||
) {
|
||||
constructor(tree, discoursePluginName) {
|
||||
constructor(tree, rootName) {
|
||||
super(tree);
|
||||
this.discoursePluginName = discoursePluginName;
|
||||
this.rootName = rootName;
|
||||
}
|
||||
|
||||
detectRootName() {
|
||||
return `discourse/plugins/${this.discoursePluginName}/discourse`;
|
||||
return this.rootName;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -176,7 +176,15 @@ module.exports = {
|
|||
|
||||
tree = RawHandlebarsCompiler(tree);
|
||||
|
||||
tree = new DiscoursePluginColocatedTemplateProcessor(tree, pluginName);
|
||||
const colocateBase = `discourse/plugins/${pluginName}`;
|
||||
tree = new DiscoursePluginColocatedTemplateProcessor(
|
||||
tree,
|
||||
`${colocateBase}/discourse`
|
||||
);
|
||||
tree = new DiscoursePluginColocatedTemplateProcessor(
|
||||
tree,
|
||||
`${colocateBase}/admin`
|
||||
);
|
||||
tree = this.compileTemplates(tree);
|
||||
|
||||
tree = this.processedAddonJsFiles(tree);
|
||||
|
|
|
@ -89,8 +89,6 @@ class ThemeJavascriptCompiler
|
|||
end
|
||||
|
||||
def append_tree(tree, for_tests: false)
|
||||
root_name = "discourse"
|
||||
|
||||
# Replace legacy extensions
|
||||
tree.transform_keys! do |filename|
|
||||
if filename.ends_with? ".js.es6"
|
||||
|
@ -121,7 +119,7 @@ class ThemeJavascriptCompiler
|
|||
|
||||
# Handle colocated components
|
||||
tree.dup.each_pair do |filename, content|
|
||||
is_component_template = filename.end_with?(".hbs") && filename.start_with?("#{root_name}/components/")
|
||||
is_component_template = filename.end_with?(".hbs") && filename.start_with?("discourse/components/", "admin/components/")
|
||||
next if !is_component_template
|
||||
template_contents = content
|
||||
|
||||
|
|
|
@ -110,6 +110,20 @@ RSpec.describe ThemeJavascriptCompiler do
|
|||
expect(compiler.raw_content).to include("setComponentTemplate")
|
||||
end
|
||||
|
||||
it "handles colocated admin components" do
|
||||
compiler.append_tree(
|
||||
{
|
||||
"admin/components/mycomponent.js" => <<~JS,
|
||||
import Component from "@glimmer/component";
|
||||
export default class MyComponent extends Component {}
|
||||
JS
|
||||
"admin/components/mycomponent.hbs" => "{{my-component-template}}"
|
||||
}
|
||||
)
|
||||
expect(compiler.raw_content).to include("__COLOCATED_TEMPLATE__ =")
|
||||
expect(compiler.raw_content).to include("setComponentTemplate")
|
||||
end
|
||||
|
||||
it "applies theme AST transforms to colocated components" do
|
||||
compiler = ThemeJavascriptCompiler.new(12345678910, 'my theme name')
|
||||
compiler.append_tree(
|
||||
|
|
Loading…
Reference in New Issue