A platform for community discussion. Free, open, simple.
DEV: Drop the deprecated `themeSettings.blah` syntax (#17394)
David Taylorfab1c00c8f83
diff --git a/app/assets/javascripts/discourse/app/helpers/theme-helpers.js b/app/assets/javascripts/discourse/app/helpers/theme-helpers.jsindex 10500dbeb72..d09180cd488 100644--- a/app/assets/javascripts/discourse/app/helpers/theme-helpers.js+++ b/app/assets/javascripts/discourse/app/helpers/theme-helpers.js@@ -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);});diff --git a/app/models/theme.rb b/app/models/theme.rbindex d82b5bd8486..5d54677311e 100644--- a/app/models/theme.rb+++ b/app/models/theme.rb@@ -6,7 +6,7 @@ require 'json_schemer'class Theme < ActiveRecord::Baseinclude GlobalPath- BASE_COMPILER_VERSION = 56+ BASE_COMPILER_VERSION = 57attr_accessor :child_componentsdiff --git a/lib/theme_javascript_compiler.rb b/lib/theme_javascript_compiler.rbindex 62e082c747d..b029041e539 100644--- a/lib/theme_javascript_compiler.rb+++ b/lib/theme_javascript_compiler.rb@@ -10,59 +10,6 @@ class ThemeJavascriptCompilerdef 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)))- }}JSend@@ -95,31 +37,13 @@ class ThemeJavascriptCompiler<<~JSlet _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 ThemeJavascriptCompilername: 'theme-template-manipulator',visitor: {SubExpression: manipulateNode,- MustacheStatement: manipulateNode,- PathExpression: manipulatePath+ MustacheStatement: manipulateNode}}});diff --git a/spec/lib/theme_javascript_compiler_spec.rb b/spec/lib/theme_javascript_compiler_spec.rbindex e3fcdda1362..b5ff5a4a0c4 100644--- a/spec/lib/theme_javascript_compiler_spec.rb+++ b/spec/lib/theme_javascript_compiler_spec.rb@@ -52,15 +52,6 @@ describe ThemeJavascriptCompiler doto 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}}" doexpect(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 dostandard_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)}}"- )- endenddescribe "#append_raw_template" do