module Facebooker::Rails::Helpers

Facebook specific helpers for creating FBML

All helpers that take a user as a parameter will get the Facebook UID from the facebook_id attribute if it exists. It will use to_s if the facebook_id attribute is not present.

Constants

FB_DIALOG_BUTTON_VALID_OPTION_KEYS
FB_NAME_OPTION_KEYS_TO_TRANSFORM
FB_NAME_VALID_OPTION_KEYS
FB_PHOTO_VALID_OPTION_KEYS
FB_PROFILE_PIC_OPTION_KEYS_TO_TRANSFORM
FB_PROFILE_PIC_VALID_OPTION_KEYS
FB_PRONOUN_OPTION_KEYS_TO_TRANSFORM
FB_PRONOUN_VALID_OPTION_KEYS
FB_REF_VALID_OPTION_KEYS
FB_TAB_ITEM_VALID_OPTION_KEYS
VALID_FB_PHOTO_ALIGN_VALUES
VALID_FB_PHOTO_SIZES
VALID_FB_PROFILE_PIC_SIZES
VALID_FB_SHARED_ALIGN_VALUES
VALID_FB_SHARED_PHOTO_SIZES
VALID_FB_TAB_ITEM_ALIGN_VALUES
VALID_PERMISSIONS

Public Instance Methods

cast_to_photo_id(object) click to toggle source
# File lib/facebooker/rails/helpers.rb, line 336
def cast_to_photo_id(object)
  object.respond_to?(:photo_id) ? object.photo_id : object
end
facebook_form_for( record_or_name_or_array,*args, &proc) click to toggle source

Create a facebook form using <fb:editor>

It yields a form builder that will convert the standard rails form helpers into the facebook specific version.

Example:

<% facebook_form_for(:poke,@poke,:url => create_poke_path) do |f| %>
  <%= f.text_field :message, :label=>"message" %>
  <%= f.buttons "Save Poke" %>
<% end %>

will generate

<fb:editor action="/pokes/create">
  <fb:editor-text name="poke[message]" id="poke_message" value="" label="message" />
  <fb:editor-buttonset>
   <fb:editor-button label="Save Poke"
  </fb:editor-buttonset>
</fb:editor>
# File lib/facebooker/rails/helpers.rb, line 189
def facebook_form_for( record_or_name_or_array,*args, &proc)

  raise ArgumentError, "Missing block" unless block_given?
  options = args.last.is_a?(Hash) ? args.pop : {}

  case record_or_name_or_array
  when String, Symbol
    object_name = record_or_name_or_array
  when Array
    object = record_or_name_or_array.last
    object_name = ActionController::RecordIdentifier.singular_class_name(object)
    apply_form_for_options!(record_or_name_or_array, options)
    args.unshift object
  else
    object = record_or_name_or_array
    object_name = ActionController::RecordIdentifier.singular_class_name(object)
    apply_form_for_options!([object], options)
    args.unshift object
  end
  method = (options[:html]||{})[:method]
  options[:builder] ||= Facebooker::Rails::FacebookFormBuilder
  editor_options={}
  
  action=options.delete(:url)
  editor_options[:action]= action unless action.blank?
  width=options.delete(:width)
  editor_options[:width]=width unless width.blank?
  width=options.delete(:labelwidth)
  editor_options[:labelwidth]=width unless width.blank?

  versioned_concat(tag("fb:editor",editor_options,true) , proc.binding)
  versioned_concat(tag(:input,{:type=>"hidden",:name=>:_method, :value=>method},false), proc.binding) unless method.blank?
  versioned_concat(token_tag, proc.binding)
  fields_for( object_name,*(args << options), &proc)
  versioned_concat("</fb:editor>",proc.binding)
end
facebook_messages() click to toggle source

Render flash values as <fb:message> and <fb:error> tags

values in flash will be rendered as an <fb:message>

values in flash will be rendered as an <fb:error>

TODO: Allow flash to render #fb_explanation

# File lib/facebooker/rails/helpers.rb, line 434
def facebook_messages
  message=""
  unless flash[:notice].blank?
    message += fb_success(*flash[:notice])
  end
  unless flash[:error].blank?
    message += fb_error(*flash[:error])
  end
  message
end
fb_about_url() click to toggle source

Return the URL for the about page of the application

# File lib/facebooker/rails/helpers.rb, line 578
def fb_about_url
  "http://#{Facebooker.www_server_base_url}/apps/application.php?api_key=#{Facebooker.api_key}"
