app/helpers/alchemy/admin/navigation_helper.rb in alchemy_cms-2.9.1 vs app/helpers/alchemy/admin/navigation_helper.rb in alchemy_cms-3.0.0.rc5
- old
+ new
@@ -31,14 +31,29 @@
end
end
# 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
+ #
def navigate_module(navigation)
+ navigation.stringify_keys!
[
navigation['action'].to_sym,
- navigation['controller'].gsub(/^\//, '').gsub(/\//, '_').to_sym
+ navigation['controller'].to_s.gsub(/\A\//, '').gsub(/\//, '_').to_sym
]
end
# CSS classes for main navigation entry.
#
@@ -93,10 +108,27 @@
alchemy_module['engine_name'],
url_options_for_navigation_entry(navigation)
)
end
+ # Alchemy modules for main navigation.
+ #
+ # Sorted by position attribute, if given.
+ #
+ 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
+
private
# Calls +url_for+ helper on engine if present or on host app.
#
# @param [String]
@@ -178,10 +210,10 @@
end
# Returns true if the given entry's controller is current controller
#
def is_entry_controller_active?(entry)
- entry['controller'].gsub(/^\//, '') == params[:controller]
+ entry['controller'].gsub(/\A\//, '') == params[:controller]
end
# Returns true if the given entry's action is current controllers action
#
# Also checks if given entry has a +nested_actions+ key, if so it checks if one of them is current controller's action