Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add ActionView::Base.default_formats

default_formats array is used by LookupContext in order to allow
rendering templates when :formats option is not passed. Previously it
was always set to Mime::SET, which created dependency on Action Pack. In
order to remove this dependency, Mime::SET is used only if
ActionController is loaded.
  • Loading branch information...
commit 5166b5edc25fd25e90a2392abf242a9a51e077dc 1 parent 94b1023
@drogus drogus authored
View
4 actionpack/lib/action_dispatch.rb
@@ -101,3 +101,7 @@ module Session
end
autoload :Mime, 'action_dispatch/http/mime_type'
+
+ActiveSupport.on_load(:action_view) do
+ ActionView::Base.default_formats ||= Mime::SET.symbols
+end
View
3  actionpack/lib/action_view/base.rb
@@ -146,6 +146,9 @@ class Base
cattr_accessor :prefix_partial_path_with_controller_namespace
@@prefix_partial_path_with_controller_namespace = true
+ # Specify default_formats that can be rendered.
+ cattr_accessor :default_formats
+
class_attribute :_routes
class_attribute :logger
View
2  actionpack/lib/action_view/lookup_context.rb
@@ -43,7 +43,7 @@ module Accessors #:nodoc:
end
register_detail(:locale) { [I18n.locale, I18n.default_locale].uniq }
- register_detail(:formats) { Mime::SET.symbols }
+ register_detail(:formats) { ActionView::Base.default_formats || [:html, :text, :js, :css, :xml, :json] }
register_detail(:handlers){ Template::Handlers.extensions }
class DetailsKey #:nodoc:
View
11 actionpack/test/template/lookup_context_test.rb
@@ -11,6 +11,17 @@ def teardown
I18n.locale = :en
end
+ test "allows to override default_formats with ActionView::Base.default_formats" do
+ begin
+ formats = ActionView::Base.default_formats
+ ActionView::Base.default_formats = [:foo, :bar]
+
+ assert_equal [:foo, :bar], ActionView::LookupContext.new([]).default_formats
+ ensure
+ ActionView::Base.default_formats = formats
+ end
+ end
+
test "process view paths on initialization" do
assert_kind_of ActionView::PathSet, @lookup_context.view_paths
end
Please sign in to comment.
Something went wrong with that request. Please try again.