2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2025-08-20 18:52:44 +08:00

clean up onebox application so it uses a single code path

use fragments for oneboxes
strip parent <p> if <div> is in it
clean some tests
This commit is contained in:
Sam 2013-04-10 17:52:38 +10:00
parent ab9c55689e
commit 33e3ad1603
6 changed files with 90 additions and 29 deletions

View file

@ -10,7 +10,7 @@ class CookedPostProcessor
@dirty = false
@opts = opts
@post = post
@doc = Nokogiri::HTML(post.cooked)
@doc = Nokogiri::HTML::fragment(post.cooked)
@size_cache = {}
end
@ -23,13 +23,10 @@ class CookedPostProcessor
args = {post_id: @post.id}
args[:invalidate_oneboxes] = true if @opts[:invalidate_oneboxes]
Oneboxer.each_onebox_link(@doc) do |url, element|
onebox, preview = Oneboxer.onebox(url, args)
if onebox
element.swap onebox
@dirty = true
end
result = Oneboxer.apply(@doc) do |url, element|
Oneboxer.onebox(url, args)
end
@dirty ||= result.changed?
end
# First let's consider the images
@ -127,6 +124,10 @@ class CookedPostProcessor
@doc.try(:to_html)
end
def doc
@doc
end
def get_size(url)
return nil unless SiteSetting.crawl_images? || url.start_with?(Discourse.base_url)
@size_cache[url] ||= FastImage.size(url)