Module: Decidim::SocialShareButtonHelper

Included in:
Design::IconographyHelper, ShareTextWidgetCell, ShareWidgetCell
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



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

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

  data = service.optional_args.reverse_merge(
    "site" => service.name.downcase,
    "external-link" => "text-only",
    "external-domain-link" => false
  )

  link_to(
    uri,
    rel: "nofollow noopener noreferrer",
    target: "_blank",
    data:,
    title: t("decidim.shared.share_modal.share_to", service: service.name)
  ) do
    (:span, render_social_share_icon(service), class: "icon") +
      (:span, service.name, class: "text")
  end
end

#render_social_share_buttons(services, title, args) ⇒ Object



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

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



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

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))
  end
end

#social_share_button_tag(title, args) ⇒ Object



6
7
8
9
10
# 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?

  render_social_share_buttons(enabled_services, title, args)
end