Permalink
Browse files

add support for the rails3.1 asset pipeline in default_html_head

  • Loading branch information...
1 parent 04a91d8 commit df52170036f344818ddf3e7a3ed57f2ce8bc8e6d @cbeer cbeer committed Jul 1, 2011
Showing with 22 additions and 5 deletions.
  1. +12 −2 lib/blacklight/controller.rb
  2. +10 −3 test_support/spec/controllers/application_controller_spec.rb
@@ -40,9 +40,14 @@ def error
# http://api.rubyonrails.org/classes/ActionController/Filters/ClassMethods.html
# for how to turn off a filter in a sub-class and such.
def default_html_head
- stylesheet_links << ['yui', 'jquery/ui-lightness/jquery-ui-1.8.1.custom.css', 'blacklight/blacklight', {:media=>'all'}]
+ if use_asset_pipeline?
+ stylesheet_links << ["application"]
+ javascript_includes << ["application"]
+ else
+ stylesheet_links << ['yui', 'jquery/ui-lightness/jquery-ui-1.8.1.custom.css', 'blacklight/blacklight', {:media=>'all'}]
- javascript_includes << ['jquery-1.4.2.min.js', 'jquery-ui-1.8.1.custom.min.js', 'blacklight/blacklight' ]
+ javascript_includes << ['jquery-1.4.2.min.js', 'jquery-ui-1.8.1.custom.min.js', 'blacklight/blacklight' ]
+ end
end
@@ -124,5 +129,10 @@ def access_denied
redirect_to new_user_session_url(:referer => request.fullpath)
end
+ private
+ # Detect if the Rails asset pipeline is enabled
+ def use_asset_pipeline?
+ Rails.application.config.respond_to?(:assets) and Rails.application.config.assets.enabled
+ end
end
@@ -6,16 +6,23 @@
describe "head content from variables" do
describe "#default_html_head" do
- before(:each) do
- controller.send(:default_html_head)
- end
it "should setup js and css defaults" do
+
+ controller.should_receive(:use_asset_pipeline?).any_number_of_times.and_return(false)
+ controller.send(:default_html_head)
controller.javascript_includes.should include(["jquery-1.4.2.min.js", "jquery-ui-1.8.1.custom.min.js", "blacklight/blacklight"])#find do |item|
# item == ["jquery-1.4.2.min.js", "jquery-ui-1.7.2.custom.min.js", "blacklight", "application", "accordion", "lightbox", {:plugin=>:blacklight}]
#end
controller.stylesheet_links.should include(["yui", "jquery/ui-lightness/jquery-ui-1.8.1.custom.css", "blacklight/blacklight", {:media=>"all"}])
end
+
+ it "should support rails 3.1 asset pipeline js and css defaults" do
+ controller.should_receive(:use_asset_pipeline?).any_number_of_times.and_return(true)
+ controller.send(:default_html_head)
+ controller.javascript_includes.should include(["application"])
+ controller.stylesheet_links.should include(["application"])
+ end
end
end

0 comments on commit df52170

Please sign in to comment.