Permalink
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...
1 parent ffbbcd8 commit 36489be39ab79e10507ddc858bd99954775d359e @drogus drogus committed Jun 15, 2012
@@ -57,6 +57,8 @@ module ActionView
end
end
+ActionView::Base.default_formats ||= Mime::SET.symbols
+
# Common Active Support usage in Action Controller
require 'active_support/concern'
require 'active_support/core_ext/class/attribute_accessors'
@@ -148,6 +148,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 :helpers
class_attribute :_routes
class_attribute :logger
@@ -44,7 +44,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:
@@ -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

0 comments on commit 36489be

Please sign in to comment.