Skip to content

Commit

Permalink
Make #site_title proc friendly
Browse files Browse the repository at this point in the history
  • Loading branch information
pcreux committed Feb 17, 2012
1 parent 0d91f8d commit 31a874f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 20 deletions.
39 changes: 24 additions & 15 deletions features/site_title.feature
Expand Up @@ -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"
15 changes: 10 additions & 5 deletions lib/active_admin/views/header_renderer.rb
Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit 31a874f

Please sign in to comment.