end
fb_action(name, url) click to toggle source

Renders an action using the <fb:action> tag

# File lib/facebooker/rails/helpers.rb, line 476
def fb_action(name, url)
  "<fb:action href=\"#{url_for(url)}\">#{name}</fb:action>"
end
fb_add_info_section() click to toggle source

Renders an ‘Add to Info’ button The button allows a user to add an application info section to her Info tab

# File lib/facebooker/rails/helpers.rb, line 608
def fb_add_info_section
  tag "fb:add-section-button",:section=>"info"
end
fb_add_profile_section() click to toggle source

Renders an ‘Add to Profile’ button The button allows a user to add condensed profile box to the main profile

# File lib/facebooker/rails/helpers.rb, line 602
def fb_add_profile_section
  tag "fb:add-section-button",:section=>"profile"
end
fb_application_name(options={}) click to toggle source

Render an fb:application-name tag

This renders the current application name via fbml. See wiki.developers.facebook.com/index.php/Fb:application-name for a full description.

# File lib/facebooker/rails/helpers.rb, line 232
def fb_application_name(options={})
  tag "fb:application-name", stringify_vals(options)
end
fb_board(xid,options={}) click to toggle source

Embed a discussion board named xid on the current page <em>See</em wiki.developers.facebook.com/index.php/Fb:board for more details Options are:

* canpost
* candelete
* canmark
* cancreatet
* numtopics
* callbackurl
* returnurl
# File lib/facebooker/rails/helpers.rb, line 594
def fb_board(xid,options={})
  options = options.dup
  title = (title = options.delete(:title)) ? fb_title(title) : nil
  content_tag("fb:board", title, stringify_vals(options.merge(:xid=>xid)))
end
fb_bookmark_button() click to toggle source

Renders the Facebook bookmark button

See wiki.developers.facebook.com/index.php/Fb:bookmark for more details

# File lib/facebooker/rails/helpers.rb, line 745
def fb_bookmark_button
  content_tag "fb:bookmark"
end
fb_comments(xid,canpost=true,candelete=false,numposts=5,options={}) click to toggle source

Create a comment area All the data for this content area is stored on the facebook servers. See: wiki.developers.facebook.com/index.php/Fb:comments for full details

# File lib/facebooker/rails/helpers.rb, line 495
def fb_comments(xid,canpost=true,candelete=false,numposts=5,options={})
  options = options.dup
                    title = (title = options.delete(:title)) ? fb_title(title) : nil 
  content_tag "fb:comments",title,stringify_vals(options.merge(:xid=>xid,:canpost=>canpost.to_s,:candelete=>candelete.to_s,:numposts=>numposts))
end
fb_container(options={},&proc) click to toggle source
# File lib/facebooker/rails/helpers.rb, line 682
def fb_container(options={},&proc)
  inner = capture(&proc)
  versioned_concat(content_tag("fb:container",inner,options), proc.binding)
end
fb_create_button(name, url) click to toggle source

Render a <fb:create-button> tag For use inside <fb:dashboard>

# File lib/facebooker/rails/helpers.rb, line 488
def fb_create_button(name, url)
   "<fb:create-button href=\"#{url_for(url)}\">#{name}</fb:create-button>"
end
fb_dashboard(&proc) click to toggle source

Create a dashboard. It can contain #fb_action, #fb_help, and #fb_create_button

For Example:

<% fb_dashboard do %>
  <%= APP_NAME %>
  <%= fb_action 'My Matches', search_path %>
  <%= fb_help 'Feedback', "http://www.facebook.com/apps/application.php?id=6236036681" %>
  <%= fb_create_button 'Invite Friends', main_path %>
<% end %>
# File lib/facebooker/rails/helpers.rb, line 454
def fb_dashboard(&proc)
  if block_given?
    content = capture(&proc)
    versioned_concat(content_tag("fb:dashboard",content,{}),proc.binding)
  else
    content_tag("fb:dashboard",content,{})
  end
end
fb_date(time, options={}) click to toggle source

Renders a fb:date element

Example: <%= #fb_date(Time.now, :format => ‘verbose’, :tz => ‘America/New York’) %>

See wiki.developers.facebook.com/index.php/Fb:date for more details

# File lib/facebooker/rails/helpers.rb, line 737
def fb_date(time, options={})
  tag "fb:date", stringify_vals({:t => time.to_i}.merge(options))
end
fb_dialog( id, cancel_button, &block ) click to toggle source

