-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract component to render answers additional information
- Loading branch information
Showing
5 changed files
with
102 additions
and
79 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
app/components/polls/questions/read_more_answer_component.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<div class="small-12 medium-6 column end answer <%= cycle("first", "") %>" id="answer_<%= answer.id %>"> | ||
<h3><%= answer.title %></h3> | ||
|
||
<% if answer.images.any? %> | ||
<%= render "polls/gallery", answer: answer %> | ||
<% end %> | ||
<% if answer.description.present? %> | ||
<div class="margin-top"> | ||
<div id="answer_description_<%= answer.id %>" class="answer-description short" data-toggler="short"> | ||
<%= wysiwyg(answer.description) %> | ||
</div> | ||
<div class="read-more"> | ||
<button type="button" id="read_more_<%= answer.id %>" | ||
data-toggle="answer_description_<%= answer.id %> read_more_<%= answer.id %> read_less_<%= answer.id %>" | ||
data-toggler="hide"> | ||
<%= t("polls.show.read_more", answer: answer.title) %> | ||
</button> | ||
<button type="button" id="read_less_<%= answer.id %>" | ||
data-toggle="answer_description_<%= answer.id %> read_more_<%= answer.id %> read_less_<%= answer.id %>" | ||
data-toggler="hide" | ||
class="hide"> | ||
<%= t("polls.show.read_less", answer: answer.title) %> | ||
</button> | ||
</div> | ||
</div> | ||
<% end %> | ||
<% if answer.documents.present? %> | ||
<div class="document-link"> | ||
<p> | ||
<span class="icon-document"></span> | ||
<strong><%= t("polls.show.documents") %></strong> | ||
</p> | ||
|
||
<% answer.documents.each do |document| %> | ||
<%= link_to document.title, | ||
document.attachment, | ||
target: "_blank", | ||
rel: "nofollow" %><br> | ||
<% end %> | ||
</div> | ||
<% end %> | ||
<% if answer.videos.present? %> | ||
<div class="video-link"> | ||
<p> | ||
<span class="icon-video"></span> | ||
<strong><%= t("polls.show.videos") %></strong> | ||
</p> | ||
|
||
<% answer.videos.each do |video| %> | ||
<%= link_to video.title, | ||
video.url, | ||
target: "_blank", | ||
rel: "nofollow" %><br> | ||
<% end %> | ||
</div> | ||
<% end %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class Polls::Questions::ReadMoreAnswerComponent < ApplicationComponent | ||
with_collection_parameter :answer | ||
attr_reader :answer | ||
delegate :wysiwyg, to: :helpers | ||
|
||
def initialize(answer:) | ||
@answer = answer | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
spec/components/polls/questions/read_more_answer_component_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
require "rails_helper" | ||
|
||
describe Polls::Questions::ReadMoreAnswerComponent do | ||
include Rails.application.routes.url_helpers | ||
let(:poll) { create(:poll) } | ||
let(:question) { create(:poll_question, poll: poll) } | ||
let(:answer) { create(:poll_question_answer, question: question) } | ||
|
||
it "renders answers with videos" do | ||
create(:poll_answer_video, answer: answer, title: "Awesome video", url: "youtube.com/watch?v=123") | ||
|
||
render_inline Polls::Questions::ReadMoreAnswerComponent.new(answer: answer) | ||
|
||
expect(page).to have_link("Awesome video", href: "youtube.com/watch?v=123") | ||
end | ||
|
||
it "renders answers with images" do | ||
create(:image, imageable: answer, title: "The yes movement") | ||
|
||
render_inline Polls::Questions::ReadMoreAnswerComponent.new(answer: answer) | ||
|
||
expect(page).to have_css "img[alt='The yes movement']" | ||
end | ||
|
||
it "renders answers with documents" do | ||
create(:document, documentable: answer, title: "The yes movement") | ||
|
||
render_inline Polls::Questions::ReadMoreAnswerComponent.new(answer: answer) | ||
|
||
expect(page).to have_link("The yes movement") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters