mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 17:46:05 -05:00
Fallback to using the first list if [poll] isn't present.
This commit is contained in:
parent
ac8203b601
commit
33cb4bc5ac
3 changed files with 18 additions and 4 deletions
|
@ -97,7 +97,13 @@ Discourse.PostView.reopen({
|
||||||
}
|
}
|
||||||
|
|
||||||
var view = initializePollView(this);
|
var view = initializePollView(this);
|
||||||
view.replaceElement($post.find(".poll-ui:first"));
|
|
||||||
|
var pollContainer = $post.find(".poll-ui:first");
|
||||||
|
if (pollContainer.length == 0) {
|
||||||
|
pollContainer = $post.find("ul:first");
|
||||||
|
}
|
||||||
|
|
||||||
|
view.replaceElement(pollContainer);
|
||||||
this.set('pollView', view);
|
this.set('pollView', view);
|
||||||
|
|
||||||
}.on('postViewInserted'),
|
}.on('postViewInserted'),
|
||||||
|
|
|
@ -26,9 +26,10 @@ module ::PollPlugin
|
||||||
|
|
||||||
def options
|
def options
|
||||||
cooked = PrettyText.cook(@post.raw, topic_id: @post.topic_id)
|
cooked = PrettyText.cook(@post.raw, topic_id: @post.topic_id)
|
||||||
poll_div = Nokogiri::HTML(cooked).css(".poll-ui").first
|
parsed = Nokogiri::HTML(cooked)
|
||||||
if poll_div
|
poll_list = parsed.css(".poll-ui ul").first || parsed.css("ul").first
|
||||||
poll_div.css("li").map {|x| x.children.to_s.strip }.uniq
|
if poll_list
|
||||||
|
poll_list.css("li").map {|x| x.children.to_s.strip }.uniq
|
||||||
else
|
else
|
||||||
[]
|
[]
|
||||||
end
|
end
|
||||||
|
|
|
@ -18,6 +18,13 @@ describe PollPlugin::Poll do
|
||||||
expect(poll.options).to eq(["Chitoge", "Onodera"])
|
expect(poll.options).to eq(["Chitoge", "Onodera"])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should fall back to using the first list if [poll] markup is not present" do
|
||||||
|
topic = create_topic(title: "This is not a poll topic")
|
||||||
|
post = create_post(topic: topic, raw: "Pick one.\n\n* Chitoge\n* Onodera")
|
||||||
|
poll = PollPlugin::Poll.new(post)
|
||||||
|
expect(poll.options).to eq(["Chitoge", "Onodera"])
|
||||||
|
end
|
||||||
|
|
||||||
it "should get details correctly" do
|
it "should get details correctly" do
|
||||||
expect(poll.details).to eq({"Chitoge" => 0, "Onodera" => 0})
|
expect(poll.details).to eq({"Chitoge" => 0, "Onodera" => 0})
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue