Skip to content

Commit

Permalink
Add ActionView::Base.default_formats
Browse files Browse the repository at this point in the history
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 Jun 15, 2012
1 parent ffbbcd8 commit 36489be
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
2 changes: 2 additions & 0 deletions actionpack/lib/action_controller.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ module ActionView
end end
end end


ActionView::Base.default_formats ||= Mime::SET.symbols

# Common Active Support usage in Action Controller # Common Active Support usage in Action Controller
require 'active_support/concern' require 'active_support/concern'
require 'active_support/core_ext/class/attribute_accessors' require 'active_support/core_ext/class/attribute_accessors'
Expand Down
3 changes: 3 additions & 0 deletions actionview/lib/action_view/base.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -148,6 +148,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 :helpers class_attribute :helpers
class_attribute :_routes class_attribute :_routes
class_attribute :logger class_attribute :logger
Expand Down
2 changes: 1 addition & 1 deletion actionview/lib/action_view/lookup_context.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -44,7 +44,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 actionview/test/template/lookup_context_test.rb
Original file line number Original file line Diff line number Diff line change
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 36489be

Please sign in to comment.