A platform for community discussion. Free, open, simple.
Add spec + make it work with .raw templates
osamasayeghfe8301007c0d
diff --git a/app/assets/javascripts/discourse/helpers/theme-setting-injector.es6 b/app/assets/javascripts/discourse/helpers/theme-setting-injector.es6index 4a0d5916efd..a9da2e70d31 100644--- a/app/assets/javascripts/discourse/helpers/theme-setting-injector.es6+++ b/app/assets/javascripts/discourse/helpers/theme-setting-injector.es6@@ -4,10 +4,7 @@import { registerHelper } from 'discourse-common/lib/helpers';-registerHelper('theme-setting-injector', function(arr, hash) {- const context = hash.context;- let value = hash.value;-+function inject(context, key, value) {if (typeof value === "string") {value = value.replace(/\\u0022/g, '"');}@@ -15,5 +12,13 @@ registerHelper('theme-setting-injector', function(arr, hash) {if (!context.get("themeSettings")) {context.set("themeSettings", {});}- context.set(`themeSettings.${hash.key}`, value);+ context.set(`themeSettings.${key}`, value);+}++registerHelper('theme-setting-injector', function(arr, hash) {+ inject(hash.context, hash.key, hash.value);+});++Handlebars.registerHelper('theme-setting-injector', function(hash) {+ inject(hash.data.root, hash.hash.key, hash.hash.value);});diff --git a/spec/models/theme_field_spec.rb b/spec/models/theme_field_spec.rbindex 0f9677780bf..8ec0a5249b1 100644--- a/spec/models/theme_field_spec.rb+++ b/spec/models/theme_field_spec.rb@@ -21,6 +21,22 @@ HTMLexpect(field.error).to eq(nil)end+ it "allows us to use theme settings in handlebars templates" do+ html = <<HTML+<script type='text/x-handlebars' data-template-name='my-template'>+ <div class="testing-div">{{themeSettings.string_setting}}</div>+</script>+HTML++ ThemeField.create!(theme_id: 1, target_id: 3, name: "yaml", value: "string_setting: \"test text \\\" 123!\"")+ baked_value = ThemeField.create!(theme_id: 1, target_id: 0, name: "head_tag", value: html).value_baked++ expect(baked_value).to include("testing-div")+ expect(baked_value).to include("theme-setting-injector")+ expect(baked_value).to include("string_setting")+ expect(baked_value).to include("test text \\\\\\\\u0022 123!")+ end+it "correctly generates errors for transpiled css" docss = "body {"field = ThemeField.create!(theme_id: 1, target_id: 0, name: "scss", value: css)