mirror of
https://github.com/discourse/discourse.git
synced 2025-06-10 19:59:12 +08:00
DEV: Drop legacy topic-list and raw-handlebars compilation system (#32081)
This commit is contained in:
@ -136,72 +136,6 @@ RSpec.describe DiscourseJsProcessor do
|
||||
JS
|
||||
end
|
||||
|
||||
describe "Raw template theme transformations" do
|
||||
# For the raw templates, we can easily render them serverside, so let's do that
|
||||
|
||||
let(:compiler) { DiscourseJsProcessor::Transpiler.new }
|
||||
let(:theme_id) { 22 }
|
||||
|
||||
let(:helpers) { <<~JS }
|
||||
Handlebars.registerHelper('theme-prefix', function(themeId, string) {
|
||||
return `theme_translations.${themeId}.${string}`
|
||||
})
|
||||
Handlebars.registerHelper('theme-i18n', function(themeId, string) {
|
||||
return `translated(theme_translations.${themeId}.${string})`
|
||||
})
|
||||
Handlebars.registerHelper('theme-setting', function(themeId, string) {
|
||||
return `setting(${themeId}:${string})`
|
||||
})
|
||||
Handlebars.registerHelper('dummy-helper', function(string) {
|
||||
return `dummy(${string})`
|
||||
})
|
||||
JS
|
||||
|
||||
let(:mini_racer) do
|
||||
ctx = MiniRacer::Context.new
|
||||
ctx.eval(
|
||||
File.open(
|
||||
"#{Rails.root}/app/assets/javascripts/discourse/node_modules/handlebars/dist/handlebars.js",
|
||||
).read,
|
||||
)
|
||||
ctx.eval(helpers)
|
||||
ctx
|
||||
end
|
||||
|
||||
def render(template)
|
||||
compiled = compiler.compile_raw_template(template, theme_id: theme_id)
|
||||
mini_racer.eval "Handlebars.template(#{compiled.squish})({})"
|
||||
end
|
||||
|
||||
it "adds the theme id to the helpers" do
|
||||
# Works normally
|
||||
expect(render("{{theme-prefix 'translation_key'}}")).to eq(
|
||||
"theme_translations.22.translation_key",
|
||||
)
|
||||
expect(render("{{theme-i18n 'translation_key'}}")).to eq(
|
||||
"translated(theme_translations.22.translation_key)",
|
||||
)
|
||||
expect(render("{{theme-setting 'setting_key'}}")).to eq("setting(22:setting_key)")
|
||||
|
||||
# Works when used inside other statements
|
||||
expect(render("{{dummy-helper (theme-prefix 'translation_key')}}")).to eq(
|
||||
"dummy(theme_translations.22.translation_key)",
|
||||
)
|
||||
end
|
||||
|
||||
it "doesn't duplicate number parameter inside {{each}}" do
|
||||
expect(
|
||||
compiler.compile_raw_template(
|
||||
"{{#each item as |test test2|}}{{theme-setting 'setting_key'}}{{/each}}",
|
||||
theme_id: theme_id,
|
||||
),
|
||||
).to include(
|
||||
'{"name":"theme-setting","hash":{},"hashTypes":{},"hashContexts":{},"types":["NumberLiteral","StringLiteral"]',
|
||||
)
|
||||
# Fail would be if theme-setting is defined with types:["NumberLiteral","NumberLiteral","StringLiteral"]
|
||||
end
|
||||
end
|
||||
|
||||
describe "Ember template transformations" do
|
||||
# For the Ember (Glimmer) templates, serverside rendering is not trivial,
|
||||
# so we compile the expected result with the standard compiler and compare to the theme compiler
|
||||
|
Reference in New Issue
Block a user