mirror of
https://github.com/discourse/discourse.git
synced 2025-03-06 11:19:51 +00:00
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 (
|
module.exports = class DiscoursePluginColocatedTemplateProcessor extends (
|
||||||
ColocatedTemplateProcessor
|
ColocatedTemplateProcessor
|
||||||
) {
|
) {
|
||||||
constructor(tree, discoursePluginName) {
|
constructor(tree, rootName) {
|
||||||
super(tree);
|
super(tree);
|
||||||
this.discoursePluginName = discoursePluginName;
|
this.rootName = rootName;
|
||||||
}
|
}
|
||||||
|
|
||||||
detectRootName() {
|
detectRootName() {
|
||||||
return `discourse/plugins/${this.discoursePluginName}/discourse`;
|
return this.rootName;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -176,7 +176,15 @@ module.exports = {
|
|||||||
|
|
||||||
tree = RawHandlebarsCompiler(tree);
|
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.compileTemplates(tree);
|
||||||
|
|
||||||
tree = this.processedAddonJsFiles(tree);
|
tree = this.processedAddonJsFiles(tree);
|
||||||
|
@ -89,8 +89,6 @@ class ThemeJavascriptCompiler
|
|||||||
end
|
end
|
||||||
|
|
||||||
def append_tree(tree, for_tests: false)
|
def append_tree(tree, for_tests: false)
|
||||||
root_name = "discourse"
|
|
||||||
|
|
||||||
# Replace legacy extensions
|
# Replace legacy extensions
|
||||||
tree.transform_keys! do |filename|
|
tree.transform_keys! do |filename|
|
||||||
if filename.ends_with? ".js.es6"
|
if filename.ends_with? ".js.es6"
|
||||||
@ -121,7 +119,7 @@ class ThemeJavascriptCompiler
|
|||||||
|
|
||||||
# Handle colocated components
|
# Handle colocated components
|
||||||
tree.dup.each_pair do |filename, content|
|
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
|
next if !is_component_template
|
||||||
template_contents = content
|
template_contents = content
|
||||||
|
|
||||||
|
@ -110,6 +110,20 @@ RSpec.describe ThemeJavascriptCompiler do
|
|||||||
expect(compiler.raw_content).to include("setComponentTemplate")
|
expect(compiler.raw_content).to include("setComponentTemplate")
|
||||||
end
|
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
|
it "applies theme AST transforms to colocated components" do
|
||||||
compiler = ThemeJavascriptCompiler.new(12345678910, 'my theme name')
|
compiler = ThemeJavascriptCompiler.new(12345678910, 'my theme name')
|
||||||
compiler.append_tree(
|
compiler.append_tree(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user