Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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
drogus committed Aug 25, 2012
1 parent 94b1023 commit 5166b5e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
4 changes: 4 additions & 0 deletions actionpack/lib/action_dispatch.rb
Expand Up @@ -101,3 +101,7 @@ module Session
end end


autoload :Mime, 'action_dispatch/http/mime_type' autoload :Mime, 'action_dispatch/http/mime_type'

ActiveSupport.on_load(:action_view) do
ActionView::Base.default_formats ||= Mime::SET.symbols
end
3 changes: 3 additions & 0 deletions actionpack/lib/action_view/base.rb
Expand Up @@ -146,6 +146,9 @@ class Base
cattr_accessor :prefix_partial_path_with_controller_namespace cattr_accessor :prefix_partial_path_with_controller_namespace
@@prefix_partial_path_with_controller_namespace = true @@prefix_partial_path_with_controller_namespace = true


# Specify default_formats that can be rendered.
cattr_accessor :default_formats

class_attribute :_routes class_attribute :_routes
class_attribute :logger class_attribute :logger


Expand Down
2 changes: 1 addition & 1 deletion actionpack/lib/action_view/lookup_context.rb
Expand Up @@ -43,7 +43,7 @@ module Accessors #:nodoc:
end end


register_detail(:locale) { [I18n.locale, I18n.default_locale].uniq } 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 } register_detail(:handlers){ Template::Handlers.extensions }


class DetailsKey #:nodoc: class DetailsKey #:nodoc:
Expand Down
11 changes: 11 additions & 0 deletions actionpack/test/template/lookup_context_test.rb
Expand Up @@ -11,6 +11,17 @@ def teardown
I18n.locale = :en I18n.locale = :en
end 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 test "process view paths on initialization" do
assert_kind_of ActionView::PathSet, @lookup_context.view_paths assert_kind_of ActionView::PathSet, @lookup_context.view_paths
end end
Expand Down

0 comments on commit 5166b5e

Please sign in to comment.