Create an fb:dialog id must be a unique name e.g. “my_dialog” cancel_button is true or false

# File lib/facebooker/rails/helpers.rb, line 26
def fb_dialog( id, cancel_button, &block )
  content = capture(&block)
  cancel_button = cancel_button ? 1 : 0 unless cancel_button == 0
  versioned_concat( content_tag("fb:dialog", content, {:id => id, :cancel_button => cancel_button}), block.binding )
end
fb_dialog_button( type, value, options={} ) click to toggle source
# File lib/facebooker/rails/helpers.rb, line 59
def fb_dialog_button( type, value, options={} )
  options.assert_valid_keys FB_DIALOG_BUTTON_VALID_OPTION_KEYS
  options.merge! :type => type, :value => value
  tag "fb:dialog-button", options
end
fb_dialog_content( &block ) click to toggle source
# File lib/facebooker/rails/helpers.rb, line 54
def fb_dialog_content( &block )
  content = capture(&block)
  versioned_concat( content_tag("fb:dialog-content", content), block.binding )
end
fb_dialog_title( title ) click to toggle source
# File lib/facebooker/rails/helpers.rb, line 50
def fb_dialog_title( title )
  content_tag "fb:dialog-title", title
end
fb_else(&proc) click to toggle source

Render fb:else tag Must be used within if block such as #fb_if_is_user or #fb_if_is_app_user . See example in #fb_if_is_app_user

# File lib/facebooker/rails/helpers.rb, line 571
def fb_else(&proc)
  content = capture(&proc)
  versioned_concat(content_tag("fb:else",content),proc.binding)
end
fb_error(message, text=nil) click to toggle source

Render an <fb:error> tag If message and text are present then this will render fb:error and fb:message tag TODO: Optionally takes a decoration tag with value of ‘no_padding’ or ‘shorten’

# File lib/facebooker/rails/helpers.rb, line 410
def fb_error(message, text=nil)
  fb_status_msg("error", message, text)
end
fb_explanation(message, text=nil) click to toggle source

Render an <fb:explanation> tag If message and text are present then this will render fb:error and fb:message tag TODO: Optionally takes a decoration tag with value of ‘no_padding’ or ‘shorten’

# File lib/facebooker/rails/helpers.rb, line 417
def fb_explanation(message, text=nil)
  fb_status_msg("explanation", message, text)
end
fb_fbml_attribute(name, text, options={}) click to toggle source

Renders a fb:fbml-attribute element

Example: <%= #fb_fbml_attribute(‘title’, Education) %>

The options hash is passed to the fb:intl element that is generated inside this element and can have the keys available for the fb:intl element.

See wiki.developers.facebook.com/index.php/Fb:fbml-attribute for more details

# File lib/facebooker/rails/helpers.rb, line 759
def fb_fbml_attribute(name, text, options={})
  content_tag("fb:fbml-attribute", fb_intl(text, options), stringify_vals({:name => name}))
end
fb_friend_selector(options={}) click to toggle source

Render an <fb:friend-selector> element See: wiki.developers.facebook.com/index.php/Fb:friend-selector for options

# File lib/facebooker/rails/helpers.rb, line 135
def fb_friend_selector(options={})
  tag("fb:friend-selector",stringify_vals(options))
end
fb_google_analytics(uacct, options={}) click to toggle source

Create a Google Analytics tag

uacct: Your Urchin/Google Analytics account ID.

# File lib/facebooker/rails/helpers.rb, line 513
def fb_google_analytics(uacct, options={})
  options = options.dup
  tag "fb:google-analytics", stringify_vals(options.merge(:uacct => uacct))
end
fb_help(name, url) click to toggle source

Render a <fb:help> tag For use inside <fb:dashboard>

# File lib/facebooker/rails/helpers.rb, line 482
def fb_help(name, url)
  "<fb:help href=\"#{url_for(url)}\">#{name}</fb:help>"
end
fb_if_is_app_user(user=nil,options={},&proc) click to toggle source
Render if-is-app-user tag
This tag renders the enclosing content only if the user specified has accepted the terms of service for the application. 
Use fb_if_user_has_added_app to determine wether the user has added the app.
Example: 
<% fb_if_is_app_user(@facebook_user) do %>
        Thanks for accepting our terms of service!
      <% fb_else do %>
        Hey you haven't agreed to our terms.  <%= link_to("Please accept our terms of service.", :action => "terms_of_service") %>
      <% end %>

<% end %>

