mirror of
https://github.com/discourse/discourse.git
synced 2025-05-24 01:03:41 +08:00
DEV: Support inline-hbs compilation in themes (#18112)
This commit makes a number of improvements to the DiscourseJsProcessor: 1. Remove dependence on the out-of-date Ember template compiler from the ember-rails gem; switch to modern template compiler 2. Refactor to make use of a proper module system with `define`/`require` 3. Introduce `babel-plugin-ember-template-compilation` to enable inline hbs compilation The `mini-loader` is upgraded to support relative lookup and `require.has`, so that these new JS packages work correctly.
This commit is contained in:
@ -35,4 +35,47 @@ RSpec.describe DiscourseJsProcessor do
|
||||
expect(DiscourseJsProcessor.skip_module?("// just some JS\nconsole.log()")).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
it "correctly transpiles widget hbs" do
|
||||
result = DiscourseJsProcessor.transpile(<<~JS, "blah", "blah/mymodule")
|
||||
import hbs from "discourse/widgets/hbs-compiler";
|
||||
const template = hbs`{{somevalue}}`;
|
||||
JS
|
||||
expect(result).to eq <<~JS.strip
|
||||
define("blah/mymodule", [], function () {
|
||||
"use strict";
|
||||
|
||||
const template = function (attrs, state) {
|
||||
var _r = [];
|
||||
|
||||
_r.push(somevalue);
|
||||
|
||||
return _r;
|
||||
};
|
||||
});
|
||||
JS
|
||||
end
|
||||
|
||||
it "correctly transpiles ember hbs" do
|
||||
result = DiscourseJsProcessor.transpile(<<~JS, "blah", "blah/mymodule")
|
||||
import { hbs } from 'ember-cli-htmlbars';
|
||||
const template = hbs`{{somevalue}}`;
|
||||
JS
|
||||
expect(result).to eq <<~JS.strip
|
||||
define("blah/mymodule", ["@ember/template-factory"], function (_templateFactory) {
|
||||
"use strict";
|
||||
|
||||
const template = (0, _templateFactory.createTemplateFactory)(
|
||||
/*
|
||||
{{somevalue}}
|
||||
*/
|
||||
{
|
||||
"id": null,
|
||||
"block": "[[[1,[34,0]]],[],false,[\\"somevalue\\"]]",
|
||||
"moduleName": "(unknown template module)",
|
||||
"isStrictMode": false
|
||||
});
|
||||
});
|
||||
JS
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user