Permalink
Browse files

Merge pull request #11396 from strzalek/extract_renderers

Remove dependency on Action View from Action Pack

This set of changes removes the need of using Action View with Action Pack.
Now you may use controllers without Action View, by rendering `:text` response
or alternatively you can plug in your own rendering logic. This is especially
handy when you're just dealing with APIs and don't need to include entire
Action View just to render simple JSON responses.
  • Loading branch information...
2 parents 27dc4fa + 0d43df7 commit c19958015fac7b50f8dedbdf17991c00d6b8bbd4 @drogus drogus committed Aug 26, 2013
Showing with 2,195 additions and 1,714 deletions.
  1. +1 −0 actionmailer/actionmailer.gemspec
  2. +0 −1 actionmailer/lib/action_mailer.rb
  3. +4 −2 actionmailer/lib/action_mailer/base.rb
  4. +2 −0 actionmailer/lib/action_mailer/log_subscriber.rb
  5. +4 −4 actionmailer/test/abstract_unit.rb
  6. +4 −0 actionmailer/test/i18n_with_controller_test.rb
  7. +9 −0 actionpack/CHANGELOG.md
  8. +3 −3 actionpack/actionpack.gemspec
  9. +1 −2 actionpack/lib/abstract_controller.rb
  10. +14 −124 actionpack/lib/abstract_controller/rendering.rb
  11. +1 −9 actionpack/lib/action_controller.rb
  12. +16 −2 actionpack/lib/action_controller/base.rb
  13. +36 −6 actionpack/lib/action_controller/metal/rendering.rb
  14. +18 −20 actionpack/lib/action_controller/metal/streaming.rb
  15. +0 −1 actionpack/lib/action_controller/railtie.rb
  16. +3 −30 actionpack/test/abstract_unit.rb
  17. +3 −0 actionpack/test/controller/assert_select_test.rb
  18. +1 −0 actionpack/test/controller/mime/respond_with_test.rb
  19. +230 −1,420 actionpack/test/controller/render_test.rb
  20. +0 −1 actionpack/test/fixtures/layout_tests/layouts/symlinked
  21. +0 −6 actionpack/test/lib/controller/fake_models.rb
  22. +21 −16 actionview/Rakefile
  23. +4 −0 actionview/lib/action_view.rb
  24. +4 −0 actionview/lib/action_view/base.rb
  25. +2 −0 actionview/lib/action_view/helpers/record_tag_helper.rb
  26. +3 −2 {actionpack/lib/abstract_controller → actionview/lib/action_view}/layouts.rb
  27. +2 −0 actionview/lib/action_view/log_subscriber.rb
  28. +13 −0 actionview/lib/action_view/railtie.rb
  29. +162 −0 actionview/lib/action_view/rendering.rb
  30. +1 −1 {actionpack/lib/abstract_controller → actionview/lib/action_view}/view_paths.rb
  31. +4 −54 actionview/test/abstract_unit.rb
  32. +2 −1 {actionpack/test → actionview/test/actionpack}/abstract/abstract_controller_test.rb
  33. +4 −3 {actionpack/test → actionview/test/actionpack}/abstract/helper_test.rb
  34. +2 −1 {actionpack/test → actionview/test/actionpack}/abstract/layouts_test.rb
  35. +1 −0 {actionpack/test → actionview/test/actionpack}/abstract/render_test.rb
  36. 0 ...t → actionview/test/actionpack}/abstract/views/abstract_controller/testing/me3/formatted.html.erb
  37. 0 ...npack/test → actionview/test/actionpack}/abstract/views/abstract_controller/testing/me3/index.erb
  38. 0 ...npack/test → actionview/test/actionpack}/abstract/views/abstract_controller/testing/me4/index.erb
  39. 0 ...npack/test → actionview/test/actionpack}/abstract/views/abstract_controller/testing/me5/index.erb
  40. 0 {actionpack/test → actionview/test/actionpack}/abstract/views/action_with_ivars.erb
  41. 0 {actionpack/test → actionview/test/actionpack}/abstract/views/helper_test.erb
  42. 0 {actionpack/test → actionview/test/actionpack}/abstract/views/index.erb
  43. 0 ...ack/test → actionview/test/actionpack}/abstract/views/layouts/abstract_controller/testing/me4.erb
  44. 0 {actionpack/test → actionview/test/actionpack}/abstract/views/layouts/application.erb
  45. 0 {actionpack/test → actionview/test/actionpack}/abstract/views/naked_render.erb
  46. +2 −0 {actionpack/test → actionview/test/actionpack}/controller/capture_test.rb
  47. +3 −3 {actionpack/test → actionview/test/actionpack}/controller/layout_test.rb
  48. +1,337 −0 actionview/test/actionpack/controller/render_test.rb
  49. +1 −0 actionview/test/fixtures/actionpack/bad_customers/_bad_customer.html.erb
  50. 0 {actionpack/test/fixtures → actionview/test/fixtures/actionpack}/customers/_customer.html.erb
  51. 0 {actionpack/test/fixtures → actionview/test/fixtures/actionpack}/fun/games/_form.erb
  52. 0 {actionpack/test/fixtures → actionview/test/fixtures/actionpack}/fun/games/hello_world.erb
  53. 0 ...npack/test/fixtures → actionview/test/fixtures/actionpack}/good_customers/_good_customer.html.erb
  54. 0 {actionpack/test/fixtures → actionview/test/fixtures/actionpack}/hello.html
  55. 0 {actionpack/test/fixtures → actionview/test/fixtures/actionpack}/layout_tests/alt/layouts/alt.erb
  56. 0 ...ures → actionview/test/fixtures/actionpack}/layout_tests/layouts/controller_name_space/nested.erb
  57. 0 {actionpack/test/fixtures → actionview/test/fixtures/actionpack}/layout_tests/layouts/item.erb
  58. 0 ...ionpack/test/fixtures → actionview/test/fixtures/actionpack}/layout_tests/layouts/layout_test.erb
  59. 0 ...fixtures → actionview/test/fixtures/actionpack}/layout_tests/layouts/multiple_extensions.html.erb
  60. +5 −0 actionview/test/fixtures/actionpack/layout_tests/layouts/symlinked/symlinked_layout.erb
  61. 0 ...ures → actionview/test/fixtures/actionpack}/layout_tests/layouts/third_party_template_library.mab
  62. 0 {actionpack/test/fixtures → actionview/test/fixtures/actionpack}/layout_tests/views/goodbye.erb
  63. 0 {actionpack/test/fixtures → actionview/test/fixtures/actionpack}/layout_tests/views/hello.erb
  64. +2 −0 actionview/test/fixtures/actionpack/layouts/_column.html.erb
  65. +1 −0 actionview/test/fixtures/actionpack/layouts/_customers.erb
  66. +2 −0 actionview/test/fixtures/actionpack/layouts/_partial_and_yield.erb
  67. +1 −0 actionview/test/fixtures/actionpack/layouts/_yield_only.erb
  68. +1 −0 actionview/test/fixtures/actionpack/layouts/_yield_with_params.erb
  69. +3 −0 actionview/test/fixtures/actionpack/layouts/block_with_layout.erb
  70. +3 −0 actionview/test/fixtures/actionpack/layouts/builder.builder
  71. +3 −0 actionview/test/fixtures/actionpack/layouts/partial_with_layout.erb
  72. +1 −0 actionview/test/fixtures/actionpack/layouts/standard.html.erb
  73. +4 −0 actionview/test/fixtures/actionpack/layouts/streaming.erb
  74. +2 −0 actionview/test/fixtures/actionpack/layouts/talk_from_action.erb
  75. +1 −0 actionview/test/fixtures/actionpack/layouts/with_html_partial.html.erb
  76. +2 −0 actionview/test/fixtures/actionpack/layouts/xhr.html.erb
  77. +2 −0 actionview/test/fixtures/actionpack/layouts/yield.erb
  78. +2 −0 actionview/test/fixtures/actionpack/layouts/yield_with_render_inline_inside.erb
  79. +2 −0 actionview/test/fixtures/actionpack/layouts/yield_with_render_partial_inside.erb
  80. 0 {actionpack/test/fixtures → actionview/test/fixtures/actionpack}/quiz/questions/_question.html.erb
  81. +1 −0 actionview/test/fixtures/actionpack/shared.html.erb
  82. +1 −0 actionview/test/fixtures/actionpack/test/_changing_priority.html.erb
  83. +1 −0 actionview/test/fixtures/actionpack/test/_changing_priority.json.erb
  84. +1 −0 actionview/test/fixtures/actionpack/test/_counter.html.erb
  85. +1 −0 actionview/test/fixtures/actionpack/test/_customer.erb
  86. +1 −0 actionview/test/fixtures/actionpack/test/_customer_counter.erb
  87. +1 −0 actionview/test/fixtures/actionpack/test/_customer_counter_with_as.erb
  88. +1 −0 actionview/test/fixtures/actionpack/test/_customer_greeting.erb
  89. +1 −0 actionview/test/fixtures/actionpack/test/_customer_with_var.erb
  90. +1 −0 actionview/test/fixtures/actionpack/test/_directory/_partial_with_locales.html.erb
  91. +1 −0 actionview/test/fixtures/actionpack/test/_first_json_partial.json.erb
  92. +1 −0 actionview/test/fixtures/actionpack/test/_form.erb
  93. +1 −0 actionview/test/fixtures/actionpack/test/_hash_greeting.erb
  94. +2 −0 actionview/test/fixtures/actionpack/test/_hash_object.erb
  95. +1 −0 actionview/test/fixtures/actionpack/test/_hello.builder
  96. 0 actionview/test/fixtures/actionpack/test/_json_change_priority.json.erb
  97. +1 −0 actionview/test/fixtures/actionpack/test/_labelling_form.erb
  98. +3 −0 actionview/test/fixtures/actionpack/test/_layout_for_partial.html.erb
  99. +1 −0 actionview/test/fixtures/actionpack/test/_partial.erb
  100. +1 −0 actionview/test/fixtures/actionpack/test/_partial.html.erb
  101. +1 −0 actionview/test/fixtures/actionpack/test/_partial.js.erb
  102. +1 −0 actionview/test/fixtures/actionpack/test/_partial_for_use_in_layout.html.erb
  103. +1 −0 actionview/test/fixtures/actionpack/test/_partial_html_erb.html.erb
  104. +1 −0 actionview/test/fixtures/actionpack/test/_partial_name_local_variable.erb
  105. +1 −0 actionview/test/fixtures/actionpack/test/_partial_only.erb
  106. +1 −0 actionview/test/fixtures/actionpack/test/_partial_only_html.html
  107. +2 −0 actionview/test/fixtures/actionpack/test/_partial_with_partial.erb
  108. +2 −0 actionview/test/fixtures/actionpack/test/_person.erb
  109. +13 −0 actionview/test/fixtures/actionpack/test/_raise_indentation.html.erb
  110. +1 −0 actionview/test/fixtures/actionpack/test/_second_json_partial.json.erb
  111. +2 −0 actionview/test/fixtures/actionpack/test/action_talk_to_layout.erb
  112. +1 −0 actionview/test/fixtures/actionpack/test/calling_partial_with_layout.html.erb
  113. +4 −0 actionview/test/fixtures/actionpack/test/capturing.erb
  114. +2 −0 actionview/test/fixtures/actionpack/test/change_priority.html.erb
  115. +1 −0 actionview/test/fixtures/actionpack/test/content_for.erb
  116. +3 −0 actionview/test/fixtures/actionpack/test/content_for_concatenated.erb
  117. +2 −0 actionview/test/fixtures/actionpack/test/content_for_with_parameter.erb
  118. +1 −0 actionview/test/fixtures/actionpack/test/dot.directory/render_file_with_ivar.erb
  119. +1 −0 actionview/test/fixtures/actionpack/test/formatted_html_erb.html.erb
  120. +1 −0 actionview/test/fixtures/actionpack/test/formatted_xml_erb.builder
  121. +1 −0 actionview/test/fixtures/actionpack/test/formatted_xml_erb.html.erb
  122. +1 −0 actionview/test/fixtures/actionpack/test/formatted_xml_erb.xml.erb
  123. +1 −0 actionview/test/fixtures/actionpack/test/greeting.html.erb
  124. +1 −0 actionview/test/fixtures/actionpack/test/greeting.xml.erb
  125. +1 −0 actionview/test/fixtures/actionpack/test/hello,world.erb
  126. +4 −0 actionview/test/fixtures/actionpack/test/hello.builder
  127. +1 −0 actionview/test/fixtures/actionpack/test/hello/hello.erb
  128. +1 −0 actionview/test/fixtures/actionpack/test/hello_world.erb
  129. +3 −0 actionview/test/fixtures/actionpack/test/hello_world_container.builder
  130. +3 −0 actionview/test/fixtures/actionpack/test/hello_world_from_rxml.builder
  131. +1 −0 actionview/test/fixtures/actionpack/test/hello_world_with_layout_false.erb
  132. +2 −0 actionview/test/fixtures/actionpack/test/hello_world_with_partial.html.erb
  133. +11 −0 actionview/test/fixtures/actionpack/test/hello_xml_world.builder
  134. +1 −0 actionview/test/fixtures/actionpack/test/html_template.html.erb
  135. +1 −0 actionview/test/fixtures/actionpack/test/hyphen-ated.erb
  136. +2 −0 actionview/test/fixtures/actionpack/test/implicit_content_type.atom.builder
  137. +1 −0 actionview/test/fixtures/actionpack/test/list.erb
  138. +4 −0 actionview/test/fixtures/actionpack/test/non_erb_block_content_for.builder
  139. +4 −0 actionview/test/fixtures/actionpack/test/potential_conflicts.erb
  140. +1 −0 actionview/test/fixtures/actionpack/test/proper_block_detection.erb
  141. +1 −0 actionview/test/fixtures/actionpack/test/render_file_from_template.html.erb
  142. +1 −0 actionview/test/fixtures/actionpack/test/render_file_with_ivar.erb
  143. +1 −0 actionview/test/fixtures/actionpack/test/render_file_with_locals.erb
  144. +1 −0 actionview/test/fixtures/actionpack/test/render_file_with_locals_and_default.erb
  145. +1 −0 actionview/test/fixtures/actionpack/test/render_implicit_html_template_from_xhr_request.da.html.erb
  146. +1 −0 actionview/test/fixtures/actionpack/test/render_implicit_html_template_from_xhr_request.html.erb
  147. +1 −0 actionview/test/fixtures/actionpack/test/render_implicit_js_template_without_layout.js.erb
  148. +1 −0 actionview/test/fixtures/actionpack/test/render_partial_inside_directory.html.erb
  149. +1 −0 actionview/test/fixtures/actionpack/test/render_to_string_test.erb
  150. +2 −0 actionview/test/fixtures/actionpack/test/render_two_partials.html.erb
  151. +1 −0 actionview/test/fixtures/actionpack/test/using_layout_around_block.html.erb
  152. +1 −0 actionview/test/fixtures/actionpack/test/with_html_partial.html.erb
  153. +1 −0 actionview/test/fixtures/actionpack/test/with_partial.html.erb
  154. +1 −0 actionview/test/fixtures/actionpack/test/with_partial.text.erb
  155. +1 −0 actionview/test/fixtures/actionpack/test/with_xml_template.html.erb
  156. +5 −0 actionview/test/fixtures/helpers/abc_helper.rb
  157. +5 −0 actionview/test/fixtures/helpers/fun/games_helper.rb
  158. +5 −0 actionview/test/fixtures/helpers/fun/pdf_helper.rb
  159. +5 −0 actionview/test/fixtures/helpers/helpery_test_helper.rb
  160. +3 −0 actionview/test/fixtures/helpers/just_me_helper.rb
  161. +3 −0 actionview/test/fixtures/helpers/me_too_helper.rb
  162. 0 {actionpack → actionview}/test/fixtures/helpers_missing/invalid_require_helper.rb
  163. 0 {actionpack → actionview}/test/fixtures/override/test/hello_world.erb
  164. 0 {actionpack → actionview}/test/fixtures/override2/layouts/test/sub.erb
  165. 0 {actionpack/test → actionview/test/lib}/controller/view_paths_test.rb
  166. +1 −1 actionview/test/template/lookup_context_test.rb
  167. +1 −0 railties/lib/rails/all.rb
  168. +4 −1 railties/lib/rails/generators/app_base.rb
  169. +1 −0 railties/lib/rails/generators/rails/app/templates/config/application.rb
  170. +1 −0 railties/lib/rails/generators/rails/plugin/templates/rails/application.rb
  171. +2 −0 railties/railties.gemspec
  172. +1 −0 railties/test/abstract_unit.rb
  173. +62 −0 railties/test/application/basic_rendering_test.rb
  174. +1 −0 railties/test/application/url_generation_test.rb
  175. +5 −0 railties/test/generators/app_generator_test.rb
  176. +1 −0 railties/test/generators/generators_test_helper.rb
  177. +7 −0 railties/test/isolation/abstract_unit.rb
  178. +2 −0 railties/test/rails_info_controller_test.rb
