Module: Flakey::Facebook

Includes:
Base
Defined in:
lib/flakey/facebook.rb

Constant Summary collapse

SHARE_URL =
'https://www.facebook.com/sharer/sharer.php'

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Base

#default_url

Instance Attribute Details

#output_bufferObject

Needed to be able to pass a block down into link_to. See the share_button method. INFO: stackoverflow.com/a/7562194/574190



10
11
12
# File 'lib/flakey/facebook.rb', line 10

def output_buffer
  @output_buffer
end

Instance Method Details

#facebook_nickname(options = {}) ⇒ Object



12
13
14
15
# File 'lib/flakey/facebook.rb', line 12

def facebook_nickname(options = {})
  options[:nickname] ||
    Flakey.configuration.facebook_nickname
end

#facebook_profile_url(options = {}) ⇒ Object



17
18
19
20
# File 'lib/flakey/facebook.rb', line 17

def facebook_profile_url(options = {}) 
  nickname = options[:nickname] || facebook_nickname
  "https://www.facebook.com/" + nickname
end

#like_button(options = {}) ⇒ Object

Generate a traditional tweet button. This method needs the Facebook JavaScript to be loaded on the page to work correctly.

Takes a hash of options used to generate the button.

url

The URL to like. Default to the current request url.

layout

String. The layout of the button.

width

Integer. The width of the area taken up by the button.

send

Boolean. Include a Send button or not.

font

String. The font to use for the button text.

class_list

String. Must include ‘fb-like’ if overwriting.

show_faces

Boolean. Whether to show faces or not.

Returns a HTML string.



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/flakey/facebook.rb', line 36

def like_button(options = {})
  url = options[:url] || default_url
  layout = options[:layout] || 'button_count'
  width = options[:width] || 250
  send = options[:send] || false
  font = options[:font] || 'tahoma'
  class_list = options[:class] || 'fb-like'
  show_faces = options[:show_faces] || false

   :div, '', :class => class_list, data: {
    href: url, send: send, layout: layout, width: width.to_s,
    :'show-faces' => show_faces, font: font
  }
end

#share_button(options = {}, &block) ⇒ Object

Generate a Facebook Share button. INFO: goo.gl/MvqIi4

Returns a HTML string.



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/flakey/facebook.rb', line 55

def share_button(options = {}, &block)
  defaults = {
    url: default_url,
    label: 'Share',
    target: '_blank',
    class: 'facebook-share-button'
  }

  settings = defaults.merge options

  url = "#{SHARE_URL}?u=#{CGI.escape settings[:url]}"
  label = settings[:label]
  settings.delete(:url)
  settings.delete(:label)

  if block_given?
    link_to(url, settings, &block)
  else
    link_to label, url, settings
  end
end