mirror of
https://github.com/discourse/discourse.git
synced 2025-06-04 23:36:11 +08:00
DEV: Remove INLINE_ONEBOX_* constants
There were two constants here, `INLINE_ONEBOX_LOADING_CSS_CLASS` and `INLINE_ONEBOX_CSS_CLASS` that were both longer than the strings they were DRYing up: `inline-onebox-loading` and `inline-onebox` I normally appreciate constants, but in this case it meant that we had a lot of JS imports resulting in many more lines of code (and CPU cycles spent figuring them out.) It also meant we had an `.erb` file and had to invoke Ruby to create the JS file, which meant the app was harder to port to Ember CLI. I removed the constants. It's less DRY but faster and simpler, and arguably the loss of DRYness is not significant as you can still search for the `inline-onebox-loading` and `inline-onebox` strings easily if you are refactoring.
This commit is contained in:
@ -4,8 +4,6 @@
|
||||
# For example, inserting the onebox content, or image sizes/thumbnails.
|
||||
|
||||
class CookedPostProcessor
|
||||
INLINE_ONEBOX_LOADING_CSS_CLASS = "inline-onebox-loading"
|
||||
INLINE_ONEBOX_CSS_CLASS = "inline-onebox"
|
||||
LIGHTBOX_WRAPPER_CSS_CLASS = "lightbox-wrapper"
|
||||
LOADING_SIZE = 10
|
||||
LOADING_COLORS = 32
|
||||
@ -518,7 +516,7 @@ class CookedPostProcessor
|
||||
oneboxes = {}
|
||||
inlineOneboxes = {}
|
||||
|
||||
Oneboxer.apply(@doc, extra_paths: [".#{INLINE_ONEBOX_LOADING_CSS_CLASS}"]) do |url, element|
|
||||
Oneboxer.apply(@doc, extra_paths: [".inline-onebox-loading"]) do |url, element|
|
||||
is_onebox = element["class"] == Oneboxer::ONEBOX_CSS_CLASS
|
||||
map = is_onebox ? oneboxes : inlineOneboxes
|
||||
skip_onebox = limit <= 0 && !map[url]
|
||||
@ -724,14 +722,14 @@ class CookedPostProcessor
|
||||
|
||||
if title = inline_onebox&.dig(:title)
|
||||
element.children = CGI.escapeHTML(title)
|
||||
element.add_class(INLINE_ONEBOX_CSS_CLASS)
|
||||
element.add_class("inline-onebox")
|
||||
end
|
||||
|
||||
remove_inline_onebox_loading_class(element)
|
||||
end
|
||||
|
||||
def remove_inline_onebox_loading_class(element)
|
||||
element.remove_class(INLINE_ONEBOX_LOADING_CSS_CLASS)
|
||||
element.remove_class("inline-onebox-loading")
|
||||
end
|
||||
|
||||
def is_svg?(img)
|
||||
|
Reference in New Issue
Block a user