aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorJoshua Peek <josh@joshpeek.com>2008-08-26 16:17:58 -0500
committerJoshua Peek <josh@joshpeek.com>2008-08-26 16:17:58 -0500
commit6ec07e0737c3099056fc11fe43f4f19dde3770a6 (patch)
tree7911a26c4ed148c706951a301a1ebdc2e46af8e2 /actionpack
parentcd91a8d3adb70e573ab8d0d733a966db5eff1e1d (diff)
downloadrails-6ec07e0737c3099056fc11fe43f4f19dde3770a6.tar.gz
rails-6ec07e0737c3099056fc11fe43f4f19dde3770a6.tar.bz2
rails-6ec07e0737c3099056fc11fe43f4f19dde3770a6.zip
Store application and other context specific helper modules in ActionView::Base#helpers
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/action_controller/base.rb2
-rw-r--r--actionpack/lib/action_view/base.rb14
-rw-r--r--actionpack/lib/action_view/helpers/prototype_helper.rb22
3 files changed, 17 insertions, 21 deletions
diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb
index 91023cd774..55e1d48949 100644
--- a/actionpack/lib/action_controller/base.rb
+++ b/actionpack/lib/action_controller/base.rb
@@ -1148,7 +1148,7 @@ module ActionController #:nodoc:
def initialize_template_class(response)
response.template = ActionView::Base.new(self.class.view_paths, {}, self)
- response.template.extend self.class.master_helper_module
+ response.template.helpers.send :include, self.class.master_helper_module
response.redirected_to = nil
@performed_render = @performed_redirect = false
end
diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb
index d174c784f3..c65048bfa0 100644
--- a/actionpack/lib/action_view/base.rb
+++ b/actionpack/lib/action_view/base.rb
@@ -208,10 +208,24 @@ module ActionView #:nodoc:
ActionView::PathSet.new(Array(value))
end
+ attr_reader :helpers
+
+ class ProxyModule < Module
+ def initialize(receiver)
+ @receiver = receiver
+ end
+
+ def include(*args)
+ super(*args)
+ @receiver.extend(*args)
+ end
+ end
+
def initialize(view_paths = [], assigns_for_first_render = {}, controller = nil)#:nodoc:
@assigns = assigns_for_first_render
@assigns_added = nil
@controller = controller
+ @helpers = ProxyModule.new(self)
self.view_paths = view_paths
end
diff --git a/actionpack/lib/action_view/helpers/prototype_helper.rb b/actionpack/lib/action_view/helpers/prototype_helper.rb
index ff83494e94..2ce818cd71 100644
--- a/actionpack/lib/action_view/helpers/prototype_helper.rb
+++ b/actionpack/lib/action_view/helpers/prototype_helper.rb
@@ -588,26 +588,8 @@ module ActionView
private
def include_helpers_from_context
- unless generator_methods_module = @context.instance_variable_get(:@__javascript_generator_methods__)
- modules = @context.extended_by - ([ActionView::Helpers] + ActionView::Helpers.included_modules)
-
- generator_methods_module = Module.new do
- modules.each do |mod|
- begin
- include mod
- rescue Exception => e
- # HACK: Probably not a good idea to suppress these warnings
- # AFAIK exceptions are only raised in while testing with mocha
- # because the module does not like to be included into other
- # non TestUnit classes
- end
- end
- include GeneratorMethods
- end
- @context.instance_variable_set(:@__javascript_generator_methods__, generator_methods_module)
- end
-
- extend generator_methods_module
+ extend @context.helpers if @context.respond_to?(:helpers)
+ extend GeneratorMethods
end
# JavaScriptGenerator generates blocks of JavaScript code that allow you