Module: Devise::KoalaConnectable::Helpers
- Defined in:
- lib/devise_koala_connectable/view_helpers.rb
Overview
Koala view helpers to easily add the link to the Facebook connection popup and also the necessary JS code.
Instance Method Summary collapse
-
#javascript_include_koala ⇒ Object
Returns the necessary JS code for the Facebook popup.
-
#koala_login_button(button_text = "Login with Facebook", login_url = "/", registration_url = nil) ⇒ Object
Returns the Login To Facebook button.
-
#koala_logout_button(button_text = "Logout", logout_url = "/", options = {}) ⇒ Object
Returns the Logout button for Facebook.
-
#koala_registration_form(registration_url = "/", fields = [:name, :email, :password], on_validate = nil, locale = "en_EN", width = nil) ⇒ Object
Renders the Facbook Registration Form (XFML).
-
#koala_registration_iframe_form(registration_url = "/", fields = [:name, :email, :password], locale = "en_EN", width = "100%", height = 330) ⇒ Object
Renders the Facbook Registration Form (Iframe).
-
#link_to_koala(link_text, link_url, options = {}) ⇒ Object
Creates the link to the Facebook connection popup.
Instance Method Details
#javascript_include_koala ⇒ Object
Returns the necessary JS code for the Facebook popup. It is recommended to put this code just before the </body> tag of your layout.
For example : … <%= javascript_include_koala %> </body> </html>
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/devise_koala_connectable/view_helpers.rb', line 32 def javascript_include_koala "<div id=\"fb-root\"></div> <script src=\"http://connect.facebook.net/en_US/all.js\"></script> <script> FB.init({ appId:'#{Devise::koala_app_id}', cookie:true, status:true, xfbml:true }); </script>" end |
#koala_login_button(button_text = "Login with Facebook", login_url = "/", registration_url = nil) ⇒ Object
Returns the Login To Facebook button.
For example : … <%= koala_login_button(“Login with Facebook”, “/after_login”) %>
96 97 98 99 100 |
# File 'lib/devise_koala_connectable/view_helpers.rb', line 96 def ( = "Login with Facebook", login_url = "/", registration_url = nil) login_url += (login_url =~ /\?/ ? '&koala=true' : '?koala=true') registration = (registration_url.present?) ? "registration-url=\"#{registration_url}\"" : "" "<fb:login-button #{registration} on-login=\"window.location.href = '#{login_url}';\">#{}</fb:login-button>" end |
#koala_logout_button(button_text = "Logout", logout_url = "/", options = {}) ⇒ Object
Returns the Logout button for Facebook. It calls the logout_url after logging out of Facbook Connect.
For example : … <%= koala_logout_button(“Logout”,“/after_logout”) %>
110 111 112 113 |
# File 'lib/devise_koala_connectable/view_helpers.rb', line 110 def ( = "Logout", logout_url = "/", = {}) = { :unobtrusive => true, :onclick => "FB.getLoginStatus(function(status){if(status.session){FB.logout(function(response){document.location.href='#{logout_url}'});}else{document.location.href='#{logout_url}'}})" }.merge() link_to , "#", end |
#koala_registration_form(registration_url = "/", fields = [:name, :email, :password], on_validate = nil, locale = "en_EN", width = nil) ⇒ Object
Renders the Facbook Registration Form (XFML). For more info: developers.facebook.com/docs/plugins/registration/
For example : … <%= koala_registration_form(“/registration”, [=> “name”, => “password”, :view => “not_prefilled”, => “birthday”, :description => “Geburtstag”, :type => “date”], “callback_function”, “de_DE”, 600) %> …
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/devise_koala_connectable/view_helpers.rb', line 51 def koala_registration_form(registration_url = "/", fields = [:name, :email, :password], on_validate = nil, locale = "en_EN", width = nil) width = (width.present?) ? "width=\"#{width.to_s}\" " : "" on_validate = (on_validate.present?) ? "onvalidate=\"#{on_validate}\" " : "" "<fb:registration fields='" + fields.to_json + "' redirect-uri=\"#{registration_url}\" locale=\"#{locale}\" #{on_validate} #{width}> </fb:registration>" end |
#koala_registration_iframe_form(registration_url = "/", fields = [:name, :email, :password], locale = "en_EN", width = "100%", height = 330) ⇒ Object
Renders the Facbook Registration Form (Iframe). For more info: developers.facebook.com/docs/plugins/registration/
For example : … <%= koala_registration_iframe_form(“/registration”, [=> “name”, => “password”, :view => “not_prefilled”, => “birthday”, :description => “Geburtstag”, :type => “date”], “de_DE”, 600, 400) %> …
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/devise_koala_connectable/view_helpers.rb', line 71 def koala_registration_iframe_form(registration_url = "/", fields = [:name, :email, :password], locale = "en_EN", width = "100%", height = 330) width = (width.present?) ? "width=\"#{width.to_s}\" " : "" height = (height.present?) ? "height=\"#{height.to_s}\" " : "" on_validate = (on_validate.present?) ? "onvalidate=\"#{on_validate}\" " : "" "<iframe src='http://www.facebook.com/plugins/registration.php? client_id=#{Devise::koala_app_id}& redirect_uri=#{CGI.escape(registration_url)}& locale=#{locale}& fields=" + fields.to_json + "' scrolling=\"auto\" frameborder=\"no\" style=\"border:none\" allowTransparency=\"true\" #{width} #{height}> </iframe>" end |
#link_to_koala(link_text, link_url, options = {}) ⇒ Object
Creates the link to the Facebook connection popup. If you create a link without putting the JS code, the popup will load in a new page. The second parameter is the return URL, it must be absolute (***_url).
For example : <%= link_to_koala “Signin using Facebook!”, user_session_url %>
17 18 19 20 21 |
# File 'lib/devise_koala_connectable/view_helpers.rb', line 17 def link_to_koala(link_text, link_url, ={}) = { :unobtrusive => true }.merge() oauth = Koala::Facebook::OAuth.new(Devise::koala_app_id, Devise::koala_secret_key, Devise::koala_callback_url) link_to link_text, oauth.url_for_oauth_code(:callback => link_url), end |