diff --git a/features/site_title.feature b/features/site_title.feature index 94c39b1ded6..58d29a5d94a 100644 --- a/features/site_title.feature +++ b/features/site_title.feature @@ -19,20 +19,29 @@ Feature: Site title Then I should see "Ruby on Rails: Welcome aboard" Scenario: Set the site title image - Given a configuration of: - """ - ActiveAdmin.application.site_title_image = "http://railscasts.com/assets/episodes/stills/284-active-admin.png?1316476106" - """ - When I am on the dashboard - And I should not see the site title "My Great Site" - And I should see the site title image "http://railscasts.com/assets/episodes/stills/284-active-admin.png?1316476106" + Given a configuration of: + """ + ActiveAdmin.application.site_title_image = "http://railscasts.com/assets/episodes/stills/284-active-admin.png?1316476106" + """ + When I am on the dashboard + And I should not see the site title "My Great Site" + And I should see the site title image "http://railscasts.com/assets/episodes/stills/284-active-admin.png?1316476106" Scenario: Set the site title image with link - Given a configuration of: - """ - ActiveAdmin.application.site_title_link = "http://www.google.com" - ActiveAdmin.application.site_title_image = "http://railscasts.com/assets/episodes/stills/284-active-admin.png?1316476106" - """ - When I am on the dashboard - And I should see the site title image "http://railscasts.com/assets/episodes/stills/284-active-admin.png?1316476106" - And I should see the site title image linked to "http://www.google.com" + Given a configuration of: + """ + ActiveAdmin.application.site_title_link = "http://www.google.com" + ActiveAdmin.application.site_title_image = "http://railscasts.com/assets/episodes/stills/284-active-admin.png?1316476106" + """ + When I am on the dashboard + And I should see the site title image "http://railscasts.com/assets/episodes/stills/284-active-admin.png?1316476106" + And I should see the site title image linked to "http://www.google.com" + + Scenario: Set the site title to a proc + Given a configuration of: + """ + ActiveAdmin.application.site_title_image = nil # Configuration is not reset between scenarios + ActiveAdmin.application.site_title = proc { "Hello #{controller.current_admin_user.email}" } + """ + When I am on the dashboard + And I should see the site title "Hello admin@example.com" diff --git a/lib/active_admin/views/header_renderer.rb b/lib/active_admin/views/header_renderer.rb index 68d748b8c42..7262a6b7633 100644 --- a/lib/active_admin/views/header_renderer.rb +++ b/lib/active_admin/views/header_renderer.rb @@ -13,7 +13,7 @@ def to_html # Renders the title/branding area for the site def title - content_tag('h1', link_to_site_title(title_image || title_text), :id => 'site_title') + content_tag('h1', link_to_site_title(title_image_tag || title_text), :id => 'site_title') end def link_to_site_title(title_tag) @@ -26,17 +26,22 @@ def link_to_site_title(title_tag) # @return [String] An HTML img tag with site_title_image. Return nil when # site_title_image is blank. - def title_image + def title_image_tag if active_admin_namespace.site_title_image.present? - image_tag(active_admin_namespace.site_title_image, + image_tag(title_image, :id => "site_title_image", :alt => active_admin_namespace.site_title) end end - + + # @return [String] The title image url + def title_image + render_or_call_method_or_proc_on(self, active_admin_namespace.site_title_image) + end + # @return [String] The site title def title_text - active_admin_namespace.site_title + render_or_call_method_or_proc_on(self, active_admin_namespace.site_title) end # Renders the global navigation returned by