Module: Facebooker::Rails::Helpers
- Defined in:
- lib/facebooker/rails/helpers.rb
Overview
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.
Constant Summary collapse
- FB_DIALOG_BUTTON_VALID_OPTION_KEYS =
[:close_dialog, :href, :form_id, :clickrewriteurl, :clickrewriteid, :clickrewriteform]
- FB_NAME_OPTION_KEYS_TO_TRANSFORM =
{:first_name_only => :firstnameonly, :last_name_only => :lastnameonly, :show_network => :shownetwork, :use_you => :useyou, :if_cant_see => :ifcantsee, :subject_id => :subjectid}
- FB_NAME_VALID_OPTION_KEYS =
[:firstnameonly, :linked, :lastnameonly, :possessive, :reflexive, :shownetwork, :useyou, :ifcantsee, :capitalize, :subjectid]
- FB_PRONOUN_OPTION_KEYS_TO_TRANSFORM =
{:use_you => :useyou, :use_they => :usethey}
- FB_PRONOUN_VALID_OPTION_KEYS =
[:useyou, :possessive, :reflexive, :objective, :usethey, :capitalize]
- FB_REF_VALID_OPTION_KEYS =
[:url, :handle]
- FB_PHOTO_VALID_OPTION_KEYS =
[:uid, :size, :align]
- VALID_FB_SHARED_PHOTO_SIZES =
[:thumb, :small, :normal, :square]
- VALID_FB_PHOTO_SIZES =
VALID_FB_SHARED_PHOTO_SIZES
- VALID_FB_PROFILE_PIC_SIZES =
VALID_FB_SHARED_PHOTO_SIZES
- VALID_PERMISSIONS =
[:email, :offline_access, :status_update, :photo_upload, :create_listing]
- FB_TAB_ITEM_VALID_OPTION_KEYS =
[:align, :selected]
- VALID_FB_SHARED_ALIGN_VALUES =
[:left, :right]
- VALID_FB_PHOTO_ALIGN_VALUES =
VALID_FB_SHARED_ALIGN_VALUES
- VALID_FB_TAB_ITEM_ALIGN_VALUES =
VALID_FB_SHARED_ALIGN_VALUES
Instance Method Summary collapse
- #cast_to_photo_id(object) ⇒ Object
-
#facebook_form_for(record_or_name_or_array, *args, &proc) ⇒ Object
Create a facebook form using <fb:editor>.
-
#facebook_messages ⇒ Object
Render flash values as <fb:message> and <fb:error> tags.
-
#fb_about_url ⇒ Object
Return the URL for the about page of the application.
-
#fb_action(name, url) ⇒ Object
Renders an action using the <fb:action> tag.
- #fb_add_info_section ⇒ Object
- #fb_add_profile_section ⇒ Object
-
#fb_board(xid, options = {}) ⇒ Object
Embed a discussion board named xid on the current page.
-
#fb_comments(xid, canpost = true, candelete = false, numposts = 5, options = {}) ⇒ Object
Create a comment area All the data for this content area is stored on the facebook servers.
-
#fb_create_button(name, url) ⇒ Object
Render a <fb:create-button> tag For use inside <fb:dashboard>.
-
#fb_dashboard(&proc) ⇒ Object
Create a dashboard.
-
#fb_dialog(id, cancel_button, &block) ⇒ Object
Create an fb:dialog id must be a unique name e.g.
- #fb_dialog_button(type, value, options = {}) ⇒ Object
- #fb_dialog_content(&block) ⇒ Object
- #fb_dialog_title(title) ⇒ Object
-
#fb_else(&proc) ⇒ Object
Render fb:else tag Must be used within if block such as fb_if_is_user or fb_if_is_app_user .
-
#fb_error(message, text = nil) ⇒ Object
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’.
-
#fb_explanation(message, text = nil) ⇒ Object
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’.
-
#fb_friend_selector(options = {}) ⇒ Object
Render an <fb:friend-selector> element See: wiki.developers.facebook.com/index.php/Fb:friend-selector for options.
-
#fb_google_analytics(uacct, options = {}) ⇒ Object
Create a Google Analytics tag.
-
#fb_help(name, url) ⇒ Object
Render a <fb:help> tag For use inside <fb:dashboard>.
-
#fb_if_is_app_user(user, options = {}, &proc) ⇒ Object
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.
-
#fb_if_is_user(user, &proc) ⇒ Object
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.
-
#fb_if_user_has_added_app(user, options = {}, &proc) ⇒ Object
Render if-user-has-added-app tag This tag renders the enclosing content only if the user specified has installed the application .
-
#fb_multi_friend_input(options = {}) ⇒ Object
Render an <fb:multi-friend-input> element See: wiki.developers.facebook.com/index.php/Fb:multi-friend-input for options.
-
#fb_multi_friend_request(type, friend_selector_message, url, &block) ⇒ Object
Create an fb:request-form with an fb_multi_friend_selector inside.
-
#fb_multi_friend_selector(message, options = {}, &block) ⇒ Object
Render an <fb:multi-friend-selector> with the passed in welcome message Full version shows all profile pics for friends.
-
#fb_multi_friend_selector_condensed(options = {}, &block) ⇒ Object
Render a condensed <fb:multi-friend-selector> with the passed in welcome message Condensed version show checkboxes for each friend.
-
#fb_name(user, options = {}) ⇒ Object
Render an fb:name tag for the given user This renders the name of the user specified.
-
#fb_narrow(&proc) ⇒ Object
Content for the narrow profile box goes in this tag.
-
#fb_photo(photo, options = {}) ⇒ Object
Render an fb:photo tag.
-
#fb_profile_pic(user, options = {}) ⇒ Object
Render an <fb:profile-pic> for the specified user.
- #fb_prompt_permission(permission, message, callback = nil) ⇒ Object
-
#fb_pronoun(user, options = {}) ⇒ Object
Render an <fb:pronoun> tag for the specified user Options give flexibility for placing in any part of a sentence.
-
#fb_ref(options) ⇒ Object
Render an fb:ref tag.
-
#fb_req_choice(label, url) ⇒ Object
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.
-
#fb_request_form(type, message_param, url, options = {}, &block) ⇒ Object
Create an fb:request-form without a selector.
-
#fb_request_form_submit(options = {}) ⇒ Object
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.
-
#fb_success(message, text = nil) ⇒ Object
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’.
-
#fb_tab_item(title, url, options = {}) ⇒ Object
Render an fb:tab_item tag.
-
#fb_tabs(&block) ⇒ Object
<%= fb_tab_item(“Home”, “home”) %> <%= fb_tab_item(“Office”, “office”) %> <% end %>.
-
#fb_title(title) ⇒ Object
title
: This is the canvas page window. -
#fb_wall(&proc) ⇒ Object
Create a Facebook wall.
-
#fb_wallpost(user, message) ⇒ Object
(also: #fb_wall_post)
Render an <fb:wallpost> tag TODO: Optionally takes a time parameter t = int The current time, which is displayed in epoch seconds.
-
#fb_wide(&proc) ⇒ Object
Content for the wide profile box goes in this tag.
- #validate_fb_photo_align_value(options) ⇒ Object
- #validate_fb_ref_does_not_have_both_url_and_handle(options) ⇒ Object
- #validate_fb_ref_has_either_url_or_handle(options) ⇒ Object
- #validate_fb_tab_item_align_value(options) ⇒ Object
Instance Method Details
#cast_to_photo_id(object) ⇒ Object
279 280 281 |
# File 'lib/facebooker/rails/helpers.rb', line 279 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) ⇒ Object
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>
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/facebooker/rails/helpers.rb', line 152 def facebook_form_for( record_or_name_or_array,*args, &proc) raise ArgumentError, "Missing block" unless block_given? = 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) (record_or_name_or_array, ) args.unshift object else object = record_or_name_or_array object_name = ActionController::RecordIdentifier.singular_class_name(object) ([object], ) args.unshift object end method = ([:html]||{})[:method] [:builder] ||= Facebooker::Rails::FacebookFormBuilder ={} action=.delete(:url) [:action]= action unless action.blank? width=.delete(:width) [:width]=width unless width.blank? width=.delete(:labelwidth) [:labelwidth]=width unless width.blank? concat(tag("fb:editor",,true) , proc.binding) concat(tag(:input,{:type=>"hidden",:name=>:_method, :value=>method},false), proc.binding) unless method.blank? concat(token_tag, proc.binding) fields_for( object_name,*(args << ), &proc) concat("</fb:editor>",proc.binding) end |
#facebook_messages ⇒ Object
376 377 378 379 380 381 382 383 384 385 |
# File 'lib/facebooker/rails/helpers.rb', line 376 def ="" unless flash[:notice].blank? += fb_success(flash[:notice]) end unless flash[:error].blank? += fb_error(flash[:error]) end end |
#fb_about_url ⇒ Object
Return the URL for the about page of the application
520 521 522 |
# File 'lib/facebooker/rails/helpers.rb', line 520 def fb_about_url "http://#{Facebooker.www_server_base_url}/apps/application.php?api_key=#{Facebooker.api_key}" end |
#fb_action(name, url) ⇒ Object
Renders an action using the <fb:action> tag
418 419 420 |
# File 'lib/facebooker/rails/helpers.rb', line 418 def fb_action(name, url) "<fb:action href=\"#{url_for(url)}\">#{name}</fb:action>" end |
#fb_add_info_section ⇒ Object
536 537 538 |
# File 'lib/facebooker/rails/helpers.rb', line 536 def fb_add_info_section tag "fb:add-section-button",:section=>"info" end |
#fb_add_profile_section ⇒ Object
532 533 534 |
# File 'lib/facebooker/rails/helpers.rb', line 532 def fb_add_profile_section tag "fb:add-section-button",:section=>"profile" end |
#fb_board(xid, options = {}) ⇒ Object
Embed a discussion board named xid on the current page
527 528 529 530 |
# File 'lib/facebooker/rails/helpers.rb', line 527 def fb_board(xid,={}) = .dup tag("fb:board",stringify_vals(.merge(:xid=>xid))) end |
#fb_comments(xid, canpost = true, candelete = false, numposts = 5, options = {}) ⇒ Object
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
437 438 439 440 441 |
# File 'lib/facebooker/rails/helpers.rb', line 437 def fb_comments(xid,canpost=true,candelete=false,numposts=5,={}) = .dup title = (title = .delete(:title)) ? fb_title(title) : nil content_tag "fb:comments",title,stringify_vals(.merge(:xid=>xid,:canpost=>canpost.to_s,:candelete=>candelete.to_s,:numposts=>numposts)) end |
#fb_create_button(name, url) ⇒ Object
Render a <fb:create-button> tag For use inside <fb:dashboard>
430 431 432 |
# File 'lib/facebooker/rails/helpers.rb', line 430 def (name, url) "<fb:create-button href=\"#{url_for(url)}\">#{name}</fb:create-button>" end |
#fb_dashboard(&proc) ⇒ Object
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 %>
396 397 398 399 400 401 402 403 |
# File 'lib/facebooker/rails/helpers.rb', line 396 def fb_dashboard(&proc) if block_given? content = capture(&proc) concat(content_tag("fb:dashboard",content,{}),proc.binding) else content_tag("fb:dashboard",content,{}) end end |
#fb_dialog(id, cancel_button, &block) ⇒ Object
Create an fb:dialog id must be a unique name e.g. “my_dialog” cancel_button is true or false
15 16 17 18 |
# File 'lib/facebooker/rails/helpers.rb', line 15 def fb_dialog( id, , &block ) content = capture(&block) concat( content_tag("fb:dialog", content, {:id => id, :cancel_button => }), block.binding ) end |
#fb_dialog_button(type, value, options = {}) ⇒ Object
29 30 31 32 33 |
# File 'lib/facebooker/rails/helpers.rb', line 29 def ( type, value, ={} ) .assert_valid_keys FB_DIALOG_BUTTON_VALID_OPTION_KEYS .merge! :type => type, :value => value tag "fb:dialog-button", end |
#fb_dialog_content(&block) ⇒ Object
24 25 26 27 |
# File 'lib/facebooker/rails/helpers.rb', line 24 def fb_dialog_content( &block ) content = capture(&block) concat( content_tag("fb:dialog-content", content), block.binding ) end |
#fb_dialog_title(title) ⇒ Object
20 21 22 |
# File 'lib/facebooker/rails/helpers.rb', line 20 def fb_dialog_title( title ) content_tag "fb:dialog-title", title end |
#fb_else(&proc) ⇒ Object
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
513 514 515 516 |
# File 'lib/facebooker/rails/helpers.rb', line 513 def fb_else(&proc) content = capture(&proc) concat(content_tag("fb:else",content),proc.binding) end |
#fb_error(message, text = nil) ⇒ Object
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’
352 353 354 |
# File 'lib/facebooker/rails/helpers.rb', line 352 def fb_error(, text=nil) fb_status_msg("error", , text) end |
#fb_explanation(message, text = nil) ⇒ Object
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’
359 360 361 |
# File 'lib/facebooker/rails/helpers.rb', line 359 def fb_explanation(, text=nil) fb_status_msg("explanation", , text) end |
#fb_friend_selector(options = {}) ⇒ Object
Render an <fb:friend-selector> element See: wiki.developers.facebook.com/index.php/Fb:friend-selector for options
98 99 100 |
# File 'lib/facebooker/rails/helpers.rb', line 98 def fb_friend_selector(={}) tag("fb:friend-selector",stringify_vals()) end |
#fb_google_analytics(uacct, options = {}) ⇒ Object
Create a Google Analytics tag
uacct
: Your Urchin/Google Analytics account ID.
455 456 457 458 |
# File 'lib/facebooker/rails/helpers.rb', line 455 def fb_google_analytics(uacct, ={}) = .dup tag "fb:google-analytics", stringify_vals(.merge(:uacct => uacct)) end |
#fb_help(name, url) ⇒ Object
Render a <fb:help> tag For use inside <fb:dashboard>
424 425 426 |
# File 'lib/facebooker/rails/helpers.rb', line 424 def fb_help(name, url) "<fb:help href=\"#{url_for(url)}\">#{name}</fb:help>" end |
#fb_if_is_app_user(user, options = {}, &proc) ⇒ Object
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 %>
470 471 472 473 474 475 |
# File 'lib/facebooker/rails/helpers.rb', line 470 def fb_if_is_app_user(user,={},&proc) content = capture(&proc) = .dup .merge!(:uid=>cast_to_facebook_id(user)) if user concat(content_tag("fb:if-is-app-user",content,stringify_vals()),proc.binding) end |
#fb_if_is_user(user, &proc) ⇒ Object
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 %>
504 505 506 507 508 509 |
# File 'lib/facebooker/rails/helpers.rb', line 504 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(",") concat(content_tag("fb:if-is-user",content,{:uid=>user_list}),proc.binding) end |
#fb_if_user_has_added_app(user, options = {}, &proc) ⇒ Object
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 %>
487 488 489 490 491 |
# File 'lib/facebooker/rails/helpers.rb', line 487 def fb_if_user_has_added_app(user,={},&proc) content = capture(&proc) = .dup concat(content_tag("fb:if-user-has-added-app",content,stringify_vals(.merge(:uid=>cast_to_facebook_id(user)))),proc.binding) end |
#fb_multi_friend_input(options = {}) ⇒ Object
Render an <fb:multi-friend-input> element See: wiki.developers.facebook.com/index.php/Fb:multi-friend-input for options
104 105 106 |
# File 'lib/facebooker/rails/helpers.rb', line 104 def fb_multi_friend_input(={}) tag "fb:multi-friend-input",stringify_vals() end |
#fb_multi_friend_request(type, friend_selector_message, url, &block) ⇒ Object
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,
For example:
<% fb_multi_friend_request("Poke","Choose some friends to Poke",create_poke_path) do %>
If you select some friends, they will see this message.
<%= fb_req_choice("They will get this button, too",new_poke_path) %>
<% end %>
86 87 88 89 90 91 92 93 |
# File 'lib/facebooker/rails/helpers.rb', line 86 def fb_multi_friend_request(type,,url,&block) content = capture(&block) concat(content_tag("fb:request-form", fb_multi_friend_selector() + token_tag, {:action=>url,:method=>"post",:invite=>true,:type=>type,:content=>content} ), block.binding) end |
#fb_multi_friend_selector(message, options = {}, &block) ⇒ Object
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.
112 113 114 115 |
# File 'lib/facebooker/rails/helpers.rb', line 112 def fb_multi_friend_selector(,={},&block) = .dup tag("fb:multi-friend-selector",stringify_vals(.merge(:showborder=>false,:actiontext=>,:max=>20))) end |
#fb_multi_friend_selector_condensed(options = {}, &block) ⇒ Object
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.
121 122 123 124 |
# File 'lib/facebooker/rails/helpers.rb', line 121 def fb_multi_friend_selector_condensed(={},&block) = .dup tag("fb:multi-friend-selector",stringify_vals(.merge(:condensed=>true))) end |
#fb_name(user, options = {}) ⇒ Object
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.
194 195 196 197 198 199 200 |
# File 'lib/facebooker/rails/helpers.rb', line 194 def fb_name(user, ={}) = .dup .transform_keys!(FB_NAME_OPTION_KEYS_TO_TRANSFORM) .assert_valid_keys(FB_NAME_VALID_OPTION_KEYS) .merge!(:uid => cast_to_facebook_id(user)) tag("fb:name", stringify_vals()) end |
#fb_narrow(&proc) ⇒ Object
Content for the narrow profile box goes in this tag
412 413 414 415 |
# File 'lib/facebooker/rails/helpers.rb', line 412 def fb_narrow(&proc) content = capture(&proc) concat(content_tag("fb:narrow", content, {}), proc.binding) end |
#fb_photo(photo, options = {}) ⇒ Object
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.
268 269 270 271 272 273 274 275 |
# File 'lib/facebooker/rails/helpers.rb', line 268 def fb_photo(photo, ={}) = .dup .assert_valid_keys(FB_PHOTO_VALID_OPTION_KEYS) .merge!(:pid => cast_to_photo_id(photo)) validate_fb_photo_size() validate_fb_photo_align_value() tag("fb:photo", stringify_vals()) end |
#fb_profile_pic(user, options = {}) ⇒ Object
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
258 259 260 261 262 263 |
# File 'lib/facebooker/rails/helpers.rb', line 258 def fb_profile_pic(user, ={}) = .dup validate_fb_profile_pic_size() .merge!(:uid => cast_to_facebook_id(user)) tag("fb:profile-pic", stringify_vals()) end |
#fb_prompt_permission(permission, message, callback = nil) ⇒ Object
540 541 542 543 544 545 |
# File 'lib/facebooker/rails/helpers.rb', line 540 def (,,callback=nil) raise(ArgumentError, "Unknown value for permission: #{}") unless VALID_PERMISSIONS.include?(.to_sym) args={:perms=>} args[:next_fbjs]=callback unless callback.nil? content_tag("fb:prompt-permission",,args) end |
#fb_pronoun(user, options = {}) ⇒ Object
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.
215 216 217 218 219 220 221 |
# File 'lib/facebooker/rails/helpers.rb', line 215 def fb_pronoun(user, ={}) = .dup .transform_keys!(FB_PRONOUN_OPTION_KEYS_TO_TRANSFORM) .assert_valid_keys(FB_PRONOUN_VALID_OPTION_KEYS) .merge!(:uid => cast_to_facebook_id(user)) tag("fb:pronoun", stringify_vals()) end |
#fb_ref(options) ⇒ Object
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
232 233 234 235 236 237 |
# File 'lib/facebooker/rails/helpers.rb', line 232 def fb_ref() .assert_valid_keys(FB_REF_VALID_OPTION_KEYS) validate_fb_ref_has_either_url_or_handle() validate_fb_ref_does_not_have_both_url_and_handle() tag("fb:ref", stringify_vals()) end |
#fb_req_choice(label, url) ⇒ Object
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
129 130 131 |
# File 'lib/facebooker/rails/helpers.rb', line 129 def fb_req_choice(label,url) tag "fb:req-choice",:label=>label,:url=>url end |
#fb_request_form(type, message_param, url, options = {}, &block) ⇒ Object
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 %>
52 53 54 55 56 57 58 |
# File 'lib/facebooker/rails/helpers.rb', line 52 def fb_request_form(type,,url,={},&block) content = capture(&block) = @template.instance_variable_get("@content_for_#{}") concat(content_tag("fb:request-form", content + token_tag, {:action=>url,:method=>"post",:invite=>true,:type=>type,:content=>}.merge()), block.binding) end |
#fb_request_form_submit(options = {}) ⇒ Object
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(@facebook_user.friends.first.id,"Invite %n") %>
<% end %>
See: wiki.developers.facebook.com/index.php/Fb:request-form-submit for options
72 73 74 |
# File 'lib/facebooker/rails/helpers.rb', line 72 def fb_request_form_submit(={}) tag("fb:request-form-submit",stringify_vals()) end |
#fb_success(message, text = nil) ⇒ Object
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’
366 367 368 |
# File 'lib/facebooker/rails/helpers.rb', line 366 def fb_success(, text=nil) fb_status_msg("success", , text) end |
#fb_tab_item(title, url, options = {}) ⇒ Object
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
303 304 305 306 307 308 309 |
# File 'lib/facebooker/rails/helpers.rb', line 303 def fb_tab_item(title, url, ={}) = .dup .assert_valid_keys(FB_TAB_ITEM_VALID_OPTION_KEYS) .merge!(:title => title, :href => url) validate_fb_tab_item_align_value() tag("fb:tab-item", stringify_vals()) end |
#fb_tabs(&block) ⇒ Object
<%= fb_tab_item(“Home”, “home”) %>
<%= fb_tab_item(“Office”, “office”) %>
<% end %>
294 295 296 297 |
# File 'lib/facebooker/rails/helpers.rb', line 294 def fb_tabs(&block) content = capture(&block) concat(content_tag("fb:tabs", content), block.binding) end |
#fb_title(title) ⇒ Object
title
: This is the canvas page window
448 449 450 |
# File 'lib/facebooker/rails/helpers.rb', line 448 def fb_title(title) "<fb:title>#{title}</fb:title>" end |
#fb_wall(&proc) ⇒ Object
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 %>
337 338 339 340 |
# File 'lib/facebooker/rails/helpers.rb', line 337 def fb_wall(&proc) content = capture(&proc) concat(content_tag("fb:wall",content,{}),proc.binding) end |
#fb_wallpost(user, message) ⇒ Object Also known as: fb_wall_post
Render an <fb:wallpost> tag TODO: Optionally takes a time parameter t = int The current time, which is displayed in epoch seconds.
344 345 346 |
# File 'lib/facebooker/rails/helpers.rb', line 344 def fb_wallpost(user,) content_tag("fb:wallpost",,:uid=>cast_to_facebook_id(user)) end |
#fb_wide(&proc) ⇒ Object
Content for the wide profile box goes in this tag
406 407 408 409 |
# File 'lib/facebooker/rails/helpers.rb', line 406 def fb_wide(&proc) content = capture(&proc) concat(content_tag("fb:wide", content, {}), proc.binding) end |
#validate_fb_photo_align_value(options) ⇒ Object
319 320 321 322 323 |
# File 'lib/facebooker/rails/helpers.rb', line 319 def validate_fb_photo_align_value() if .has_key?(:align) && !VALID_FB_PHOTO_ALIGN_VALUES.include?([:align].to_sym) raise(ArgumentError, "Unkown value for align: #{[:align]}") end end |
#validate_fb_ref_does_not_have_both_url_and_handle(options) ⇒ Object
245 246 247 248 249 |
# File 'lib/facebooker/rails/helpers.rb', line 245 def validate_fb_ref_does_not_have_both_url_and_handle() if .has_key?(:url) && .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) ⇒ Object
239 240 241 242 243 |
# File 'lib/facebooker/rails/helpers.rb', line 239 def validate_fb_ref_has_either_url_or_handle() unless .has_key?(:url) || .has_key?(:handle) raise ArgumentError, "fb_ref requires :url or :handle" end end |
#validate_fb_tab_item_align_value(options) ⇒ Object
313 314 315 316 317 |
# File 'lib/facebooker/rails/helpers.rb', line 313 def validate_fb_tab_item_align_value() if .has_key?(:align) && !VALID_FB_TAB_ITEM_ALIGN_VALUES.include?([:align].to_sym) raise(ArgumentError, "Unkown value for align: #{[:align]}") end end |