Skip to content

Commit

Permalink
add favicon support
Browse files Browse the repository at this point in the history
  • Loading branch information
stereoscott committed Aug 1, 2013
1 parent 29f4976 commit 17afb73
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/views/layouts/active_admin_logged_out.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
<% ActiveAdmin.application.javascripts.each do |path| %>
<%= javascript_include_tag path %>
<% end %>
<%= favicon_link_tag ActiveAdmin.application.favicon if ActiveAdmin.application.favicon %>
<%= csrf_meta_tag %>
</head>
Expand Down
20 changes: 20 additions & 0 deletions features/favicon.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Feature: Favicon

Configuring a Favicon file

Background:
Given a configuration of:
"""
ActiveAdmin.register Post
ActiveAdmin.application.favicon = "a/favicon.ico"
"""

Scenario: Logged out views show Favicon
Given I am logged out
When I am on the login page
Then I should see the favicon "a/favicon.ico"

Scenario: Logged in views show Favicon
Given I am logged in
When I am on the dashboard
Then I should see the favicon "a/favicon.ico"
4 changes: 4 additions & 0 deletions features/step_definitions/asset_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@
Then /^I should see the js file "([^"]*)"$/ do |path|
page.should have_xpath("//script[contains(@src, /javascripts/#{path})]")
end

Then /^I should see the favicon "([^"]*)"$/ do |path|
page.should have_xpath("//link[contains(@href, \"#{path}\")]")
end
2 changes: 2 additions & 0 deletions features/support/paths.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ def path_to(page_name)
"/admin"
when /the new post page/
"/admin/posts/new"
when /the login page/
"/admin/login"
when /the admin password reset form with reset password token "([^"]*)"/
"/admin/password/edit?reset_password_token=#{$1}"

Expand Down
3 changes: 3 additions & 0 deletions lib/active_admin/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ def initialize

# Set the site title image displayed in the main layout (has precendence over :site_title)
inheritable_setting :site_title_image, ""

# Set a favicon
inheritable_setting :favicon, false

# The view factory to use to generate all the view classes. Take
# a look at ActiveAdmin::ViewFactory
Expand Down
5 changes: 5 additions & 0 deletions lib/active_admin/views/pages/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ def build_active_admin_head
active_admin_application.javascripts.each do |path|
text_node(javascript_include_tag(path))
end

if active_admin_application.favicon
text_node(favicon_link_tag(active_admin_application.favicon))
end

text_node csrf_meta_tag
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ ActiveAdmin.setup do |config|
# Active Admin resources and pages from here.
#
# config.before_filter :do_something_awesome


# == Setting a Favicon
#
# config.favicon = '/assets/favicon.ico'


# == Register Stylesheets & Javascripts
Expand Down
9 changes: 9 additions & 0 deletions spec/unit/application_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@
application.site_title_image = "http://railscasts.com/assets/episodes/stills/284-active-admin.png?1316476106"
application.site_title_image.should == "http://railscasts.com/assets/episodes/stills/284-active-admin.png?1316476106"
end

it "should store the site's favicon" do
application.favicon.should == false
end

it "should set the site's favicon" do
application.favicon = "/a/favicon.ico"
application.favicon.should == "/a/favicon.ico"
end

it "should have a view factory" do
application.view_factory.should be_an_instance_of(ActiveAdmin::ViewFactory)
Expand Down

0 comments on commit 17afb73

Please sign in to comment.