Module: HomePage::Navigation

Defined in:
lib/home_page/navigation.rb

Defined Under Namespace

Classes: Base

Class Method Summary collapse

Class Method Details

.codeObject



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/home_page/navigation.rb', line 26

def self.code
  Proc.new do |navigation|
    navigation.items do |primary, options|
      primary.dom_class = 'nav navbar-nav'
      
      [:users, :authentication].each do |resource|
        instance_exec primary, ::HomePage::Navigation::Base.menu_options(resource), &::HomePage::Navigation.menu_code(resource)
      end
    end
  end
end


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
64
# File 'lib/home_page/navigation.rb', line 38

def self.menu_code(resource)
  case resource
  when :users
    Proc.new do |primary, options|
      if user_signed_in?
        primary.item :users, I18n.t('users.index.title'), users_path do |users|
          unless (@user.new_record? rescue true) || current_user.try(:id) == @user.id
            if options[:after_resource_has_many]
              instance_exec users, {}, &options[:after_resource_has_many]
            end
          end
        end
      end
    end
  when :authentication
    Proc.new do |primary, options|
      if user_signed_in?
        primary.item :sign_out, I18n.t('authentication.sign_out'), destroy_user_session_path, method: :delete
      else
        primary.item :authentication, I18n.t('authentication.title'), new_user_session_path do |authentication|
          authentication.item :sign_in, I18n.t('authentication.sign_in'), new_user_session_path
          authentication.item :sign_up, I18n.t('authentication.sign_up'), new_user_registration_path
        end
      end
    end
  end
end