Module: Decidim::SocialShareButtonHelper

Defined in:
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
# File '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

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

#render_social_share_buttons(services, title, args) ⇒ Object



14
15
16
17
18
# File '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

#render_social_share_icon(service, options = {}) ⇒ Object



39
40
41
42
43
44
45
# File 'app/helpers/decidim/social_share_button_helper.rb', line 39

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

#social_share_button_tag(title, args) ⇒ Object



6
7
8
9
10
11
12
# File '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