Module: Decidim::SocialShareButtonHelper

Defined in:
decidim-core/app/helpers/decidim/social_share_button_helper.rb

Overview

A Helper that reimplements the SocialShareButton gem helpers, so that we do not depend on it anymore.

Instance Method Summary collapse

Instance Method Details

#render_social_share_button(service, title, args) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'decidim-core/app/helpers/decidim/social_share_button_helper.rb', line 20

def render_social_share_button(service, title, args)
  uri = service.formatted_share_uri(title, args)
  return unless uri

  social_icon = if service.icon.include? ".svg"
                  image_tag service.icon_path, alt: t("decidim.shared.share_modal.share_to", service: service.name)
                else
                  icon(service.icon, style: "color: #{service.icon_color};")
                end

  link_to(
    uri,
    rel: "nofollow noopener noreferrer",
    target: "_blank",
    data: {
      "site" => service.name.downcase,
      "external-link" => false,
      "external-domain-link" => false
    },
    title: t("decidim.shared.share_modal.share_to", service: service.name)
  ) do
    social_icon + (:span, service.name)
  end
end

#render_social_share_buttons(services, title, args) ⇒ Object



14
15
16
17
18
# File 'decidim-core/app/helpers/decidim/social_share_button_helper.rb', line 14

def render_social_share_buttons(services, title, args)
  services.map do |service|
    render_social_share_button(service, title, args)
  end.join.html_safe
end

#social_share_button_tag(title, args) ⇒ Object



6
7
8
9
10
11
12
# File 'decidim-core/app/helpers/decidim/social_share_button_helper.rb', line 6

def social_share_button_tag(title, args)
  return unless enabled_services.length.positive?

   :div, class: "share-modal__list", data: { social_share: "" } do
    render_social_share_buttons(enabled_services, title, args)
  end
end