Permalink
Browse files

Cache JavaScriptGenerator's helper module set on the template

  • Loading branch information...
1 parent c111522 commit 229eedfda87a7706dbb5e3e51af8707b3adae375 @josh josh committed Aug 26, 2008
@@ -328,11 +328,6 @@ def pick_template(template_path)
memoize :pick_template
private
- def extended_by_without_helpers #:nodoc:
- extended_by.reject { |mod| mod.name =~ /^ActionView::Helpers/ }
- end
- memoize :extended_by_without_helpers
-
# Evaluate the local assigns and pushes them to the view.
def evaluate_assigns
unless @assigns_added
@@ -588,8 +588,26 @@ def initialize(context, &block) #:nodoc:
private
def include_helpers_from_context
- @context.send(:extended_by_without_helpers).each { |mod| extend mod }
- extend GeneratorMethods
+ 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
end
# JavaScriptGenerator generates blocks of JavaScript code that allow you
@@ -108,9 +108,4 @@ def test_javascript_tag_with_block_and_options_in_erb
def test_javascript_cdata_section
assert_dom_equal "\n//<![CDATA[\nalert('hello')\n//]]>\n", javascript_cdata_section("alert('hello')")
end
-
- private
- def extended_by_without_helpers
- []
- end
end
@@ -53,10 +53,6 @@ def protect_against_forgery?
false
end
- def extended_by_without_helpers
- []
- end
-
def create_generator
block = Proc.new { |*args| yield *args if block_given? }
JavaScriptGenerator.new self, &block

0 comments on commit 229eedf

Please sign in to comment.