Sha256: 746e914e5bcfd5478681174a44dbaf02e691a0261ef24055082c4ac46b353c92

Contents?: true

Size: 1.34 KB

Versions: 1

Compression:

Stored size: 1.34 KB

Contents

module SharingTags::ActionView::ButtonHelper

  def link_to_facebook_share(name = "Facebook", &block)
    share_link_to name, :facebook, [], &block
  end

  def link_to_vkontakte_share(name = "Vkontakte", &block)
    share_link_to name, :vkontakte, [:title, :description, :image], &block
  end

  def link_to_odnoklassniki_share(name = "Odnoklassniki", &block)
    share_link_to name, :odnoklassniki, [:title, :description], &block
  end

  def link_to_twitter_share(name = "Twitter", &block)
    share_link_to name, :twitter, [:title, :description], &block
  end

  private

  def share_link_to(name_or_options = nil, network = nil, data_params = [], &block)
    params = sharing_tags[network]
    data_attrs = params.get(*(data_params +[:network, :share_url]))

    if block_given?
      name_or_options = {} if !name_or_options || name_or_options.is_a?(String)
      data_attrs.merge!(name_or_options.delete(:data)) if name_or_options[:data]

      if name_or_options[:role]
        name_or_options[:role] += " sharing_tags_share"
      else
        name_or_options[:role] = "sharing_tags_share"
      end

      name_or_options.merge!(data: data_attrs, target: "_blank")

      link_to params.page_url, name_or_options, &block
    else
      link_to name_or_options, params.page_url, data: data_attrs, role: "sharing_tags_share", target: "_blank", &block
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sharing_tags-0.0.5 lib/sharing_tags/action_view/button_helper.rb