mirror of
https://github.com/discourse/discourse.git
synced 2025-05-31 11:27:52 +08:00
DEV: Show warning message when using ember css selectors (#12036)
* DEV: Show warning message when using ember css selectors When editing the theme css via the admin UI a warning message will be displayed if it detects that the `#emberXXX` or `.ember-view` css selectors are being used. These are dynamic selectors that ember generates, but they can change so they should not be used. * Update error message text to be more helpful * Display a warning instead of erroring out This allows the theme to still be saved, but a warning is displayed. Updated the tests to check for the error message. Updated the pre tags css so that it wraps for long messages.
This commit is contained in:
@ -50,6 +50,10 @@ class ThemeField < ActiveRecord::Base
|
||||
@theme_var_type_ids ||= [2]
|
||||
end
|
||||
|
||||
def self.css_theme_type_ids
|
||||
@css_theme_type_ids ||= [0, 1]
|
||||
end
|
||||
|
||||
def self.force_recompilation!
|
||||
find_each do |field|
|
||||
field.compiler_version = 0
|
||||
@ -372,6 +376,8 @@ class ThemeField < ActiveRecord::Base
|
||||
result = compile_scss
|
||||
if contains_optimized_link?(self.value)
|
||||
self.error = I18n.t("themes.errors.optimized_link")
|
||||
elsif contains_ember_css_selector?(self.value)
|
||||
self.error = I18n.t("themes.ember_selector_error")
|
||||
else
|
||||
self.error = nil unless error.nil?
|
||||
end
|
||||
@ -390,6 +396,10 @@ class ThemeField < ActiveRecord::Base
|
||||
OptimizedImage::URL_REGEX.match?(text)
|
||||
end
|
||||
|
||||
def contains_ember_css_selector?(text)
|
||||
text.match(/#ember\d+|[.]ember-view/)
|
||||
end
|
||||
|
||||
class ThemeFileMatcher
|
||||
OPTIONS = %i{name type target}
|
||||
# regex: used to match file names to fields (import).
|
||||
|
Reference in New Issue
Block a user