The `use_helpers` method was added in ViewComponent 3.8.0, and it's included by default in all components since version 3.11.0. Note we sometimes delegated the `can?` method to the controller instead of the helpers, for no particularly reason. We're unifying that code as well.
32 lines
737 B
Ruby
32 lines
737 B
Ruby
class Layout::SocialComponent < ApplicationComponent
|
|
use_helpers :content_block
|
|
|
|
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",
|
|
instagram: "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)
|
|
end
|
|
|
|
def link_text(site_name)
|
|
t("social.#{site_name}", org: setting["org_name"])
|
|
end
|
|
|
|
def footer_content_block
|
|
content_block("footer")
|
|
end
|
|
end
|