Module: Carrot::Facebook::ViewHelpers

Defined in:
lib/carrot-facebook/view_helpers.rb

Instance Method Summary collapse

Instance Method Details

#auto_grow(timer = true) ⇒ Object



70
71
72
# File 'lib/carrot-facebook/view_helpers.rb', line 70

def auto_grow(timer = true)
  (:script, "FB.Canvas.setAutoGrow(#{timer});")
end

#facepile(*options) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/carrot-facebook/view_helpers.rb', line 74

def facepile(*options)
  opts = {:href => ENV['FACEBOOK_APP_URL'],
          :max_rows => 1,
          :width => 300,
          :show_count => true }
  opts.merge!(options.first) unless options.empty?

  raise "Must provide a :url option parameter or ENV['FACEBOOK_APP_URL']" unless opts[:href]
  
  %Q{
  <div class="fb-facepile" 
  data-href="#{opts[:href]}" 
  data-max-rows="#{opts[:max_rows]}"
  data-show-count="#{opts[:show_count]}"
  data-width="#{opts[:width]}">
  </div>
  }.html_safe
end

#fb_avatar(fb_id = nil, type = :square) ⇒ Object

extend ActionView::Helpers::AssetTagHelper Public: Generates a user’s Facebook avatar.

fb_id - The String of the Facebook user’s ID. type - The Symbol of the desired image size.

[:square (50x50), :small (50xN), :normal (100xN), :large (200xN)]

Examples

fb_avatar(‘1234567890’, :normal)

# => "//graph.facebook.com/1234567890/picture?type=normal"

Returns the generated Facebook URL.



19
20
21
22
23
# File 'lib/carrot-facebook/view_helpers.rb', line 19

def fb_avatar(fb_id = nil, type = :square)
  if fb_id
    "//graph.facebook.com/#{fb_id}/picture?type=#{type}"
  end
end

#fb_avatar_tag(fb_id = nil, type = :square) ⇒ Object

Public: Display a user’s Facebook avatar.

fb_id - The String of the Facebook user’s ID. type - The Symbol of the desired image size.

[:square (50x50), :small (50xN), :normal (100xN), :large (200xN)]

Examples

fb_avatar_tag(‘1234567890’, :normal)

# => '<img alt="Facebook Avatar for User 1234567890" src="//graph.facebook.com/1234567890/picture?type=normal" />'

Returns the image tag for the Facebook user’s avatar.



37
38
39
40
41
# File 'lib/carrot-facebook/view_helpers.rb', line 37

def fb_avatar_tag(fb_id = nil, type = :square)
  if fb_id
    tag(:img, src: fb_avatar(fb_id, type), alt: "Facebook Avatar for User #{fb_id}")
  end
end

#fbjs(*options) ⇒ Object

Public: Generate Facebook’s Javascript

options - A Hash potentially consisting of two keys:

app_id - A String denoting the Facebook App ID (Also accepts ENV["FACEBOOK_APP_ID"])
xfbml  - A Boolean denoting whether XFBML should be rendered upon pageload

Examples

fb_js
fb_js(app_id: '1234567890')
fb_js(xfbml: false)
fb_js(app_id: '1234567890', xfbml: false)

Returns and initializes the Facebook Javascript SDK



57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/carrot-facebook/view_helpers.rb', line 57

def fbjs(*options)
  opts = { :app_id => ENV['FACEBOOK_APP_ID'], :xfbml => true }
  opts.merge!(options.first) unless options.empty?

  %Q{
    <div id="fb-root"></div>
    <script src="//connect.facebook.net/en_US/all.js"></script>
    <script>
      FB.init({ appId: '#{opts[:app_id]}', xfbml: '#{opts[:xfbml]}' });
    </script>
  }.html_safe
end