mirror of
https://github.com/discourse/discourse.git
synced 2025-06-03 19:39:30 +08:00
FEATURE: Implement Onebox for posts including polls. (#7539)
This commit is contained in:

committed by
Régis Hanol

parent
c77bc525cb
commit
227c45107d
@ -22,6 +22,7 @@ en:
|
||||
poll_minimum_trust_level_to_create: "Define the minimum trust level needed to create polls."
|
||||
|
||||
poll:
|
||||
poll: "poll"
|
||||
invalid_argument: "Invalid value '%{value}' for argument '%{argument}'."
|
||||
|
||||
multiple_polls_without_name: "There are multiple polls without a name. Use the '<code>name</code>' attribute to uniquely identify your polls."
|
||||
|
@ -435,6 +435,13 @@ after_initialize do
|
||||
end
|
||||
end
|
||||
|
||||
on(:reduce_excerpt) do |doc, options|
|
||||
post = options[:post]
|
||||
doc.css("div.poll").each do |poll|
|
||||
poll.replace "<a href='#{UrlHelper.escape_uri(post.url)}'>#{I18n.t("poll.poll")}</a>"
|
||||
end
|
||||
end
|
||||
|
||||
on(:post_created) do |post|
|
||||
DiscoursePoll::Poll.schedule_jobs(post)
|
||||
|
||||
|
@ -119,4 +119,21 @@ describe PrettyText do
|
||||
expect(n cooked).to eq(n expected)
|
||||
|
||||
end
|
||||
|
||||
it 'can onebox posts' do
|
||||
post = Fabricate(:post, raw: <<~EOF)
|
||||
A post with a poll
|
||||
|
||||
[poll type=regular]
|
||||
* Hello
|
||||
* World
|
||||
[/poll]
|
||||
EOF
|
||||
|
||||
onebox = Oneboxer.onebox_raw(post.full_url, user_id: Fabricate(:user).id)
|
||||
doc = Nokogiri::HTML(onebox[:preview])
|
||||
|
||||
expect(onebox[:preview]).to include("A post with a poll")
|
||||
expect(onebox[:preview]).to include("<a href=\"#{post.url}\">poll</a>")
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user