forked from rsiddle/Spree-Social-Bookmarks
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
social_bookmarks_helper.rb
33 lines (29 loc) · 1.2 KB
/
social_bookmarks_helper.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
module Spree
module SocialBookmarksHelper
# Dislay the social bookmarks
# <%= display_bookmarks(@product.name, product_url(@product)) %> OR
# <%= display_bookmarks(@product.name) %> which will use the current URI request
def display_bookmarks(product_or_url = nil, title = nil)
product = nil
image = nil
if product_or_url.nil?
# TODO there has to be a better way to handle this
url = request.env["REQUEST_URI"]
url = 'http://'+request.host + request.fullpath if url.nil? or url.eql?(url.gsub(/http:/,'').gsub(/HTTP:/,''))
elsif product_or_url.class == String and url.eql?(url.gsub(/http:/,'').gsub(/HTTP:/,''))
url = 'http://'+request.host + url
elsif product_or_url.class == Spree::Product
url = polymorphic_url product_or_url
product = product_or_url
title = product_or_url.name if title.nil?
image = request.protocol + request.host + product.images.first.attachment.url if product.images.count > 0
end
render :partial => 'spree/shared/bookmarks', :locals => {
:title => title,
:url => u(url),
:product => product,
:image => u(image)
}
end
end
end