Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added configurable global navigation naming. Closes #48

  • Loading branch information...
commit b28e7fb317ada9cd84912b94862a34f780967039 1 parent b6b08e6
@gregbell gregbell authored
View
36 README.rdoc
@@ -96,6 +96,42 @@ it is set to the name of your Rails.application class name.
# config/initializers/active_admin.rb
config.site_title = "My Admin Site"
+== Customize The Resource
+
+=== Rename the Resource
+
+By default, any references to the resource (menu, routes, buttons, etc) in the
+interface will use the name of the class. You can rename the resource by using
+the <tt>:as</tt> option.
+
+ ActiveAdmin.register Post, :as => "Article"
+
+The resource will then be available as /admin/articles
+
+=== Customize the Navigation
+
+The resource will be displayed in the global navigation by default.
+
+To disable the resource from being displayed in the global navigation:
+
+ ActiveAdmin.register Post do
+ menu false
+ end
+
+To change the name of the label in the menu:
+
+ ActiveAdmin.register Post do
+ menu :label => "My Posts"
+ end
+
+To add the menu as a child of another menu:
+
+ ActiveAdmin.register Post do
+ menu :parent => "Blog"
+ end
+
+This will create the menu item if it doesn't exist yet.
+
== Customizing the Index Page
Filtering and listing resources is one of the most important tasks for
View
26 features/menu.feature
@@ -0,0 +1,26 @@
+Feature: Menu
+
+ Background:
+ Given I am logged in
+
+ Scenario: Hide the menu item
+ Given a configuration of:
+ """
+ ActiveAdmin.register Post do
+ menu false
+ end
+ """
+ When I am on the dashboard
+ Then I should not see a menu item for "Posts"
+
+ Scenario: Set the menu item label
+ Given a configuration of:
+ """
+ ActiveAdmin.register Post do
+ menu :label => "Articles"
+ end
+ """
+ When I am on the dashboard
+ Then I should see a menu item for "Articles"
+ Then show me the page
+ And I should not see a menu item for "Posts"
View
7 features/step_definitions/menu_steps.rb
@@ -0,0 +1,7 @@
+Then /^I should see a menu item for "([^"]*)"$/ do |name|
+ Then %{I should see "#{name}" within "#tabs li a"}
+end
+
+Then /^I should not see a menu item for "([^"]*)"$/ do |name|
+ Then %{I should not see "#{name}" within "#tabs li a"}
+end
View
2  lib/active_admin.rb
@@ -132,7 +132,7 @@ def setup
# Registers a brand new configuration for the given resource.
def register(resource, options = {}, &block)
- namespace_name = (options[:namespace] || default_namespace) == false ? :root : (options[:namespace] || default_namespace)
+ namespace_name = options[:namespace] == false ? :root : (options[:namespace] || default_namespace || :root)
namespace = find_or_create_namespace(namespace_name)
namespace.register(resource, options, &block)
end
View
9 lib/active_admin/resource.rb
@@ -121,16 +121,17 @@ def parent_menu_item_name
@menu_options[:parent]
end
+ # Returns the name to be displayed in the menu for this resource
+ def menu_item_name
+ @menu_options[:label] || plural_resource_name
+ end
+
# Should this resource be added to the menu system?
def include_in_menu?
return false if @menu_options[:display] == false
!(belongs_to? && !belongs_to_config.optional?)
end
- # Returns the name to be displayed in the menu for this resource
- def menu_item_name
- @menu_item_name ||= plural_resource_name
- end
# Clears all the member actions this resource knows about
def clear_member_actions!
View
10 spec/unit/resource_spec.rb
@@ -90,6 +90,16 @@ module ::Mock; class Resource; end; end
end
end
+ describe "menu item name" do
+ it "should be the resource name when not set" do
+ config.menu_item_name.should == "Categories"
+ end
+ it "should be settable" do
+ config.menu :label => "My Label"
+ config.menu_item_name.should == "My Label"
+ end
+ end
+
describe "parent menu item name" do
it "should be nil when not set" do
config.parent_menu_item_name.should == nil

4 comments on commit b28e7fb

@elomarns

It would be great to hide a menu item if the user doesn't have permission to see it. Something like this:

menu :if => lambda { |user| user.admin? }

@tc4mpbell

Can this label setting also be shown as the h2#page_title on the resource pages?
And on the New/Edit/Delete buttons?

I have namespaced stuff (Misc::Thing); shows up as "Misc Things", would like to just set label to "Things".

Thanks!

@gregbell
Owner
@tc4mpbell

Odd, had in my mind that :as did something different... Reading fail. Works great, thanks very much!

Please sign in to comment.
Something went wrong with that request. Please try again.