# File lib/facebooker/rails/helpers.rb, line 528
def fb_if_is_app_user(user=nil,options={},&proc)
  content = capture(&proc) 
  options = options.dup
  options.merge!(:uid=>cast_to_facebook_id(user)) if user
  versioned_concat(content_tag("fb:if-is-app-user",content,stringify_vals(options)),proc.binding)
end
fb_if_is_user(user,&proc) click to toggle source

Render fb:if-is-user tag This tag only renders enclosing content if the user is one of those specified user can be a single user or an Array of users Example: <% #fb_if_is_user(@check_user) do %>

     <%= fb_name(@facebook_user) %> are one of the users. <%= link_to("Check the other side", :action => "friend") %>
<% fb_else do %>
  <%= fb_name(@facebook_user) %>  are not one of the users  <%= fb_name(@check_user) %>
    <%= link_to("Check the other side", :action => "you") %>
<% end %>

<% end %>

# File lib/facebooker/rails/helpers.rb, line 562
def fb_if_is_user(user,&proc)
  content = capture(&proc) 
  user = [user] unless user.is_a? Array
  user_list=user.map{|u| cast_to_facebook_id(u)}.join(",")
  versioned_concat(content_tag("fb:if-is-user",content,{:uid=>user_list}),proc.binding)
end
fb_if_user_has_added_app(user,options={},&proc) click to toggle source
Render if-user-has-added-app tag
This tag renders the enclosing content only if the user specified has installed the application 

Example: 
<% fb_if_user_has_added_app(@facebook_user) do %>
        Hey you are an app user!
      <% fb_else do %>
        Hey you aren't an app user.  <%= link_to("Add App and see the other side.", :action => "added_app") %>
      <% end %>

<% end %>

# File lib/facebooker/rails/helpers.rb, line 545
def fb_if_user_has_added_app(user,options={},&proc)
  content = capture(&proc) 
  options = options.dup
  versioned_concat(content_tag("fb:if-user-has-added-app", content, stringify_vals(options.merge(:uid=>cast_to_facebook_id(user)))),proc.binding)
end
fb_iframe(src, options = {}) click to toggle source
# File lib/facebooker/rails/helpers.rb, line 42
def fb_iframe(src, options = {})
  content_tag "fb:iframe", '', options.merge({ :src => src })
end
fb_intl(text=nil, options={}, &proc) click to toggle source

Renders a fb:intl element

Example: <%= #fb_intl(‘Age’, :desc => ‘Label for the age form field’, :delimiters => ‘[]’) %>

See wiki.developers.facebook.com/index.php/Fb:intl for more details

# File lib/facebooker/rails/helpers.rb, line 705
def fb_intl(text=nil, options={}, &proc)
  raise ArgumentError, "Missing block or text" unless block_given? or text
  if block_given?
    versioned_concat(fb_intl(capture(&proc), options))
  else
    content_tag("fb:intl", text, stringify_vals(options))
  end
end
fb_intl_token(name, text=nil, &proc) click to toggle source

Renders a fb:intl-token element

Example: <%= fb_intl-token(‘number’, 5) %>

See wiki.developers.facebook.com/index.php/Fb:intl-token for more details

# File lib/facebooker/rails/helpers.rb, line 721
def fb_intl_token(name, text=nil, &proc)
  raise ArgumentError, "Missing block or text" unless block_given? or text
  if block_given?
    versioned_concat(fb_intl_token(name, capture(&proc)))
  else
    content_tag("fb:intl-token", text, stringify_vals({:name => name}))
  end
end
fb_multi_friend_input(options={}) click to toggle source

Render an <fb:multi-friend-input> element See: wiki.developers.facebook.com/index.php/Fb:multi-friend-input for options

# File lib/facebooker/rails/helpers.rb, line 141
def fb_multi_friend_input(options={})
  tag "fb:multi-friend-input",stringify_vals(options)
end
fb_multi_friend_request(type,friend_selector_message,url, fb_multi_friend_selector_options = {},&block) click to toggle source

Create an fb:request-form with an #fb_multi_friend_selector inside

The content of the block are used as the message on the form, the options hash is passed onto fb_multi_friend_selector.

For example:

<% fb_multi_friend_request("Poke","Choose some friends to Poke",create_poke_path,:exclude_ids => "123456789,987654321") do %>
  If you select some friends, they will see this message.
  <%= fb_req_choice("They will get this button, too",new_poke_path) %>
