Skip to content

Commit

Permalink
Added support to pages for setting a custom title
Browse files Browse the repository at this point in the history
* To mimic the APIs of the other resources, the page #content DSL method
  now accepts a hash with the "title" key
* `:title` can be set to a string to be rendered, a symbol to be called
  in the context of the view, or a proc to be run at render-time
* Updated the dashboard template to use I18n and procs for the page
  title and menu items
  • Loading branch information
gregbell committed Jul 4, 2012
1 parent 645a8ca commit 3ea2ea6
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 8 deletions.
26 changes: 26 additions & 0 deletions features/registering_pages.feature
Expand Up @@ -30,6 +30,32 @@ Feature: Registering Pages
Then I should see the page title "Status"
And I should see the Active Admin layout

Scenario: Registering a page with a custom title as a string
Given a configuration of:
"""
ActiveAdmin.register_page "Status" do
content :title => "Custom Page Title" do
"I love chocolate."
end
end
"""
When I go to the dashboard
And I follow "Status"
Then I should see the page title "Custom Page Title"

Scenario: Registering a page with a custom title as a proc
Given a configuration of:
"""
ActiveAdmin.register_page "Status" do
content :title => proc{ "Custom Page Title from Proc" } do
"I love chocolate."
end
end
"""
When I go to the dashboard
And I follow "Status"
Then I should see the page title "Custom Page Title from Proc"

Scenario: Adding a sidebar section to a page
Given a configuration of:
"""
Expand Down
2 changes: 1 addition & 1 deletion lib/active_admin/views/pages/base.rb
Expand Up @@ -26,7 +26,7 @@ def build_active_admin_head
active_admin_application.stylesheets.each do |style|
text_node(stylesheet_link_tag(style.path, style.options).html_safe)
end

active_admin_application.javascripts.each do |path|
script :src => javascript_path(path), :type => "text/javascript"
end
Expand Down
14 changes: 10 additions & 4 deletions lib/active_admin/views/pages/page.rb
Expand Up @@ -4,9 +4,7 @@ module Pages
class Page < Base

def main_content
page_presenter = active_admin_config.get_page_presenter(:index)

if page_presenter && page_presenter.block
if page_presenter.block
instance_exec &page_presenter.block
else
nil
Expand All @@ -15,8 +13,16 @@ def main_content

protected

def page_presenter
active_admin_config.get_page_presenter(:index) || ActiveAdmin::PagePresenter.new
end

def title
active_admin_config.name
if page_presenter[:title]
render_or_call_method_or_proc_on self, page_presenter[:title]
else
active_admin_config.name
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/active_admin/views/pages/show.rb
Expand Up @@ -4,7 +4,7 @@ module Pages
class Show < Base

def config
active_admin_config.get_page_presenter(:show) || ::ActiveAdmin::PagePresenter.new
active_admin_config.get_page_presenter(:show) || super
end

def title
Expand Down
5 changes: 3 additions & 2 deletions lib/generators/active_admin/install/templates/dashboard.rb
@@ -1,7 +1,8 @@
ActiveAdmin.register_page "Dashboard" do
menu :priority => 1

content do
menu :priority => 1, :label => proc{ I18n.t("active_admin.dashboard") }

content :title => proc{ I18n.t("active_admin.dashboard") } do
div :class => "blank_slate_container", :id => "dashboard_default_message" do
span :class => "blank_slate" do
span "Welcome to Active Admin. This is the default dashboard page."
Expand Down

0 comments on commit 3ea2ea6

Please sign in to comment.