grimen (owner)

Revisions

gist: 197026 Download_button fork
public
Public Clone URL: git://gist.github.com/197026.git
Embed All Files: show embed
AccountHelper #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
module AccountHelper
  
  def login_link(*args)
    options = args.extract_options!
    options.reverse_merge!(
        :label => t('formtastic.actions.account_session.new')
      )
    session_type = args.first.is_a?(Symbol) ? args.shift : :standard
    
    case session_type
    when :standard
      link_to options[:label], new_account_session_path
    when :facebook
      options.reverse_merge!(
          :size => :large,
          :length => :long,
          :autologoutlink => false,
          :background => :white,
          :button => true
        )
      render '/accounts/helpers/fb_connect_login', :options => options
    end
  end
  
  def logout_link(*args)
    options = args.extract_options!
    options.reverse_merge!(
        :label => t('formtastic.actions.account_session.destroy')
      )
    session_type = args.first.is_a?(Symbol) ? args.shift : :standard
    
    # Use Facebook logout by default if the logged in user is FB-connected.
    session_type = :facebook if current_account && current_account.using_facebook_connect?
    
    case session_type
    when :standard
      link_to options[:label], destroy_account_session_path, :method => :delete
    when :facebook
      options.reverse_merge!(
          :size => :small,
          :length => :long,
          :background => :dark,
          :button => false
        )
      render '/accounts/helpers/fb_connect_logout', :options => options
    end
  end
  
end
application.html.haml #
1
2
3
%body
  = fb_connect_javascript_tag :lang => I18n.locale.to_s.gsub('-', '_') # FIXME: Format correctly.
  = init_fb_connect :XFBML, :js => :jquery
login_helper.html.haml #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
.fb_connect_login_wrapper
  - semantic_form_for(AccountSession.new, :url => account_session_path, :html => {:id => 'fb_connect_login_form', :style => 'display:none;'}) { |f| }
  
  :javascript
    function fb_connect_login() {
      jQuery('#fb_connect_login_form').submit();
    };
    
    function fb_connect_login_custom() {
      FB.Connect.requireSession(fb_connect_login);
      return false;
    };
    
  - if options.delete(:button)
    = fb_login_button('fb_connect_login();', options)
  - else
    = link_to_function(options.delete(:label), 'fb_connect_login_custom();')
logout_helper.html.haml #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
.fb_connect_logout_wrapper
  - semantic_form_for(AccountSession.new, :url => destroy_account_session_path, :html => {:method => :delete, :id => 'fb_connect_logout_form', :style => 'display:none;'}) { |f| }
  
  :javascript
    function fb_connect_logout() {
      jQuery('#fb_connect_logout_form').submit();
      return false;
    };
    
    function fb_connect_logout_custom() {
      FB.Connect.logout(fb_connect_logout);
      return false;
    };
    
  - if options.delete(:button)
    = fb_login_button('fb_connect_logout();', options.merge(:autologoutlink => true))
  - else
    = link_to_function(options.delete(:label), 'fb_connect_logout_custom();')