Sha256: 84bb1c27e3e38b60a3e19ea4e11f6b8a7cee84442b844e3138c76890bfa96156

Contents?: true

Size: 1.22 KB

Versions: 16

Compression:

Stored size: 1.22 KB

Contents

module Pageflow
  module SocialShareLinksHelper
    include SocialShareHelper

    PROVIDER_URL_TEMPLATES = {
      email: 'mailto:?body=%{url}',
      facebook: 'http://www.facebook.com/sharer/sharer.php?u=%{url}',
      google: 'https://plus.google.com/share?url=%{url}',
      linked_in: 'https://www.linkedin.com/shareArticle?mini=true&url=%{url}',
      telegram: 'tg://msg?text=%{url}',
      twitter: 'https://twitter.com/intent/tweet?url=%{url}',
      whats_app: 'WhatsApp://send?text=%{url}'
    }.freeze

    def social_share_link(provider, entry, &block)
      block ||= ->() {}
      page_share_link_url = social_share_link_url(provider, social_share_page_url(entry, 'permaId'))
      data_attributes = entry.share_url.present? ? {} : {share_page: page_share_link_url}

      link_to(social_share_link_url(provider, social_share_entry_url(entry)),
              target: '_blank',
              tabindex: '2',
              class: ['share', provider],
              data: data_attributes,
              &block)
    end

    private

    def social_share_link_url(provider, url)
      return nil if url.blank?
      encoded_url = ERB::Util.url_encode(url)
      PROVIDER_URL_TEMPLATES[provider] % {url: encoded_url}
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
pageflow-14.5.2 app/helpers/pageflow/social_share_links_helper.rb
pageflow-15.1.0.beta6 app/helpers/pageflow/social_share_links_helper.rb
pageflow-15.1.0.beta5 app/helpers/pageflow/social_share_links_helper.rb
pageflow-15.1.0.beta4 app/helpers/pageflow/social_share_links_helper.rb
pageflow-15.1.0.beta3 app/helpers/pageflow/social_share_links_helper.rb
pageflow-15.1.0.beta2 app/helpers/pageflow/social_share_links_helper.rb
pageflow-15.1.0.beta1 app/helpers/pageflow/social_share_links_helper.rb
pageflow-15.0.2 app/helpers/pageflow/social_share_links_helper.rb
pageflow-15.0.1 app/helpers/pageflow/social_share_links_helper.rb
pageflow-15.0.0 app/helpers/pageflow/social_share_links_helper.rb
pageflow-14.5.1 app/helpers/pageflow/social_share_links_helper.rb
pageflow-14.5.0 app/helpers/pageflow/social_share_links_helper.rb
pageflow-15.0.0.rc2 app/helpers/pageflow/social_share_links_helper.rb
pageflow-15.0.0.rc1 app/helpers/pageflow/social_share_links_helper.rb
pageflow-15.0.0.beta4 app/helpers/pageflow/social_share_links_helper.rb
pageflow-15.0.0.beta3 app/helpers/pageflow/social_share_links_helper.rb