Module: SocialSharer::ViewHelpers

Defined in:
lib/social_sharer/view_helpers.rb

Instance Method Summary collapse

Instance Method Details

#social_share_tags(options) ⇒ Object

Given an options object, create a number of social URLs



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
34
35
36
# File 'lib/social_sharer/view_helpers.rb', line 4

def social_share_tags(options)
  validate_social_tag_options(options)

  has_individual_settings = options[:individual_settings]

  twitter_url = has_individual_settings ? options[:twitter][:url] : options[:url]
  twitter_url += '?src=tw'

  twitter_message = has_individual_settings ? options[:twitter][:message] : options[:twitter_message]
  twitter_handle = has_individual_settings ? options[:twitter][:handle] : options[:twitter_handle]

  facebook_url = has_individual_settings ? options[:facebook][:url] : options[:url]
  facebook_url += '?src=fb'

  twitter_handle_text = if twitter_handle.nil?
                          ''
                        else
                          "via #{twitter_handle} "
                        end

  link_to('Share on Twitter', 'http://twitter.com/', rel: 'nofollow', onclick: "popUp=window.open("\
                                                                                 "'http://twitter.com/intent/tweet?text=#{twitter_message} #{twitter_handle_text}#{twitter_url}',"\
                                                                                 "'popupwindow',"\
                                                                                 "'scrollbars=yes,width=800,height=400');"\
                                                                               "popUp.focus();"\
                                                                               "return false") +
  link_to('Share on Facebook', 'http://www.facebook.com/', rel: 'nofollow', onclick: "popUp=window.open("\
                                                                                       "'http://www.facebook.com/sharer.php?u=#{facebook_url}',"\
                                                                                       "'popupwindow',"\
                                                                                       "'scrollbars=yes,width=800,height=400');"\
                                                                                     "popUp.focus();"\
                                                                                     "return false")
end