Module: Facebooker2::Rails::Helpers::FacebookConnect
- Included in:
- Facebooker2::Rails::Helpers
- Defined in:
- lib/facebooker2/rails/helpers/facebook_connect.rb
Instance Method Summary collapse
- #fb_login(options = {}, &proc) ⇒ Object
-
#fb_login_and_redirect(url, options = {}) ⇒ Object
Render an <fb:login-button> element, similar to fb_login_button.
-
#fb_logout_link(text, url, *args) ⇒ Object
Logs the user out of facebook and redirects to the given URL args are passed to the call to link_to_function.
- #fb_server_fbml(style = nil, width = nil, &proc) ⇒ Object
Instance Method Details
#fb_login(options = {}, &proc) ⇒ Object
35 36 37 38 39 |
# File 'lib/facebooker2/rails/helpers/facebook_connect.rb', line 35 def fb_login( = {},&proc) js = capture(&proc) text = .delete(:text) concat(content_tag("fb:login-button",text,.merge(:onlogin=>js.to_str))) end |
#fb_login_and_redirect(url, options = {}) ⇒ Object
Render an <fb:login-button> element, similar to fb_login_button. Adds a js redirect to the onlogin event via rjs.
Examples
fb_login_and_redirect '/other_page'
=> <fb:login-button onlogin="window.location.href = "/other_page";"></fb:login-button>
Like #fb_login_button, this also supports the :text option
fb_login_and_redirect '/other_page', :text => "Login with Facebook", :v => '2'
=> <fb:login-button onlogin="window.location.href = "/other_page";" v="2">Login with Facebook</fb:login-button>
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/facebooker2/rails/helpers/facebook_connect.rb', line 19 def fb_login_and_redirect(url, = {}) # Check if we got the update_page method (pre-Rails 3.1) if respond_to? 'update_page' js = update_page do |page| page.redirect_to url end # Else use plain js else js = "window.location.href = '#{url}'" end text = .delete(:text) #rails 3 only escapes non-html_safe strings, so get the raw string instead of the SafeBuffer content_tag("fb:login-button",text,.merge(:onlogin=>js.to_str)) end |
#fb_logout_link(text, url, *args) ⇒ Object
Logs the user out of facebook and redirects to the given URL
args are passed to the call to link_to_function
44 45 46 47 |
# File 'lib/facebooker2/rails/helpers/facebook_connect.rb', line 44 def fb_logout_link(text,url,*args) function= "FB.logout(function() {window.location.href = '#{url}';})" link_to_function text, function.to_str, *args end |
#fb_server_fbml(style = nil, width = nil, &proc) ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/facebooker2/rails/helpers/facebook_connect.rb', line 49 def fb_server_fbml(style=nil, width=nil, &proc) style_string=" style=\"#{style}\"" if style width_string=" width=\"#{width}\"" if width content = capture(&proc) output = "<fb:serverFbml#{style_string}#{width_string}><script type='text/fbml'><fb:fbml>#{content}</fb:fbml></script></fb:serverFbml>" output = output.respond_to?(:html_safe) ? output.html_safe : output concat(output) end |