mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
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.
This commit is contained in:
parent
f21a528f55
commit
45efb665f0
4 changed files with 19 additions and 1 deletions
|
@ -101,3 +101,7 @@ module ActionDispatch
|
|||
end
|
||||
|
||||
autoload :Mime, 'action_dispatch/http/mime_type'
|
||||
|
||||
ActiveSupport.on_load(:action_view) do
|
||||
ActionView::Base.default_formats ||= Mime::SET.symbols
|
||||
end
|
||||
|
|
|
@ -146,6 +146,9 @@ module ActionView #:nodoc:
|
|||
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
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ module ActionView
|
|||
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 @@ class LookupContextTest < ActiveSupport::TestCase
|
|||
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
|
||||
|
|
Loading…
Reference in a new issue