Module: HomePage::Navigation

Defined in:
lib/home_page/navigation.rb

Defined Under Namespace

Classes: Base

Class Method Summary collapse

Class Method Details

.codeObject



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/home_page/navigation.rb', line 35

def self.code
  Proc.new do |navigation|
    navigation.items do |primary, options|
      primary.dom_class = 'nav navbar-nav'
      
      ::HomePage::Navigation::Base.items.each do |item|
        klass = "HomePage#{item.is_a?(Array) ? item.first.to_s.classify : ''}::Navigation"
        item = item.is_a?(Array) ? item.last : item
        instance_exec primary, HomePage::Navigation::Base.menu_options(item), &klass.constantize.menu_code(item)
      end
    end
  end
end


49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/home_page/navigation.rb', line 49

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