Merge pull request #4505 from consul/social_footer
Avoid rendering empty lists in top links and footer
This commit is contained in:
@@ -33,6 +33,7 @@
|
|||||||
@import "tags";
|
@import "tags";
|
||||||
@import "admin/**/*";
|
@import "admin/**/*";
|
||||||
@import "budgets/**/*";
|
@import "budgets/**/*";
|
||||||
|
@import "layout/**/*";
|
||||||
@import "sdg/**/*";
|
@import "sdg/**/*";
|
||||||
@import "sdg_management/*";
|
@import "sdg_management/*";
|
||||||
@import "sdg_management/**/*";
|
@import "sdg_management/**/*";
|
||||||
|
|||||||
@@ -143,10 +143,6 @@
|
|||||||
content: "\f02f";
|
content: "\f02f";
|
||||||
}
|
}
|
||||||
|
|
||||||
.icon-blog::before {
|
|
||||||
content: "\f19a";
|
|
||||||
}
|
|
||||||
|
|
||||||
.icon-box::before {
|
.icon-box::before {
|
||||||
content: "\f187";
|
content: "\f187";
|
||||||
}
|
}
|
||||||
@@ -276,7 +272,6 @@
|
|||||||
content: "\f0c9";
|
content: "\f0c9";
|
||||||
}
|
}
|
||||||
|
|
||||||
.icon-blog,
|
|
||||||
.icon-facebook,
|
.icon-facebook,
|
||||||
.icon-instagram,
|
.icon-instagram,
|
||||||
.icon-telegram,
|
.icon-telegram,
|
||||||
|
|||||||
@@ -1633,23 +1633,6 @@ table {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.social {
|
|
||||||
|
|
||||||
li {
|
|
||||||
display: inline-block;
|
|
||||||
}
|
|
||||||
|
|
||||||
a {
|
|
||||||
font-size: rem-calc(24);
|
|
||||||
margin: 0 $line-height / 2;
|
|
||||||
text-decoration: none;
|
|
||||||
|
|
||||||
&:hover {
|
|
||||||
@include brand-text;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.share-supported {
|
.share-supported {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
|
|
||||||
|
|||||||
26
app/assets/stylesheets/layout/social.scss
Normal file
26
app/assets/stylesheets/layout/social.scss
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
.social {
|
||||||
|
@include grid-column;
|
||||||
|
text-align: right;
|
||||||
|
|
||||||
|
@include breakpoint(medium) {
|
||||||
|
width: 1 * 100% / 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
ul {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
li {
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
|
||||||
|
a {
|
||||||
|
font-size: rem-calc(24);
|
||||||
|
margin: 0 $line-height / 2;
|
||||||
|
text-decoration: none;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
@include brand-text;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
14
app/components/layout/social_component.html.erb
Normal file
14
app/components/layout/social_component.html.erb
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
<div class="social">
|
||||||
|
<ul>
|
||||||
|
<% sites.each do |name, url| %>
|
||||||
|
<li>
|
||||||
|
<%= link_to "#{url}/#{setting["#{name}_handle"]}", target: "_blank", title: link_title(name) do %>
|
||||||
|
<span class="show-for-sr"><%= link_text(name) %></span>
|
||||||
|
<span class="icon-<%= name %>" aria-hidden="true"></span>
|
||||||
|
<% end %>
|
||||||
|
</li>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<%= raw footer_content_block %>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
31
app/components/layout/social_component.rb
Normal file
31
app/components/layout/social_component.rb
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
class Layout::SocialComponent < ApplicationComponent
|
||||||
|
delegate :content_block, to: :helpers
|
||||||
|
|
||||||
|
def render?
|
||||||
|
sites.any? || footer_content_block.present?
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def sites
|
||||||
|
{
|
||||||
|
twitter: "https://twitter.com",
|
||||||
|
facebook: "https://www.facebook.com",
|
||||||
|
youtube: "https://www.youtube.com",
|
||||||
|
telegram: "https://www.telegram.me",
|
||||||
|
instragram: "https://www.instagram.com"
|
||||||
|
}.select { |name, _| setting["#{name}_handle"].present? }
|
||||||
|
end
|
||||||
|
|
||||||
|
def link_title(site_name)
|
||||||
|
t("shared.go_to_page") + link_text(site_name) + t("shared.target_blank")
|
||||||
|
end
|
||||||
|
|
||||||
|
def link_text(site_name)
|
||||||
|
t("social.#{site_name}", org: setting["org_name"])
|
||||||
|
end
|
||||||
|
|
||||||
|
def footer_content_block
|
||||||
|
content_block("footer")
|
||||||
|
end
|
||||||
|
end
|
||||||
3
app/components/layout/top_links_component.html.erb
Normal file
3
app/components/layout/top_links_component.html.erb
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
<ul class="no-bullet external-links">
|
||||||
|
<%= raw top_links_content_block %>
|
||||||
|
</ul>
|
||||||
13
app/components/layout/top_links_component.rb
Normal file
13
app/components/layout/top_links_component.rb
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
class Layout::TopLinksComponent < ApplicationComponent
|
||||||
|
delegate :content_block, to: :helpers
|
||||||
|
|
||||||
|
def render?
|
||||||
|
top_links_content_block.present?
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def top_links_content_block
|
||||||
|
content_block("top_links")
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -48,7 +48,7 @@ module ApplicationHelper
|
|||||||
SiteCustomization::Image.image_path_for(filename) || filename
|
SiteCustomization::Image.image_path_for(filename) || filename
|
||||||
end
|
end
|
||||||
|
|
||||||
def content_block(name, locale)
|
def content_block(name, locale = I18n.locale)
|
||||||
SiteCustomization::ContentBlock.block_for(name, locale)
|
SiteCustomization::ContentBlock.block_for(name, locale)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -31,57 +31,6 @@
|
|||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="small-12 medium-4 column social">
|
<%= render Layout::SocialComponent.new %>
|
||||||
<div class="text-right">
|
|
||||||
<ul>
|
|
||||||
<% if setting["twitter_handle"] %>
|
|
||||||
<li>
|
|
||||||
<%= link_to "https://twitter.com/#{setting["twitter_handle"]}", target: "_blank",
|
|
||||||
title: t("shared.go_to_page") + t("social.twitter", org: setting["org_name"]) + t("shared.target_blank") do %>
|
|
||||||
<span class="show-for-sr"><%= t("social.twitter", org: setting["org_name"]) %></span>
|
|
||||||
<span class="icon-twitter" aria-hidden="true"></span>
|
|
||||||
<% end %>
|
|
||||||
</li>
|
|
||||||
<% end %>
|
|
||||||
<% if setting["facebook_handle"] %>
|
|
||||||
<li>
|
|
||||||
<%= link_to "https://www.facebook.com/#{setting["facebook_handle"]}/", target: "_blank",
|
|
||||||
title: t("shared.go_to_page") + t("social.facebook", org: setting["org_name"]) + t("shared.target_blank") do %>
|
|
||||||
<span class="show-for-sr"><%= t("social.facebook", org: setting["org_name"]) %></span>
|
|
||||||
<span class="icon-facebook" aria-hidden="true"></span>
|
|
||||||
<% end %>
|
|
||||||
</li>
|
|
||||||
<% end %>
|
|
||||||
<% if setting["youtube_handle"] %>
|
|
||||||
<li>
|
|
||||||
<%= link_to "https://www.youtube.com/#{setting["youtube_handle"]}", target: "_blank",
|
|
||||||
title: t("shared.go_to_page") + t("social.youtube", org: setting["org_name"]) + t("shared.target_blank") do %>
|
|
||||||
<span class="show-for-sr"><%= t("social.youtube", org: setting["org_name"]) %></span>
|
|
||||||
<span class="icon-youtube" aria-hidden="true"></span>
|
|
||||||
<% end %>
|
|
||||||
</li>
|
|
||||||
<% end %>
|
|
||||||
<% if setting["telegram_handle"] %>
|
|
||||||
<li>
|
|
||||||
<%= link_to "https://www.telegram.me/#{setting["telegram_handle"]}", target: "_blank",
|
|
||||||
title: t("shared.go_to_page") + t("social.telegram", org: setting["org_name"]) + t("shared.target_blank") do %>
|
|
||||||
<span class="show-for-sr"><%= t("social.telegram", org: setting["org_name"]) %></span>
|
|
||||||
<span class="icon-telegram" aria-hidden="true"></span>
|
|
||||||
<% end %>
|
|
||||||
</li>
|
|
||||||
<% end %>
|
|
||||||
<% if setting["instagram_handle"] %>
|
|
||||||
<li>
|
|
||||||
<%= link_to "https://www.instagram.com/#{setting["instagram_handle"]}", target: "_blank",
|
|
||||||
title: t("shared.go_to_page") + t("social.instagram", org: setting["org_name"]) + t("shared.target_blank") do %>
|
|
||||||
<span class="show-for-sr"><%= t("social.instagram", org: setting["org_name"]) %></span>
|
|
||||||
<span class="icon-instagram" aria-hidden="true"></span>
|
|
||||||
<% end %>
|
|
||||||
</li>
|
|
||||||
<% end %>
|
|
||||||
<%= raw content_block("footer", I18n.locale) %>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</footer>
|
</footer>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<div class="small-12 medium-9 column">
|
<div class="small-12 medium-9 column">
|
||||||
<ul>
|
<ul>
|
||||||
<%= raw content_block("subnavigation_left", I18n.locale) %>
|
<%= raw content_block("subnavigation_left") %>
|
||||||
|
|
||||||
<% if feature?(:debates) %>
|
<% if feature?(:debates) %>
|
||||||
<li>
|
<li>
|
||||||
@@ -59,6 +59,6 @@
|
|||||||
</li>
|
</li>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<%= raw content_block("subnavigation_right", I18n.locale) %>
|
<%= raw content_block("subnavigation_right") %>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,3 +1 @@
|
|||||||
<ul class="no-bullet external-links">
|
<%= render Layout::TopLinksComponent.new %>
|
||||||
<%= raw content_block("top_links", I18n.locale) %>
|
|
||||||
</ul>
|
|
||||||
|
|||||||
39
spec/components/layout/social_component_spec.rb
Normal file
39
spec/components/layout/social_component_spec.rb
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
require "rails_helper"
|
||||||
|
|
||||||
|
describe Layout::SocialComponent, type: :component do
|
||||||
|
describe "#render?" do
|
||||||
|
it "renders when a social setting is present" do
|
||||||
|
Setting["twitter_handle"] = "myhandle"
|
||||||
|
|
||||||
|
render_inline Layout::SocialComponent.new
|
||||||
|
|
||||||
|
expect(page).to have_css "ul"
|
||||||
|
end
|
||||||
|
|
||||||
|
it "renders when a content block is present" do
|
||||||
|
Setting["twitter_handle"] = ""
|
||||||
|
Setting["facebook_handle"] = ""
|
||||||
|
Setting["youtube_handle"] = ""
|
||||||
|
Setting["telegram_handle"] = ""
|
||||||
|
Setting["instagram_handle"] = ""
|
||||||
|
|
||||||
|
create(:site_customization_content_block, name: "footer")
|
||||||
|
|
||||||
|
render_inline Layout::SocialComponent.new
|
||||||
|
|
||||||
|
expect(page).to have_css "ul"
|
||||||
|
end
|
||||||
|
|
||||||
|
it "does not render with no settings present and no content block present" do
|
||||||
|
Setting["twitter_handle"] = ""
|
||||||
|
Setting["facebook_handle"] = ""
|
||||||
|
Setting["youtube_handle"] = ""
|
||||||
|
Setting["telegram_handle"] = ""
|
||||||
|
Setting["instagram_handle"] = ""
|
||||||
|
|
||||||
|
render_inline Layout::SocialComponent.new
|
||||||
|
|
||||||
|
expect(page).not_to have_css "ul"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
19
spec/components/layout/top_links_component_spec.rb
Normal file
19
spec/components/layout/top_links_component_spec.rb
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
require "rails_helper"
|
||||||
|
|
||||||
|
describe Layout::TopLinksComponent, type: :component do
|
||||||
|
describe "#render?" do
|
||||||
|
it "renders when a content block is defined" do
|
||||||
|
create(:site_customization_content_block, name: "top_links")
|
||||||
|
|
||||||
|
render_inline Layout::TopLinksComponent.new
|
||||||
|
|
||||||
|
expect(page).to have_css "ul"
|
||||||
|
end
|
||||||
|
|
||||||
|
it "does not render when no content block is defined" do
|
||||||
|
render_inline Layout::TopLinksComponent.new
|
||||||
|
|
||||||
|
expect(page).not_to have_css "ul"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user