Sha256: 7d7535099dfba4f2537c4711129670a1a499ef47f55e1bc02b30fa37854c291a

Contents?: true

Size: 754 Bytes

Versions: 1

Compression:

Stored size: 754 Bytes

Contents

module Spree
  module PinterestHelper
    def pin_it_button(product)
      return if product.images.empty?

      url = escape spree.product_url(product)
      media = escape absolute_image_url(product.images.first.attachment.url)
      description = escape product.name

      link_to("Pin It",
              "http://pinterest.com/pin/create/button/?url=#{url}&media=#{media}&description=#{description}",
              :class => "pin-it-button",
              "count-layout" => "horizontal").html_safe
    end

    private

    def escape(string)
      URI.escape string, /[^#{URI::PATTERN::UNRESERVED}]/
    end

    def absolute_image_url(url)
      return url if url.starts_with? "http"

      request.protocol + request.host + url
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
spree_pinterest-0.2.1 app/helpers/spree/pinterest_helper.rb