DEV: Drop the deprecated themeSettings.blah syntax (#17394)

This syntax has been printing deprecation messages since 880311dd4d
This commit is contained in:
David Taylor 2022-07-18 10:10:23 +01:00 committed by GitHub
parent ab05d931a0
commit fab1c00c8f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 6 additions and 115 deletions

View File

@ -1,6 +1,5 @@
import { registerUnbound } from "discourse-common/lib/helpers";
import I18n from "I18n";
import deprecated from "discourse-common/lib/deprecated";
import { getSetting as getThemeSetting } from "discourse/lib/theme-settings-store";
registerUnbound("theme-i18n", (themeId, key, params) => {
@ -12,13 +11,6 @@ registerUnbound(
(themeId, key) => `theme_translations.${themeId}.${key}`
);
registerUnbound("theme-setting", (themeId, key, hash) => {
if (hash.deprecated) {
deprecated(
"The `{{themeSetting.setting_name}}` syntax is deprecated. Use `{{theme-setting 'setting_name'}}` instead",
{ since: "v2.2.0.beta8" }
);
}
registerUnbound("theme-setting", (themeId, key) => {
return getThemeSetting(themeId, key);
});

View File

@ -6,7 +6,7 @@ require 'json_schemer'
class Theme < ActiveRecord::Base
include GlobalPath
BASE_COMPILER_VERSION = 56
BASE_COMPILER_VERSION = 57
attr_accessor :child_components

View File

@ -10,59 +10,6 @@ class ThemeJavascriptCompiler
def discourse_node_manipulator
<<~JS
// Helper to replace old themeSetting syntax
function generateHelper(settingParts) {
const settingName = settingParts.join('.');
return {
"path": {
"type": "PathExpression",
"original": "theme-setting",
"this": false,
"data": false,
"parts": [
"theme-setting"
],
"depth":0
},
"params": [
{
type: "NumberLiteral",
value: #{@theme_id},
original: #{@theme_id}
},
{
"type": "StringLiteral",
"value": settingName,
"original": settingName
}
],
"hash": {
"type": "Hash",
"pairs": [
{
"type": "HashPair",
"key": "deprecated",
"value": {
"type": "BooleanLiteral",
"value": true,
"original": true
}
}
]
}
}
}
function manipulatePath(path) {
// Override old themeSetting syntax when it's a param inside another node
if(path.parts && path.parts[0] == "themeSettings"){
const settingParts = path.parts.slice(1);
path.type = "SubExpression";
Object.assign(path, generateHelper(settingParts))
}
}
function manipulateNode(node) {
// Magically add theme id as the first param for each of these helpers)
if (node.path.parts && ["theme-i18n", "theme-prefix", "theme-setting"].includes(node.path.parts[0])) {
@ -74,11 +21,6 @@ class ThemeJavascriptCompiler
})
}
}
// Override old themeSetting syntax when it's in its own node
if (node.path.parts && node.path.parts[0] == "themeSettings") {
Object.assign(node, generateHelper(node.path.parts.slice(1)))
}
}
JS
end
@ -95,31 +37,13 @@ class ThemeJavascriptCompiler
<<~JS
let _superCompile = Handlebars.Compiler.prototype.compile;
Handlebars.Compiler.prototype.compile = function(program, options) {
// `replaceGet()` in raw-handlebars.js.es6 adds a `get` in front of things
// so undo this specific case for the old themeSettings.blah syntax
let visitor = new Handlebars.Visitor();
visitor.mutating = true;
visitor.MustacheStatement = (node) => {
if(node.path.original == 'get'
&& node.params
&& node.params[0]
&& node.params[0].parts
&& node.params[0].parts[0] == 'themeSettings'){
node.path.parts = node.params[0].parts
node.params = []
}
};
visitor.accept(program);
[
["SubExpression", manipulateNode],
["MustacheStatement", manipulateNode],
["PathExpression", manipulatePath]
"SubExpression",
"MustacheStatement"
].forEach((pass) => {
let visitor = new Handlebars.Visitor();
visitor.mutating = true;
visitor[pass[0]] = pass[1];
visitor[pass] = manipulateNode;
visitor.accept(program);
})
@ -139,8 +63,7 @@ class ThemeJavascriptCompiler
name: 'theme-template-manipulator',
visitor: {
SubExpression: manipulateNode,
MustacheStatement: manipulateNode,
PathExpression: manipulatePath
MustacheStatement: manipulateNode
}
}
});

View File

@ -52,15 +52,6 @@ describe ThemeJavascriptCompiler do
to eq('dummy(theme_translations.22.translation_key)')
end
it 'works with the old settings syntax' do
expect(render("{{themeSettings.setting_key}}")).
to eq('setting(22:setting_key)')
# Works when used inside other statements
expect(render("{{dummy-helper themeSettings.setting_key}}")).
to eq('dummy(setting(22:setting_key))')
end
it "doesn't duplicate number parameter inside {{each}}" do
expect(compiler.compile("{{#each item as |test test2|}}{{theme-setting 'setting_key'}}{{/each}}")).
to include('{"name":"theme-setting","hash":{},"hashTypes":{},"hashContexts":{},"types":["NumberLiteral","StringLiteral"]')
@ -112,21 +103,6 @@ describe ThemeJavascriptCompiler do
standard_compile "{{dummy-helper (theme-prefix #{theme_id} 'translation_key')}}"
)
end
it 'works with the old settings syntax' do
expect(
theme_compile "{{themeSettings.setting_key}}"
).to eq(
standard_compile "{{theme-setting #{theme_id} 'setting_key' deprecated=true}}"
)
# Works when used inside other statements
expect(
theme_compile "{{dummy-helper themeSettings.setting_key}}"
).to eq(
standard_compile "{{dummy-helper (theme-setting #{theme_id} 'setting_key' deprecated=true)}}"
)
end
end
describe "#append_raw_template" do