mirror of
https://github.com/discourse/discourse.git
synced 2024-11-27 03:10:46 -06:00
Add spec + make it work with .raw templates
This commit is contained in:
parent
ce1a6f2fd8
commit
fe8301007c
@ -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);
|
||||
});
|
||||
|
@ -21,6 +21,22 @@ HTML
|
||||
expect(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" do
|
||||
css = "body {"
|
||||
field = ThemeField.create!(theme_id: 1, target_id: 0, name: "scss", value: css)
|
||||
|
Loading…
Reference in New Issue
Block a user