Reuse code between feed components
They were all following the same format. Note we need to group the `see_all` translation keys together (the same way it's done with the `most_active` keys) so we don't have an unused translation warning. We're also moving the "see all" link in processes outside the feed content; the same way it's done in debates and proposals and removing unnecessary classes in the processes feed: the column class is causing the processes not to be aligned with the debates above them, and the margin bottom is not needed because the margin of the footer is already enough.
This commit is contained in:
@@ -2902,24 +2902,6 @@ table {
|
||||
}
|
||||
}
|
||||
|
||||
.feed-description {
|
||||
|
||||
p {
|
||||
font-size: $small-font-size;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.feed-content {
|
||||
|
||||
.debate,
|
||||
.proposal {
|
||||
margin-bottom: 0;
|
||||
margin-top: 0;
|
||||
padding: $line-height / 2 0;
|
||||
}
|
||||
}
|
||||
|
||||
.figure-card {
|
||||
display: flex;
|
||||
margin: 0 0 $line-height;
|
||||
|
||||
20
app/assets/stylesheets/widgets/feeds/feed.scss
Normal file
20
app/assets/stylesheets/widgets/feeds/feed.scss
Normal file
@@ -0,0 +1,20 @@
|
||||
.widget-feed {
|
||||
|
||||
.feed-description {
|
||||
|
||||
p {
|
||||
font-size: $small-font-size;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.feed-content {
|
||||
|
||||
.debate,
|
||||
.proposal {
|
||||
margin-bottom: 0;
|
||||
margin-top: 0;
|
||||
padding: $line-height / 2 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
20
app/assets/stylesheets/widgets/feeds/proposal.scss
Normal file
20
app/assets/stylesheets/widgets/feeds/proposal.scss
Normal file
@@ -0,0 +1,20 @@
|
||||
.feed-proposals .proposal {
|
||||
@include grid-row-nest;
|
||||
clear: both;
|
||||
|
||||
.feed-image {
|
||||
display: inline-block;
|
||||
height: rem-calc(120);
|
||||
overflow: hidden;
|
||||
width: 100%;
|
||||
|
||||
@include breakpoint(medium) {
|
||||
height: rem-calc(96);
|
||||
}
|
||||
|
||||
img {
|
||||
max-width: none;
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
.feed-proposals {
|
||||
|
||||
.proposal {
|
||||
clear: both;
|
||||
|
||||
.feed-image {
|
||||
display: inline-block;
|
||||
height: rem-calc(120);
|
||||
overflow: hidden;
|
||||
width: 100%;
|
||||
|
||||
@include breakpoint(medium) {
|
||||
height: rem-calc(96);
|
||||
}
|
||||
|
||||
img {
|
||||
max-width: none;
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
3
app/components/widgets/feeds/debate_component.html.erb
Normal file
3
app/components/widgets/feeds/debate_component.html.erb
Normal file
@@ -0,0 +1,3 @@
|
||||
<div class="debate">
|
||||
<strong><%= link_to debate.title, url_for(debate) %></strong>
|
||||
</div>
|
||||
7
app/components/widgets/feeds/debate_component.rb
Normal file
7
app/components/widgets/feeds/debate_component.rb
Normal file
@@ -0,0 +1,7 @@
|
||||
class Widgets::Feeds::DebateComponent < ApplicationComponent
|
||||
attr_reader :debate
|
||||
|
||||
def initialize(debate)
|
||||
@debate = debate
|
||||
end
|
||||
end
|
||||
@@ -1,13 +0,0 @@
|
||||
<div id="feed_debates" class="feed-debates">
|
||||
<div class="feed-content">
|
||||
<h3 class="title"><%= t("welcome.feed.most_active.#{feed.kind}") %></h3>
|
||||
|
||||
<% feed.items.each do |item| %>
|
||||
<div class="<%= item.class.to_s.parameterize(separator: "_") %>">
|
||||
<strong><%= link_to item.title, url_for(item) %></strong>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<%= link_to t("welcome.feed.see_all_debates"), debates_path, class: "see-all" %>
|
||||
</div>
|
||||
@@ -1,7 +0,0 @@
|
||||
class Widgets::Feeds::DebatesComponent < ApplicationComponent
|
||||
attr_reader :feed
|
||||
|
||||
def initialize(feed)
|
||||
@feed = feed
|
||||
end
|
||||
end
|
||||
11
app/components/widgets/feeds/feed_component.html.erb
Normal file
11
app/components/widgets/feeds/feed_component.html.erb
Normal file
@@ -0,0 +1,11 @@
|
||||
<div id="feed_<%= kind %>" class="widget-feed feed-<%= kind %>">
|
||||
<div class="feed-content">
|
||||
<h3 class="title"><%= t("welcome.feed.most_active.#{kind}") %></h3>
|
||||
|
||||
<% feed.items.each do |item| %>
|
||||
<%= render item_component_class.new(item) %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<%= link_to t("welcome.feed.see_all.#{kind}"), see_all_path, class: "see-all" %>
|
||||
</div>
|
||||
25
app/components/widgets/feeds/feed_component.rb
Normal file
25
app/components/widgets/feeds/feed_component.rb
Normal file
@@ -0,0 +1,25 @@
|
||||
class Widgets::Feeds::FeedComponent < ApplicationComponent
|
||||
attr_reader :feed
|
||||
delegate :kind, to: :feed
|
||||
|
||||
def initialize(feed)
|
||||
@feed = feed
|
||||
end
|
||||
|
||||
def see_all_path
|
||||
polymorphic_path(feed.items.model)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def item_component_class
|
||||
case kind
|
||||
when "proposals"
|
||||
Widgets::Feeds::ProposalComponent
|
||||
when "debates"
|
||||
Widgets::Feeds::DebateComponent
|
||||
when "processes"
|
||||
Widgets::Feeds::ProcessComponent
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,11 +1,7 @@
|
||||
<div class="row margin-bottom feeds-list feeds-participation">
|
||||
<% feeds.each do |feed| %>
|
||||
<% if feed_proposals?(feed) %>
|
||||
<%= render Widgets::Feeds::ProposalsComponent.new(feed) %>
|
||||
<% end %>
|
||||
|
||||
<% if feed_debates?(feed) %>
|
||||
<%= render Widgets::Feeds::DebatesComponent.new(feed) %>
|
||||
<% if feed_proposals?(feed) || feed_debates?(feed) %>
|
||||
<%= render Widgets::Feeds::FeedComponent.new(feed) %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
13
app/components/widgets/feeds/process_component.html.erb
Normal file
13
app/components/widgets/feeds/process_component.html.erb
Normal file
@@ -0,0 +1,13 @@
|
||||
<div class="legislation-process card">
|
||||
<%= link_to url_for(process) do %>
|
||||
<figure class="figure-card">
|
||||
<%= image_tag("welcome_process.png", alt: "") %>
|
||||
<figcaption>
|
||||
<span><%= t("welcome.feed.process_label") %></span><br>
|
||||
<h3><%= process.title %></h3>
|
||||
</figcaption>
|
||||
</figure>
|
||||
<p class="description small"><%= process.summary %></p>
|
||||
<p class="small"><%= t("welcome.feed.see_process") %></p>
|
||||
<% end %>
|
||||
</div>
|
||||
7
app/components/widgets/feeds/process_component.rb
Normal file
7
app/components/widgets/feeds/process_component.rb
Normal file
@@ -0,0 +1,7 @@
|
||||
class Widgets::Feeds::ProcessComponent < ApplicationComponent
|
||||
attr_reader :process
|
||||
|
||||
def initialize(process)
|
||||
@process = process
|
||||
end
|
||||
end
|
||||
@@ -1,21 +0,0 @@
|
||||
<div class="card small-12 column margin-bottom">
|
||||
<div class="feed-content">
|
||||
<h3 class="title"><%= t("welcome.feed.most_active.#{feed.kind}") %></h3>
|
||||
|
||||
<% feed.items.each do |item| %>
|
||||
<%= link_to url_for(item) do %>
|
||||
<figure class="figure-card <%= item.class.to_s.parameterize(separator: "_") %>">
|
||||
<%= image_tag("welcome_process.png", alt: "") %>
|
||||
<figcaption>
|
||||
<span><%= t("welcome.feed.process_label") %></span><br>
|
||||
<h3><%= item.title %></h3>
|
||||
</figcaption>
|
||||
</figure>
|
||||
<p class="description small"><%= item.summary %></p>
|
||||
<p class="small"><%= t("welcome.feed.see_process") %></p>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<%= link_to t("welcome.feed.see_all_processes"), legislation_processes_path, class: "float-right see-all" %>
|
||||
</div>
|
||||
</div>
|
||||
@@ -1,7 +0,0 @@
|
||||
class Widgets::Feeds::ProcessesComponent < ApplicationComponent
|
||||
attr_reader :feed
|
||||
|
||||
def initialize(feed)
|
||||
@feed = feed
|
||||
end
|
||||
end
|
||||
16
app/components/widgets/feeds/proposal_component.html.erb
Normal file
16
app/components/widgets/feeds/proposal_component.html.erb
Normal file
@@ -0,0 +1,16 @@
|
||||
<div class="proposal">
|
||||
<div class="feed-description small-12 column
|
||||
<%= "medium-6 large-9" if proposal.image.present? %>">
|
||||
<strong><%= link_to proposal.title, url_for(proposal) %></strong><br>
|
||||
<p><%= proposal.summary %></p>
|
||||
</div>
|
||||
|
||||
<% if proposal.image.present? %>
|
||||
<div class="small-12 medium-6 large-3 column">
|
||||
<div class="feed-image">
|
||||
<%= image_tag proposal.image_url(:thumb),
|
||||
alt: proposal.image.title.unicode_normalize %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
7
app/components/widgets/feeds/proposal_component.rb
Normal file
7
app/components/widgets/feeds/proposal_component.rb
Normal file
@@ -0,0 +1,7 @@
|
||||
class Widgets::Feeds::ProposalComponent < ApplicationComponent
|
||||
attr_reader :proposal
|
||||
|
||||
def initialize(proposal)
|
||||
@proposal = proposal
|
||||
end
|
||||
end
|
||||
@@ -1,25 +0,0 @@
|
||||
<div id="feed_proposals" class="feed-proposals">
|
||||
<div class="feed-content">
|
||||
<h3 class="title"><%= t("welcome.feed.most_active.#{feed.kind}") %></h3>
|
||||
|
||||
<% feed.items.each do |item| %>
|
||||
<div class="<%= item.class.to_s.parameterize(separator: "_") %> row">
|
||||
<div class="feed-description small-12 column
|
||||
<%= "medium-6 large-9" if item.image.present? %>">
|
||||
<strong><%= link_to item.title, url_for(item) %></strong><br>
|
||||
<p><%= item.summary %></p>
|
||||
</div>
|
||||
<% if item.image.present? %>
|
||||
<div class="small-12 medium-6 large-3 column">
|
||||
<div class="feed-image">
|
||||
<%= image_tag item.image_url(:thumb),
|
||||
alt: item.image.title.unicode_normalize %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<%= link_to t("welcome.feed.see_all_proposals"), proposals_path, class: "see-all" %>
|
||||
</div>
|
||||
@@ -1,7 +0,0 @@
|
||||
class Widgets::Feeds::ProposalsComponent < ApplicationComponent
|
||||
attr_reader :feed
|
||||
|
||||
def initialize(feed)
|
||||
@feed = feed
|
||||
end
|
||||
end
|
||||
@@ -1,7 +1,7 @@
|
||||
<div class="feeds-list">
|
||||
<% @feeds.each do |feed| %>
|
||||
<% if feed_processes?(feed) %>
|
||||
<%= render Widgets::Feeds::ProcessesComponent.new(feed) %>
|
||||
<%= render Widgets::Feeds::FeedComponent.new(feed) %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
@@ -875,9 +875,10 @@ en:
|
||||
debates: "Most active debates"
|
||||
proposals: "Most active proposals"
|
||||
processes: "Open processes"
|
||||
see_all_debates: See all debates
|
||||
see_all_proposals: See all proposals
|
||||
see_all_processes: See all processes
|
||||
see_all:
|
||||
debates: See all debates
|
||||
proposals: See all proposals
|
||||
processes: See all processes
|
||||
process_label: Process
|
||||
see_process: See process
|
||||
cards:
|
||||
|
||||
@@ -875,9 +875,10 @@ es:
|
||||
debates: "Debates más activos"
|
||||
proposals: "Propuestas más activas"
|
||||
processes: "Procesos abiertos"
|
||||
see_all_debates: Ver todos los debates
|
||||
see_all_proposals: Ver todas las propuestas
|
||||
see_all_processes: Ver todos los procesos
|
||||
see_all:
|
||||
debates: Ver todos los debates
|
||||
proposals: Ver todas las propuestas
|
||||
processes: Ver todos los procesos
|
||||
process_label: Proceso
|
||||
see_process: Ver proceso
|
||||
cards:
|
||||
|
||||
@@ -106,7 +106,7 @@ describe "Homepage", :admin do
|
||||
visit root_path
|
||||
|
||||
expect(page).to have_content "Open processes"
|
||||
expect(page).to have_css(".legislation_process", count: 3)
|
||||
expect(page).to have_css(".legislation-process", count: 3)
|
||||
end
|
||||
|
||||
xscenario "Deactivate"
|
||||
|
||||
Reference in New Issue
Block a user