Files
nairobi/app/components/layout/social_component.rb
Javi Martín da76c848fc Avoid rendering an empty list in footer
We've had an accessibility error reported by the Spanish "Portal
Administración electrónica" (PAe). While I can't find any accessibility
rule saying empty lists should be avoided, it looks like some screen
readers report finding lists with 0 items, which is annoying.

We could also do it with CSS using `ul:empty { display: none}`. However,
at the time of writing no browser supports this rule when the tag
contains whitespace.
2021-06-24 13:15:03 +02:00

32 lines
789 B
Ruby

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", I18n.locale)
end
end