FEATURE: detect theme errors and catch them (#7589)

* FEATURE: detect theme errors and catch them

* Bump COMPILER_VERSION

* Feedback

* Override eslint no console for one line

* Can't use our ajax method

* remove emoji from translation file
This commit is contained in:
Osama Sayegh
2019-05-24 17:25:55 +03:00
committed by GitHub
parent a51e2271af
commit e20c30987c
7 changed files with 97 additions and 6 deletions

View File

@ -109,6 +109,24 @@ describe Theme do
expect(Theme.lookup_field(theme.id, :desktop, "head_tag")).to eq("<b>I am bold</b>")
end
it "changing theme name should re-transpile HTML theme fields" do
theme.update!(name: "old_name")
html = <<~HTML
<script type='text/discourse-plugin' version='0.1'>
const x = 1;
</script>
HTML
theme.set_field(target: :common, name: "head_tag", value: html)
theme.save!
field = theme.theme_fields.where(value: html).first
old_value = field.value_baked
theme.update!(name: "new_name")
field.reload
new_value = field.value_baked
expect(old_value).not_to eq(new_value)
end
it 'should precompile fragments in body and head tags' do
with_template = <<HTML
<script type='text/x-handlebars' name='template'>
@ -329,6 +347,7 @@ HTML
end
it "allows values to be used in JS" do
theme.name = 'awesome theme"'
theme.set_field(target: :settings, name: :yaml, value: "name: bob")
theme_field = theme.set_field(target: :common, name: :after_header, value: '<script type="text/discourse-plugin" version="1.0">alert(settings.name); let a = ()=>{};</script>')
theme.save!
@ -343,12 +362,18 @@ HTML
})();
(function () {
if ('Discourse' in window && typeof Discourse._registerPluginCode === 'function') {
var __theme_name__ = "awesome theme\\\"";
var settings = Discourse.__container__.lookup("service:theme-settings").getObjectForTheme(#{theme.id});
var themePrefix = function themePrefix(key) {
return 'theme_translations.#{theme.id}.' + key;
};
Discourse._registerPluginCode('1.0', function (api) {
alert(settings.name);var a = function a() {};
try {
alert(settings.name);var a = function a() {};
} catch (err) {
var rescue = require("discourse/lib/utilities").rescueThemeError;
rescue(__theme_name__, err, api);
}
});
}
})();
@ -372,12 +397,18 @@ HTML
})();
(function () {
if ('Discourse' in window && typeof Discourse._registerPluginCode === 'function') {
var __theme_name__ = "awesome theme\\\"";
var settings = Discourse.__container__.lookup("service:theme-settings").getObjectForTheme(#{theme.id});
var themePrefix = function themePrefix(key) {
return 'theme_translations.#{theme.id}.' + key;
};
Discourse._registerPluginCode('1.0', function (api) {
alert(settings.name);var a = function a() {};
try {
alert(settings.name);var a = function a() {};
} catch (err) {
var rescue = require("discourse/lib/utilities").rescueThemeError;
rescue(__theme_name__, err, api);
}
});
}
})();