Module: Facebooker::Rails::Helpers::FbConnect
- Included in:
- Facebooker::Rails::Helpers
- Defined in:
- lib/facebooker/rails/helpers/fb_connect.rb
Instance Method Summary collapse
- #fb_connect_javascript_tag ⇒ Object
- #fb_login_and_redirect(url, options = {}) ⇒ Object
-
#fb_login_button(*args) ⇒ Object
Render an <fb:login-button> element.
- #fb_logout_link(text, url, *args) ⇒ Object
- #fb_unconnected_friends_count ⇒ Object
- #fb_user_action(action, user_message = nil, prompt = "", callback = nil) ⇒ Object
-
#init_fb_connect(*required_features, &proc) ⇒ Object
For information on the :app_settings argument see wiki.developers.facebook.com/index.php/JS_API_M_FB.Facebook.Init_2 While it would be nice to treat :app_settings as a hash, some of the arguments do different things if they are a string vs a javascript function and Rails’ Hash#to_json always quotes strings so there is no way to indicate when the value should be a javascript function.
Instance Method Details
#fb_connect_javascript_tag ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/facebooker/rails/helpers/fb_connect.rb', line 6 def fb_connect_javascript_tag if request.ssl? javascript_include_tag "https://www.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php" else javascript_include_tag "http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php" end end |
#fb_login_and_redirect(url, options = {}) ⇒ Object
91 92 93 94 95 96 |
# File 'lib/facebooker/rails/helpers/fb_connect.rb', line 91 def fb_login_and_redirect(url, = {}) js = update_page do |page| page.redirect_to url end content_tag("fb:login-button",nil,.merge(:onlogin=>js)) end |
#fb_login_button(*args) ⇒ Object
Render an <fb:login-button> element
Examples
<%= fb_login_button%>
> <fb:login-button></fb:login-button>
Specifying a javascript callback
<%= fb_login_button ‘update_something();’%>
> <fb:login-button onlogin=‘update_something();’></fb:login-button>
Adding options See: wiki.developers.facebook.com/index.php/Fb:login-button
<%= fb_login_button ‘update_something();’, :size => :small, :background => :dark%>
> <fb:login-button background=‘dark’ onlogin=‘update_something();’ size=‘small’></fb:login-button>
82 83 84 85 86 87 88 89 |
# File 'lib/facebooker/rails/helpers/fb_connect.rb', line 82 def (*args) callback = args.first = args[1] || {} .merge!(:onlogin=>callback)if callback content_tag("fb:login-button",nil, ) end |
#fb_logout_link(text, url, *args) ⇒ Object
102 103 104 105 106 107 |
# File 'lib/facebooker/rails/helpers/fb_connect.rb', line 102 def fb_logout_link(text,url,*args) js = update_page do |page| page.call "FB.Connect.logoutAndRedirect",url end link_to_function text, js, *args end |
#fb_unconnected_friends_count ⇒ Object
98 99 100 |
# File 'lib/facebooker/rails/helpers/fb_connect.rb', line 98 def fb_unconnected_friends_count content_tag "fb:unconnected-friends-count",nil end |
#fb_user_action(action, user_message = nil, prompt = "", callback = nil) ⇒ Object
109 110 111 112 113 114 |
# File 'lib/facebooker/rails/helpers/fb_connect.rb', line 109 def fb_user_action(action, = nil, prompt = "", callback = nil) defaulted_callback = callback || "null" update_page do |page| page.call("FB.Connect.showFeedDialog",action.template_id,action.data,action.target_ids,action.body_general,nil,page.literal("FB.RequireConnect.promptConnect"),page.literal(defaulted_callback),prompt,.nil? ? nil : {:value=>}) end end |
#init_fb_connect(*required_features, &proc) ⇒ Object
For information on the :app_settings argument see wiki.developers.facebook.com/index.php/JS_API_M_FB.Facebook.Init_2 While it would be nice to treat :app_settings as a hash, some of the arguments do different things if they are a string vs a javascript function and Rails’ Hash#to_json always quotes strings so there is no way to indicate when the value should be a javascript function. For this reason :app_settings needs to be a string that is valid JSON (including the {}‘s).
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/facebooker/rails/helpers/fb_connect.rb', line 20 def init_fb_connect(*required_features,&proc) additions = "" if block_given? additions = capture(&proc) end # Yes, app_settings is set to a string of an empty JSON element. That's intentional. = {:js => :prototype, :app_settings => '{}'} if required_features.last.is_a?(Hash) .merge!(required_features.pop.symbolize_keys) end if request.ssl? init_string = "FB.Facebook.init('#{Facebooker.api_key}','/xd_receiver_ssl.html', #{[:app_settings]});" else init_string = "FB.Facebook.init('#{Facebooker.api_key}','/xd_receiver.html', #{[:app_settings]});" end unless required_features.blank? init_string = <<-FBML #{case [:js] when :jquery then "$(document).ready(" when :dojo then "dojo.addOnLoad(" else "Element.observe(window,'load'," end} function() { FB_RequireFeatures(#{required_features.to_json}, function() { #{init_string} #{additions} }); }); FBML end # block_is_within_action_view? is rails 2.1.x and has been # deprecated. rails >= 2.2.x uses block_called_from_erb? block_tester = respond_to?(:block_is_within_action_view?) ? :block_is_within_action_view? : :block_called_from_erb? if block_given? && send(block_tester, proc) concat(javascript_tag(init_string)) else javascript_tag init_string end end |