FEATURE: Allow theme settings to request refresh (#15037)

Similar to site settings, adds support for `refresh` option to theme settings.

```yaml
super_feature_enabled:
  type: bool
  default: false
  refresh: true
```
This commit is contained in:
Jarek Radosz
2021-11-22 13:16:56 +01:00
committed by GitHub
parent f43c433d50
commit d91d67a442
5 changed files with 63 additions and 0 deletions

View File

@ -94,6 +94,13 @@ class Theme < ActiveRecord::Base
clear_cached_settings!
DB.after_commit { ColorScheme.hex_cache.clear }
notify_theme_change(with_scheme: notify_with_scheme)
if theme_setting_requests_refresh
DB.after_commit do
Discourse.request_refresh!
self.theme_setting_requests_refresh = false
end
end
end
def update_child_components
@ -572,6 +579,10 @@ class Theme < ActiveRecord::Base
raise Discourse::NotFound unless target_setting
target_setting.value = new_value
if target_setting.requests_refresh?
self.theme_setting_requests_refresh = true
end
end
def update_translation(translation_key, new_value)
@ -727,6 +738,8 @@ class Theme < ActiveRecord::Base
private
attr_accessor :theme_setting_requests_refresh
def to_scss_variable(name, value)
escaped = SassC::Script::Value::String.quote(value, sass: true)
"$#{name}: unquote(#{escaped});"