Module: Share::Helpers

Defined in:
lib/share/helpers.rb

Instance Method Summary collapse

Instance Method Details



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/share/helpers.rb', line 3

def share_links options_or_text
  url = request.url
  text = options_or_text.is_a?(Hash) ? options_or_text[:tweet] : options_or_text
   :ul, :class => "share-container" do |content|
    lis =  { "twitter" => "http://twitter.com/intent/tweet?&text=" + URI.encode("#{text} #{url}"),
             "facebook" => "http://facebook.com/sharer.php?u=#{url}",
             "google-plus" => "https://plus.google.com/share?url=#{url}"}.map do |key, value|
        (:li,
          link_to("<i class=\"icon-fa-social icon-#{key}-sign\"></i>".html_safe, value, :title => "Share on #{key.to_s.humanize}", :class => "share-link #{key}",
            "onclick" => "javascript:window.open(this.href,'', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600');return false;"
          ), :class => "share-item")
    end
    if options_or_text.is_a?(Hash) && options_or_text[:email].present?
        body = options_or_text[:email][:body].gsub("{{url}}", request.url)
        target = "mailto:?subject=#{options_or_text[:email][:subject]}&body=#{body}"
        lis << (:li,
          link_to("<i class=\"icon-fa-social icon-envelope\"></i>".html_safe, target, :title => "Share with email", :class => "share-link email",
        ), :class => "share-item")
    end
    lis.join.html_safe
  end
end