<% end %>
# File lib/facebooker/rails/helpers.rb, line 123
def fb_multi_friend_request(type,friend_selector_message,url, fb_multi_friend_selector_options = {},&block)
  content = capture(&block)
  versioned_concat(content_tag("fb:request-form",
                      fb_multi_friend_selector(friend_selector_message, fb_multi_friend_selector_options) + token_tag,
                      {:action=>url,:method=>"post",:invite=>true,:type=>type,:content=>content}
                      ),
        block.binding)
end
fb_multi_friend_selector(message,options={},&block) click to toggle source

Render an <fb:multi-friend-selector> with the passed in welcome message Full version shows all profile pics for friends.

See: wiki.developers.facebook.com/index.php/Fb:multi-friend-selector for options Note: I don’t think the block is used here.

# File lib/facebooker/rails/helpers.rb, line 149
def fb_multi_friend_selector(message,options={},&block)
  options = options.dup
  tag("fb:multi-friend-selector",stringify_vals({:showborder=>false,:actiontext=>message,:max=>20}.merge(options)))
end
fb_multi_friend_selector_condensed(options={},&block) click to toggle source

Render a condensed <fb:multi-friend-selector> with the passed in welcome message Condensed version show checkboxes for each friend. See: wiki.developers.facebook.com/index.php/Fb:multi-friend-selector_%28condensed%29 for options Note: I don’t think the block is used here.

# File lib/facebooker/rails/helpers.rb, line 158
def fb_multi_friend_selector_condensed(options={},&block)
  options = options.dup
  tag("fb:multi-friend-selector",stringify_vals(options.merge(:condensed=>true)))
end
fb_name(user, options={}) click to toggle source

Render an fb:name tag for the given user This renders the name of the user specified. You can use this tag as both subject and object of a sentence. See wiki.developers.facebook.com/index.php/Fb:name for full description.

Use this tag on FBML pages instead of retrieving the user’s info and rendering the name explicitly.

# File lib/facebooker/rails/helpers.rb, line 241
def fb_name(user, options={})
  options = options.dup
  options.transform_keys!(FB_NAME_OPTION_KEYS_TO_TRANSFORM)
  options.assert_valid_keys(FB_NAME_VALID_OPTION_KEYS)
  options.merge!(:uid => cast_to_facebook_id(user))
  content_tag("fb:name",nil, stringify_vals(options))
end
fb_narrow(&proc) click to toggle source

Content for the narrow profile box goes in this tag

# File lib/facebooker/rails/helpers.rb, line 470
def fb_narrow(&proc)
  content = capture(&proc)
  versioned_concat(content_tag("fb:narrow", content, {}), proc.binding)
end
fb_photo(photo, options={}) click to toggle source

Render an fb:photo tag. photo is either a Facebooker::Photo or an id of a Facebook photo or an object that responds to photo_id. See: wiki.developers.facebook.com/index.php/Fb:photo for complete list of options.

# File lib/facebooker/rails/helpers.rb, line 325
def fb_photo(photo, options={})
  options = options.dup
  options.assert_valid_keys(FB_PHOTO_VALID_OPTION_KEYS)
  options.merge!(:pid => cast_to_photo_id(photo))
  validate_fb_photo_size(options)
  validate_fb_photo_align_value(options)
  content_tag("fb:photo",nil, stringify_vals(options))
end
fb_profile_pic(user, options={}) click to toggle source

Render an <fb:profile-pic> for the specified user.

You can optionally specify the size using the :size=> option. Valid sizes are :thumb, :small, :normal and :square. Or, you can specify width and height settings instead, just like an img tag.

You can optionally specify whether or not to include the facebook icon overlay using the :facebook_logo => true option. Default is false.

# File lib/facebooker/rails/helpers.rb, line 309
def fb_profile_pic(user, options={})
  options = options.dup
  validate_fb_profile_pic_size(options)
  options.transform_keys!(FB_PROFILE_PIC_OPTION_KEYS_TO_TRANSFORM)
  options.assert_valid_keys(FB_PROFILE_PIC_VALID_OPTION_KEYS)
  options.merge!(:uid => cast_to_facebook_id(user))
  content_tag("fb:profile-pic", nil,stringify_vals(options))
end
fb_prompt_permission(permission,message,callback=nil) click to toggle source

Renders a link that, when clicked, initiates a dialog requesting the specified extended permission from the user.

You can prompt a user with the following permissions:

