diff options
author | Carlhuda <carlhuda@engineyard.com> | 2010-03-18 18:12:04 -0700 |
---|---|---|
committer | Carlhuda <carlhuda@engineyard.com> | 2010-03-18 18:14:54 -0700 |
commit | a5d80f84d269bba6b0f0802612f29df1ee09d720 (patch) | |
tree | d5673cda114eeaab9dcbc7107d227f6c83f2c2f3 /actionpack/lib/abstract_controller | |
parent | e629e21135d9d0e87c02e1106e489f943f19d2d9 (diff) | |
download | rails-a5d80f84d269bba6b0f0802612f29df1ee09d720.tar.gz rails-a5d80f84d269bba6b0f0802612f29df1ee09d720.tar.bz2 rails-a5d80f84d269bba6b0f0802612f29df1ee09d720.zip |
Each controller class has it's own view context subclass. This removes the need for ActionView::Base.for_controller
Diffstat (limited to 'actionpack/lib/abstract_controller')
-rw-r--r-- | actionpack/lib/abstract_controller/helpers.rb | 10 | ||||
-rw-r--r-- | actionpack/lib/abstract_controller/rendering.rb | 28 |
2 files changed, 25 insertions, 13 deletions
diff --git a/actionpack/lib/abstract_controller/helpers.rb b/actionpack/lib/abstract_controller/helpers.rb index f875213afb..53cf6b3931 100644 --- a/actionpack/lib/abstract_controller/helpers.rb +++ b/actionpack/lib/abstract_controller/helpers.rb @@ -6,16 +6,10 @@ module AbstractController include Rendering - def self.next_serial - @helper_serial ||= 0 - @helper_serial += 1 - end - included do - class_attribute :_helpers, :_helper_serial + class_attribute :_helpers delegate :_helpers, :to => :'self.class' self._helpers = Module.new - self._helper_serial = ::AbstractController::Helpers.next_serial end module ClassMethods @@ -95,8 +89,6 @@ module AbstractController # helper(:three, BlindHelper) { def mice() 'mice' end } # def helper(*args, &block) - self._helper_serial = AbstractController::Helpers.next_serial + 1 - modules_for_helpers(args).each do |mod| add_template_helper(mod) end diff --git a/actionpack/lib/abstract_controller/rendering.rb b/actionpack/lib/abstract_controller/rendering.rb index 402ad7c8d7..58d339d563 100644 --- a/actionpack/lib/abstract_controller/rendering.rb +++ b/actionpack/lib/abstract_controller/rendering.rb @@ -42,18 +42,38 @@ module AbstractController I18n.config = old_config end + module ClassMethods + def view_context_class + @view_context_class ||= begin + controller = self + Class.new(ActionView::Base) do + if controller.respond_to?(:_helpers) + include controller._helpers + # TODO: Fix RJS to not require this + self.helpers = controller._helpers + end + end + end + end + end + + attr_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.for_controller[controller] + # View.new[lookup_context, assigns, controller] # Create a new ActionView instance for a controller - # View#render_template[options] + # View#render[options] # Returns String with the rendered template # # Override this method in a module to change the default behavior. def view_context - klass = ActionView::Base.for_controller(self) - klass.new(lookup_context, view_assigns, self) + view_context_class.new(lookup_context, view_assigns, self) end # Normalize arguments, options and then delegates render_to_body and |