Skip to content

A platform for community discussion. Free, open, simple.

DEV: Remove duplicated methods (#16178)

Bianca Nenciuf317783e653a
diff --git a/lib/cooked_post_processor.rb b/lib/cooked_post_processor.rb
index ffeffe788e0..30092ed98a1 100644
--- a/lib/cooked_post_processor.rb
+++ b/lib/cooked_post_processor.rb
@@ -120,77 +120,6 @@ class CookedPostProcessor
)
end
- def add_image_placeholder!(img)
- src = img["src"].sub(/^https?:/i, "")
-
- if large_images.include?(src)
- return add_large_image_placeholder!(img)
- elsif broken_images.include?(src)
- return add_broken_image_placeholder!(img)
- end
-
- false
- end
-
- def add_large_image_placeholder!(img)
- url = img["src"]
-
- is_hyperlinked = is_a_hyperlink?(img)
-
- placeholder = create_node("div", "large-image-placeholder")
- img.add_next_sibling(placeholder)
- placeholder.add_child(img)
-
- a = create_link_node(nil, url, true)
- img.add_next_sibling(a)
-
- span = create_span_node("url", url)
- a.add_child(span)
- span.add_previous_sibling(create_icon_node("far-image"))
- span.add_next_sibling(
- create_span_node(
- "help",
- I18n.t(
- "upload.placeholders.too_large_humanized",
- max_size: ActiveSupport::NumberHelper.number_to_human_size(SiteSetting.max_image_size_kb.kilobytes)
- )
- )
- )
-
- # Only if the image is already linked
- if is_hyperlinked
- parent = placeholder.parent
- parent.add_next_sibling(placeholder)
-
- if parent.name == 'a' && parent["href"].present?
- if url == parent["href"]
- parent.remove
- else
- parent["class"] = "link"
- a.add_previous_sibling(parent)
-
- lspan = create_span_node("url", parent["href"])
- parent.add_child(lspan)
- lspan.add_previous_sibling(create_icon_node("link"))
- end
- end
- end
-
- img.remove
- true
- end
-
- def add_broken_image_placeholder!(img)
- img.name = "span"
- img.set_attribute("class", "broken-image")
- img.set_attribute("title", I18n.t("post.image_placeholder.broken"))
- img << "<svg class=\"fa d-icon d-icon-unlink svg-icon\" aria-hidden=\"true\"><use href=\"#unlink\"></use></svg>"
- img.remove_attribute("src")
- img.remove_attribute("width")
- img.remove_attribute("height")
- true
- end
-
def extract_images
# all images with a src attribute
@doc.css("img[src]") -