* email
* read_stream
* publish_stream
* offline_access
* status_update
* photo_upload
* create_event
* rsvp_event
* sms
* video_upload
* create_note
* share_item
* read_mailbox

Example: <%= #fb_prompt_permission(‘email’, “Would you like to receive email from our application?” ) %>

See wiki.developers.facebook.com/index.php/Fb:prompt-permission for more details. Correct as of 7th June 2009.

# File lib/facebooker/rails/helpers.rb, line 634
def fb_prompt_permission(permission,message,callback=nil)
  raise(ArgumentError, "Unknown value for permission: #{permission}") unless VALID_PERMISSIONS.include?(permission.to_sym)
  args={:perms=>permission}
  args[:next_fbjs]=callback unless callback.nil?
  content_tag("fb:prompt-permission",message,args)
end
fb_prompt_permissions(permissions,message,callback=nil) click to toggle source

Renders a link to prompt for multiple permissions at once.

Example: <%= fb_prompt_permissions(, ‘Would you like to grant some permissions?’)

# File lib/facebooker/rails/helpers.rb, line 645
def fb_prompt_permissions(permissions,message,callback=nil)
  permissions.each do |p|
    raise(ArgumentError, "Unknown value for permission: #{p}") unless VALID_PERMISSIONS.include?(p.to_sym)          
  end
  args={:perms=>permissions*','}
  args[:next_fbjs]=callback unless callback.nil?
  content_tag("fb:prompt-permission",message,args)        
end
fb_pronoun(user, options={}) click to toggle source

Render an <fb:pronoun> tag for the specified user Options give flexibility for placing in any part of a sentence. See wiki.developers.facebook.com/index.php/Fb:pronoun for complete list of options.

# File lib/facebooker/rails/helpers.rb, line 262
def fb_pronoun(user, options={})
  options = options.dup
  options.transform_keys!(FB_PRONOUN_OPTION_KEYS_TO_TRANSFORM)
  options.assert_valid_keys(FB_PRONOUN_VALID_OPTION_KEYS)
  options.merge!(:uid => cast_to_facebook_id(user))
  content_tag("fb:pronoun",nil, stringify_vals(options))
end
fb_ref(options) click to toggle source

Render an fb:ref tag.

Options must contain either url or handle.

  • url The URL from which to fetch the FBML. You may need to call fbml.refreshRefUrl to refresh cache

  • handle The string previously set by fbml.setRefHandle that identifies the FBML

See wiki.developers.facebook.com/index.php/Fb:ref for complete description

# File lib/facebooker/rails/helpers.rb, line 279
def fb_ref(options)
  options.assert_valid_keys(FB_REF_VALID_OPTION_KEYS)
  validate_fb_ref_has_either_url_or_handle(options)
  validate_fb_ref_does_not_have_both_url_and_handle(options)
  tag("fb:ref", stringify_vals(options))
end
fb_req_choice(label,url) click to toggle source

Render a button in a request using the <fb:req-choice> tag url must be an absolute url This should be used inside the block of an #fb_multi_friend_request

# File lib/facebooker/rails/helpers.rb, line 166
def fb_req_choice(label,url)
  tag "fb:req-choice",:label=>label,:url=>url
end
fb_request_form(type,message_param,url,options={},&block) click to toggle source

Create an fb:request-form without a selector

The block passed to this tag is used as the content of the form

The message param is the name sent to content_for that specifies the body of the message

For example,

<% content_for("invite_message") do %>
  This gets sent in the invite. <%= fb_req_choice("with a button!",new_poke_path) %>
<% end %>
<% fb_request_form("Poke","invite_message",create_poke_path) do %>
  Send a poke to: <%= fb_friend_selector %> <br />
  <%= fb_request_form_submit %>
<% end %>
# File lib/facebooker/rails/helpers.rb, line 89
def fb_request_form(type,message_param,url,options={},&block)
  content = capture(&block)
  message = @template.instance_variable_get("@content_for_#{message_param}")
  versioned_concat(content_tag("fb:request-form", content + token_tag,
            {:action=>url,:method=>"post",:invite=>true,:type=>type,:content=>message}.merge(options)),
        block.binding)
end
fb_request_form_submit(options={}) click to toggle source

Create a submit button for an <fb:request-form> If the request is for an individual user you can optionally Provide the user and a label for the request button. For example

<% content_for("invite_user") do %>
  This gets sent in the invite. <%= fb_req_choice("Come join us!",new_invite_path) %>
