mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
parent
ddd45d1419
commit
0d22beb81d
@ -9,10 +9,11 @@ class PostAnalyzer
|
|||||||
@raw = raw
|
@raw = raw
|
||||||
@topic_id = topic_id
|
@topic_id = topic_id
|
||||||
@onebox_urls = []
|
@onebox_urls = []
|
||||||
|
@found_oneboxes = false
|
||||||
end
|
end
|
||||||
|
|
||||||
def found_oneboxes?
|
def found_oneboxes?
|
||||||
@onebox_urls.present?
|
@found_oneboxes
|
||||||
end
|
end
|
||||||
|
|
||||||
def has_oneboxes?
|
def has_oneboxes?
|
||||||
@ -36,7 +37,9 @@ class PostAnalyzer
|
|||||||
result = Oneboxer.apply(cooked) do |url|
|
result = Oneboxer.apply(cooked) do |url|
|
||||||
@onebox_urls << url
|
@onebox_urls << url
|
||||||
Oneboxer.invalidate(url) if opts[:invalidate_oneboxes]
|
Oneboxer.invalidate(url) if opts[:invalidate_oneboxes]
|
||||||
Oneboxer.cached_onebox(url)
|
onebox = Oneboxer.cached_onebox(url)
|
||||||
|
@found_oneboxes = true if onebox.present?
|
||||||
|
onebox
|
||||||
end
|
end
|
||||||
|
|
||||||
cooked = result.to_html if result.changed?
|
cooked = result.to_html if result.changed?
|
||||||
@ -126,7 +129,7 @@ class PostAnalyzer
|
|||||||
|
|
||||||
# How many links are present in the post
|
# How many links are present in the post
|
||||||
def link_count
|
def link_count
|
||||||
raw_links.size
|
raw_links.size + @onebox_urls.size
|
||||||
end
|
end
|
||||||
|
|
||||||
def cooked_stripped
|
def cooked_stripped
|
||||||
|
@ -28,7 +28,7 @@ class CookedPostProcessor
|
|||||||
@cooking_options = @cooking_options.symbolize_keys
|
@cooking_options = @cooking_options.symbolize_keys
|
||||||
|
|
||||||
@doc = Nokogiri::HTML::fragment(post.cook(post.raw, @cooking_options))
|
@doc = Nokogiri::HTML::fragment(post.cook(post.raw, @cooking_options))
|
||||||
@has_oneboxes = @doc.css("aside.onebox").count > 0
|
@has_oneboxes = post.post_analyzer.found_oneboxes?
|
||||||
@size_cache = {}
|
@size_cache = {}
|
||||||
|
|
||||||
@disable_loading_image = !!opts[:disable_loading_image]
|
@disable_loading_image = !!opts[:disable_loading_image]
|
||||||
|
@ -268,6 +268,7 @@ describe DiscourseNarrativeBot::NewUserNarrative do
|
|||||||
|
|
||||||
describe 'onebox tutorial' do
|
describe 'onebox tutorial' do
|
||||||
before do
|
before do
|
||||||
|
Oneboxer.stubs(:cached_onebox).with('https://en.wikipedia.org/wiki/ROT13').returns('oneboxed Wikipedia')
|
||||||
narrative.set_data(user, state: :tutorial_onebox, topic_id: topic.id)
|
narrative.set_data(user, state: :tutorial_onebox, topic_id: topic.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ describe PostAnalyzer do
|
|||||||
before { Oneboxer.stubs(:onebox) }
|
before { Oneboxer.stubs(:onebox) }
|
||||||
|
|
||||||
it 'fetches the cached onebox for any urls in the post' do
|
it 'fetches the cached onebox for any urls in the post' do
|
||||||
Oneboxer.expects(:cached_onebox).with url
|
Oneboxer.expects(:cached_onebox).with(url).returns('something')
|
||||||
post_analyzer.cook(raw, options)
|
post_analyzer.cook(raw, options)
|
||||||
expect(post_analyzer.found_oneboxes?).to be(true)
|
expect(post_analyzer.found_oneboxes?).to be(true)
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user