Module: Alchemy::Admin::NavigationHelper
- Included in:
 - BaseHelper
 
- Defined in:
 - app/helpers/alchemy/admin/navigation_helper.rb
 
Overview
This module contains helper methods for rendering the admin navigation.
Instance Method Summary collapse
- 
  
    
      #alchemy_main_navigation_entry(alchemy_module)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Renders one admin main navigation entry.
 - 
  
    
      #entry_active?(entry)  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    
Returns true if given navi entry is in params controller and action.
 - 
  
    
      #main_navigation_css_classes(navigation)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
CSS classes for main navigation entry.
 - 
  
    
      #navigate_module(navigation)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Used for checking the main navi permissions.
 - 
  
    
      #sorted_alchemy_modules  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Alchemy modules for main navigation.
 - 
  
    
      #url_for_module(alchemy_module)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Returns url for given Alchemy module.
 - 
  
    
      #url_for_module_sub_navigation(navigation)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Returns url for given Alchemy module sub navigation entry.
 
Instance Method Details
#alchemy_main_navigation_entry(alchemy_module) ⇒ Object
Renders one admin main navigation entry
      13 14 15 16 17 18 19  | 
    
      # File 'app/helpers/alchemy/admin/navigation_helper.rb', line 13 def (alchemy_module) render( "alchemy/admin/partials/main_navigation_entry", alchemy_module: alchemy_module, navigation: alchemy_module["navigation"] ) end  | 
  
#entry_active?(entry) ⇒ Boolean
Returns true if given navi entry is in params controller and action
Example
<%= entry_active?({controller: 'admin/users', action: 'index'}) %>
  
      62 63 64  | 
    
      # File 'app/helpers/alchemy/admin/navigation_helper.rb', line 62 def entry_active?(entry) is_entry_controller_active?(entry) && is_entry_action_active?(entry) end  | 
  
#main_navigation_css_classes(navigation) ⇒ Object
CSS classes for main navigation entry.
      46 47 48 49 50 51 52  | 
    
      # File 'app/helpers/alchemy/admin/navigation_helper.rb', line 46 def () [ "main_navi_entry", admin_mainnavi_active?() ? "active" : nil, .key?("sub_navigation") ? "has_sub_navigation" : nil ].compact end  | 
  
#navigate_module(navigation) ⇒ Object
Used for checking the main navi permissions
To let your module be navigatable by the user you have to provide an Ability for it.
Example:
# module.yml
name: 'my_module'
navigation: {
  controller: 'my/admin/posts'
  action: 'index'
}
# ability.rb
can :index, :my_admin_posts
  
      37 38 39 40 41 42  | 
    
      # File 'app/helpers/alchemy/admin/navigation_helper.rb', line 37 def navigate_module() [ ["action"].to_sym, ["controller"].to_s.gsub(/\A\//, "").tr("/", "_").to_sym ] end  | 
  
#sorted_alchemy_modules ⇒ Object
Alchemy modules for main navigation.
Sorted by position attribute, if given.
      105 106 107 108 109 110 111 112 113 114 115 116  | 
    
      # File 'app/helpers/alchemy/admin/navigation_helper.rb', line 105 def sorted_alchemy_modules sorted = [] not_sorted = [] alchemy_modules.map do |m| if m["position"].blank? not_sorted << m else sorted << m end end sorted.sort_by { |m| m["position"] } + not_sorted end  | 
  
#url_for_module(alchemy_module) ⇒ Object
Returns url for given Alchemy module.
If the module is inside an engine it calls the url_for helper on the engines routing proxy.
If the module is inside the host rails app it calls the url_for helper on the main_app routing proxy.
      75 76 77 78 79 80  | 
    
      # File 'app/helpers/alchemy/admin/navigation_helper.rb', line 75 def url_for_module(alchemy_module) route_from_engine_or_main_app( alchemy_module["engine_name"], (alchemy_module) ) end  | 
  
#url_for_module_sub_navigation(navigation) ⇒ Object
Returns url for given Alchemy module sub navigation entry.
If the module is inside an engine it calls the url_for helper on the engines routing proxy.
If the module is inside the host rails app it calls the url_for helper on the main_app routing proxy.
      91 92 93 94 95 96 97 98 99  | 
    
      # File 'app/helpers/alchemy/admin/navigation_helper.rb', line 91 def () alchemy_module = module_definition_for() return if alchemy_module.nil? route_from_engine_or_main_app( alchemy_module["engine_name"], () ) end  |