@@ -20,6 +20,7 @@ Gem::Specification.new do |s|
s.requirements << 'none'
s.add_dependency 'actionpack', version
+ s.add_dependency 'actionview', version
s.add_dependency 'mail', '~> 2.5.4'
end
@@ -22,7 +22,6 @@
#++
require 'abstract_controller'
-require 'action_view'
require 'action_mailer/version'
# Common Active Support usage in Action Mailer
@@ -3,6 +3,7 @@
require 'active_support/core_ext/string/inflections'
require 'active_support/core_ext/hash/except'
require 'active_support/core_ext/module/anonymous'
+
require 'action_mailer/log_subscriber'
module ActionMailer
@@ -361,11 +362,12 @@ module ActionMailer
# <tt>delivery_method :test</tt>. Most useful for unit and functional testing.
class Base < AbstractController::Base
include DeliveryMethods
+
abstract!
- include AbstractController::Logger
include AbstractController::Rendering
- include AbstractController::Layouts
+
+ include AbstractController::Logger
include AbstractController::Helpers
include AbstractController::Translation
include AbstractController::AssetPaths
@@ -1,3 +1,5 @@
+require 'active_support/log_subscriber'
+
module ActionMailer
# Implements the ActiveSupport::LogSubscriber for logging notifications when
# email is delivered and received.
@@ -11,11 +11,11 @@
require 'active_support/testing/autorun'
require 'action_mailer'
require 'action_mailer/test_case'
+require 'mail'
-silence_warnings do
- # These external dependencies have warnings :/
- require 'mail'
-end
+# Emulate AV railtie
+require 'action_view'
+ActionMailer::Base.send(:include, ActionView::Layouts)
# Show backtraces for deprecated behavior for quicker cleanup.
ActiveSupport::Deprecation.debug = true
@@ -1,4 +1,5 @@
require 'abstract_unit'
+require 'action_view'
require 'action_controller'
class I18nTestMailer < ActionMailer::Base
@@ -14,6 +15,9 @@ def mail_with_i18n_subject(recipient)
end
end
+# Emulate AV railtie
+ActionController::Base.superclass.send(:include, ActionView::Layouts)
+
class TestController < ActionController::Base
def send_mail
I18nTestMailer.mail_with_i18n_subject("test@localhost").deliver
View
@@ -1,3 +1,12 @@
+* Introduce `BasicRendering` which is the most basic rendering implementation. It
+ allows to `render :text` and `render :nothing` without need of having ActionView.
+
+ *Łukasz Strzałkowski*
+
+* Separate ActionView completely from ActionPack.
+
+ *Łukasz Strzałkowski*
+
* Development mode exceptions are rendered in text format in case of XHR request.
*Kir Shatrov*
@@ -20,11 +20,11 @@ Gem::Specification.new do |s|
s.requirements << 'none'
s.add_dependency 'activesupport', version
- s.add_dependency 'actionview', version
s.add_dependency 'rack', '~> 1.5.2'
s.add_dependency 'rack-test', '~> 0.6.2'
- s.add_development_dependency 'activemodel', version
- s.add_development_dependency 'tzinfo', '~> 0.3.37'
+ s.add_development_dependency 'actionview', version
+ s.add_development_dependency 'activemodel', version
+ s.add_development_dependency 'tzinfo', '~> 0.3.37'
end
@@ -10,12 +10,11 @@ module AbstractController
autoload :Base
autoload :Callbacks
autoload :Collector
+ autoload :DoubleRenderError, "abstract_controller/rendering"
autoload :Helpers
- autoload :Layouts
autoload :Logger
autoload :Rendering
autoload :Translation
autoload :AssetPaths
- autoload :ViewPaths
autoload :UrlFor
end
@@ -1,5 +1,5 @@
-require "abstract_controller/base"
-require "action_view"
+require 'active_support/concern'
+require 'active_support/core_ext/class/attribute'
module AbstractController
class DoubleRenderError < Error
@@ -10,91 +10,16 @@ def initialize(message = nil)
end
end
- # This is a class to fix I18n global state. Whenever you provide I18n.locale during a request,
- # it will trigger the lookup_context and consequently expire the cache.
- class I18nProxy < ::I18n::Config #:nodoc:
- attr_reader :original_config, :lookup_context
-
- def initialize(original_config, lookup_context)
- original_config = original_config.original_config if original_config.respond_to?(:original_config)
- @original_config, @lookup_context = original_config, lookup_context
- end
-
- def locale
- @original_config.locale
- end
-
- def locale=(value)
- @lookup_context.locale = value
- end
- end
-
module Rendering
extend ActiveSupport::Concern
- include AbstractController::ViewPaths
included do
class_attribute :protected_instance_variables
self.protected_instance_variables = []
end
- # Overwrite process to setup I18n proxy.
- def process(*) #:nodoc:
- old_config, I18n.config = I18n.config, I18nProxy.new(I18n.config, lookup_context)
- super
- ensure
- I18n.config = old_config
- end
-
- module ClassMethods
- def view_context_class
- @view_context_class ||= begin
- routes = respond_to?(:_routes) && _routes
- helpers = respond_to?(:_helpers) && _helpers
-
- Class.new(ActionView::Base) do
- if routes
- include routes.url_helpers
- include routes.mounted_helpers
- end
-
- if helpers
- include helpers
- end
- end
- end
- end
- end
-
- attr_internal_writer :view_context_class
-
- def view_context_class
- @_view_context_class ||= self.class.view_context_class
- end
-
- # An instance of a view class. The default view class is ActionView::Base
- #
- # The view class must have the following methods:
- # View.new[lookup_context, assigns, controller]
- # Create a new ActionView instance for a controller
- # View#render[options]
- # Returns String with the rendered template
- #
- # Override this method in a module to change the default behavior.
- def view_context
- view_context_class.new(view_renderer, view_assigns, self)
- end
-
- # Returns an object that is able to render templates.
- def view_renderer
- @_view_renderer ||= ActionView::Renderer.new(lookup_context)
- end
-
- # Normalize arguments, options and then delegates render_to_body and
- # sticks the result in self.response_body.
- def render(*args, &block)
- options = _normalize_render(*args, &block)
- self.response_body = render_to_body(options)
+ def default_protected_instance_vars
+ [:@_action_name, :@_response_body, :@_formats, :@_prefixes, :@_config]
end
# Raw rendering of a template to a string.
@@ -109,28 +34,23 @@ def render(*args, &block)
# overridden in order to still return a string.
# :api: plugin
def render_to_string(*args, &block)
- options = _normalize_render(*args, &block)
- render_to_body(options)
end
# Raw rendering of a template.
# :api: plugin
def render_to_body(options = {})
- _process_options(options)
- _render_template(options)
end
- # Find and renders a template based on the options given.
- # :api: private
- def _render_template(options) #:nodoc:
- lookup_context.rendered_format = nil if options[:formats]
- view_renderer.render(view_context, options)
+ # Normalize arguments, options and then delegates render_to_body and
+ # sticks the result in self.response_body.
+ # :api: public
+ def render(*args, &block)
end
- DEFAULT_PROTECTED_INSTANCE_VARIABLES = [
- :@_action_name, :@_response_body, :@_formats, :@_prefixes, :@_config,
- :@_view_context_class, :@_view_renderer, :@_lookup_context
- ]
+ # Return Content-Type of rendered content
+ # :api: public
+ def rendered_format
+ end
# This method should return a hash with assigns.
# You can overwrite this configuration per controller.
@@ -139,58 +59,28 @@ def view_assigns
hash = {}
variables = instance_variables
variables -= protected_instance_variables
- variables -= DEFAULT_PROTECTED_INSTANCE_VARIABLES
+ variables -= default_protected_instance_vars
variables.each { |name| hash[name[1..-1]] = instance_variable_get(name) }
hash
end
- private
-
- # Normalize args and options.
- # :api: private
- def _normalize_render(*args, &block)
- options = _normalize_args(*args, &block)
- _normalize_options(options)
- options
- end
-
# Normalize args by converting render "foo" to render :action => "foo" and
# render "foo/bar" to render :file => "foo/bar".
# :api: plugin
def _normalize_args(action=nil, options={})
- case action
- when NilClass
- when Hash
- options = action
- when String, Symbol
- action = action.to_s
- key = action.include?(?/) ? :file : :action
- options[key] = action
- else
- options[:partial] = action
- end
-
options
end
# Normalize options.
# :api: plugin
def _normalize_options(options)
- if options[:partial] == true
- options[:partial] = action_name
- end
-
- if (options.keys & [:partial, :file, :template]).empty?
- options[:prefixes] ||= _prefixes
- end
-
- options[:template] ||= (options[:action] || action_name).to_s
options
end
# Process extra options.
# :api: plugin
def _process_options(options)
+ options
end
end
end
@@ -13,6 +13,7 @@ module ActionController
autoload :Middleware
autoload_under "metal" do
+ autoload :BasicRendering, 'action_controller/metal/rendering'
autoload :Compatibility
autoload :ConditionalGet
autoload :Cookies
@@ -46,18 +47,9 @@ module ActionController
def self.eager_load!
super
ActionController::Caching.eager_load!
- HTML.eager_load!
end
end
-# All of these simply register additional autoloads
-require 'action_view'
-require 'action_view/vendor/html-scanner'
-
-ActiveSupport.on_load(:action_view) do
- ActionView::RoutingUrlFor.send(:include, ActionDispatch::Routing::UrlFor)
-end
-
# Common Active Support usage in Action Controller
require 'active_support/core_ext/class/attribute_accessors'
require 'active_support/core_ext/load_error'
@@ -2,6 +2,21 @@
require "action_controller/metal/params_wrapper"
module ActionController
+ # The <tt>metal</tt> anonymous class was introduced to solve issue with including modules in <tt>ActionController::Base</tt>.
+ # Modules needes to be included in particluar order. First wee need to have <tt>AbstractController::Rendering</tt> included,
+ # next we should include actuall implementation which would be for example <tt>ActionView::Rendering</tt> and after that
+ # <tt>ActionController::Rendering</tt>. This order must be preserved and as we want to have middle module included dynamicaly
+ # <tt>metal</tt> class was introduced. It has <tt>AbstractController::Rendering</tt> included and is parent class of
+ # <tt>ActionController::Base</tt> which includes <tt>ActionController::Rendering</tt>. If we include <tt>ActionView::Rendering</tt>
+ # beetween them to perserve the required order, we can simply do this by:
+ #
+ # ActionController::Base.superclass.send(:include, ActionView::Rendering)
+ #
+ metal = Class.new(Metal) do
+ include AbstractController::Rendering
+ include ActionController::BasicRendering
+ end
+
# Action Controllers are the core of a web request in \Rails. They are made up of one or more actions that are executed
# on request and then either it renders a template or redirects to another action. An action is defined as a public method
# on the controller, which will automatically be made accessible to the web-server through \Rails Routes.
@@ -160,7 +175,7 @@ module ActionController
# render action: "overthere" # won't be called if monkeys is nil
# end
#
- class Base < Metal
+ class Base < metal
abstract!
# We document the request and response methods here because albeit they are
@@ -200,7 +215,6 @@ def self.without_modules(*modules)
end
MODULES = [
- AbstractController::Layouts,
AbstractController::Translation,
AbstractController::AssetPaths,
Oops, something went wrong.

0 comments on commit c199580

Please sign in to comment.