<% end %>
<% fb_request_form("Invite","invite_user",create_invite_path) do %>
  Invite <%= fb_name(@facebook_user.friends.first.id)%> to the party <br />
  <%= fb_request_form_submit(:uid => @facebook_user.friends.first.id, :label => "Invite %n") %>
<% end %>

See: wiki.developers.facebook.com/index.php/Fb:request-form-submit for options

# File lib/facebooker/rails/helpers.rb, line 109
def fb_request_form_submit(options={})
   tag("fb:request-form-submit",stringify_vals(options))
end
fb_serverfbml(options={},&proc) click to toggle source

Renders the FBML on a Facebook server inside an iframe.

Meant to be used for a Facebook Connect site or an iframe application

# File lib/facebooker/rails/helpers.rb, line 677
def fb_serverfbml(options={},&proc)
  inner = capture(&proc)
  versioned_concat(content_tag("fb:serverfbml",inner,options), proc.binding)
end
fb_share_button(url) click to toggle source

Renders a standard ‘Share’ button for the specified URL.

# File lib/facebooker/rails/helpers.rb, line 670
def fb_share_button(url)
  content_tag "fb:share-button",nil,:class=>"url",:href=>url
end
fb_show_feed_dialog(action, user_message = "", prompt = "", callback = nil) click to toggle source
# File lib/facebooker/rails/helpers.rb, line 67
def fb_show_feed_dialog(action, user_message = "", prompt = "", callback = nil)
  update_page do |page|
    page.call "Facebook.showFeedDialog",action.template_id,action.data,action.body_general,action.target_ids,callback,prompt,user_message
  end
end
fb_stream_publish(stream_post,user_message_prompt=nil,callback=nil,auto_publish=false,actor=nil) click to toggle source
# File lib/facebooker/rails/helpers.rb, line 32
def fb_stream_publish(stream_post,user_message_prompt=nil,callback=nil,auto_publish=false,actor=nil)
  stream_publish("Facebook.streamPublish",stream_post,user_message_prompt,callback,auto_publish,actor)
end
fb_success(message, text=nil) click to toggle source

Render an <fb:success> tag If message and text are present then this will render fb:error and fb:message tag TODO: Optionally takes a decoration tag with value of ‘no_padding’ or ‘shorten’

# File lib/facebooker/rails/helpers.rb, line 424
def fb_success(message, text=nil)
  fb_status_msg("success", message, text)
end
fb_swf(src, options = {}) click to toggle source
# File lib/facebooker/rails/helpers.rb, line 46
def fb_swf(src, options = {})
  tag "fb:swf", options.merge(:swfsrc => src)
end
fb_tab_item(title, url, options={}) click to toggle source

Render an fb:tab_item tag. Use this in conjunction with #fb_tabs Options can contains :selected => true to indicate that a tab is the current tab. See: wiki.developers.facebook.com/index.php/Fb:tab-item for complete list of options

# File lib/facebooker/rails/helpers.rb, line 361
def fb_tab_item(title, url, options={})
  options= options.dup
  options.assert_valid_keys(FB_TAB_ITEM_VALID_OPTION_KEYS)
  options.merge!(:title => title, :href => url)    
  validate_fb_tab_item_align_value(options)
  tag("fb:tab-item", stringify_vals(options))
end
fb_tabs(&block) click to toggle source

Render an fb:tabs tag containing some number of fb:tab_item tags. Example: <% #fb_tabs do %>

<%= fb_tab_item("Home", "home") %>
<%= fb_tab_item("Office", "office") %>

<% end %>

# File lib/facebooker/rails/helpers.rb, line 352
def fb_tabs(&block)
  content = capture(&block)
  versioned_concat(content_tag("fb:tabs", content), block.binding)
end
fb_time(time, options={}) click to toggle source

Renders an fb:time element

Example: <%= #fb_time(Time.now, :tz => ‘America/New York’, :preposition => true) %>

See wiki.developers.facebook.com/index.php/Fb:time for more details

# File lib/facebooker/rails/helpers.rb, line 694
def fb_time(time, options={})
  tag "fb:time",stringify_vals({:t => time.to_i}.merge(options))
end
fb_title(title) click to toggle source

Adds a title to the title bar

Facebook | App Name | This is the canvas page window title

title: This is the canvas page window

# File lib/facebooker/rails/helpers.rb, line 506
def fb_title(title)
 "<fb:title>#{title}</fb:title>"
end
fb_user_status(user,linked=true) click to toggle source

Returns the status of the user

# File lib/facebooker/rails/helpers.rb, line 665
def fb_user_status(user,linked=true)
  content_tag "fb:user-status",nil,stringify_vals(:uid=>cast_to_facebook_id(user), :linked=>linked)
end
fb_wall(&proc) click to toggle source

Create a Facebook wall. It can contain fb_wall_posts

For Example:

<% fb_wall do %>
  <%= fb_wall_post(@user,"This is my message") %>
  <%= fb_wall_post(@otheruser,"This is another message") %>
<% end %>
# File lib/facebooker/rails/helpers.rb, line 395
def fb_wall(&proc)
  content = capture(&proc)
  versioned_concat(content_tag("fb:wall",content,{}),proc.binding)
end
fb_wall_post(user,message) click to toggle source
Alias for: fb_wallpost
fb_wallpost(user,message) click to toggle source

Render an <fb:wallpost> tag TODO: Optionally takes a time parameter t = int The current time, which is displayed in epoch seconds.

# File lib/facebooker/rails/helpers.rb, line 402
def fb_wallpost(user,message)
  content_tag("fb:wallpost",message,:uid=>cast_to_facebook_id(user))
end
Also aliased as: fb_wall_post
fb_wide(&proc) click to toggle source

Content for the wide profile box goes in this tag

# File lib/facebooker/rails/helpers.rb, line 464
def fb_wide(&proc)
  content = capture(&proc)
  versioned_concat(content_tag("fb:wide", content, {}), proc.binding)
end
fbjs_library() click to toggle source
# File lib/facebooker/rails/helpers.rb, line 37
def fbjs_library
  "<script>var _token = '#{form_authenticity_token}';var _hostname = '#{ActionController::Base.asset_host}'</script>"+
  "#{javascript_include_tag 'facebooker'}"
end
validate_fb_photo_align_value(options) click to toggle source
# File lib/facebooker/rails/helpers.rb, line 377
def validate_fb_photo_align_value(options)
  if options.has_key?(:align) && !VALID_FB_PHOTO_ALIGN_VALUES.include?(options[:align].to_sym)
    raise(ArgumentError, "Unknown value for align: #{options[:align]}")
  end
end
validate_fb_ref_does_not_have_both_url_and_handle(options) click to toggle source
# File lib/facebooker/rails/helpers.rb, line 292
def validate_fb_ref_does_not_have_both_url_and_handle(options)
  if options.has_key?(:url) && options.has_key?(:handle)
    raise ArgumentError, "fb_ref may not have both :url and :handle"
  end
end
validate_fb_ref_has_either_url_or_handle(options) click to toggle source
# File lib/facebooker/rails/helpers.rb, line 286
def validate_fb_ref_has_either_url_or_handle(options)
  unless options.has_key?(:url) || options.has_key?(:handle)
    raise ArgumentError, "fb_ref requires :url or :handle"
  end
end
validate_fb_tab_item_align_value(options) click to toggle source
# File lib/facebooker/rails/helpers.rb, line 371
def validate_fb_tab_item_align_value(options)
  if options.has_key?(:align) && !VALID_FB_TAB_ITEM_ALIGN_VALUES.include?(options[:align].to_sym)
    raise(ArgumentError, "Unknown value for align: #{options[:align]}")
  end
end
versioned_concat(string,binding) click to toggle source
# File lib/facebooker/rails/helpers.rb, line 15
def versioned_concat(string,binding)
  if ignore_binding?
    concat(string)
  else
    concat(string,binding)
  end
end

Protected Instance Methods

cast_to_facebook_id(object) click to toggle source
# File lib/facebooker/rails/helpers.rb, line 765
def cast_to_facebook_id(object)
  Facebooker::User.cast_to_facebook_id(object)
end
validate_fb_photo_size(options) click to toggle source
# File lib/facebooker/rails/helpers.rb, line 775
def validate_fb_photo_size(options)
  if options.has_key?(:size) && !VALID_FB_PHOTO_SIZES.include?(options[:size].to_sym)
    raise(ArgumentError, "Unknown value for size: #{options[:size]}")
  end
end
validate_fb_profile_pic_size(options) click to toggle source
# File lib/facebooker/rails/helpers.rb, line 769
def validate_fb_profile_pic_size(options)
  if options.has_key?(:size) && !VALID_FB_PROFILE_PIC_SIZES.include?(options[:size].to_sym)
    raise(ArgumentError, "Unknown value for size: #{options[:size]}")
  end
end