Compare commits

...

5 Commits

Author SHA1 Message Date
Charlie Somerville
71dc3f7fa3 will CI like this? 2013-10-23 19:41:38 -04:00
Charlie Somerville
47d4630c39 here too 2013-10-23 18:52:22 -04:00
Charlie Somerville
7e5382f27e instantiate the cached helper class instead of extending AV::B 2013-10-23 16:42:47 -04:00
Charlie Somerville
88b2f91442 delete ActionView::Base#helpers because it's completely useless 2013-10-23 16:42:28 -04:00
Charlie Somerville
26a1e3738f cache a class that is pre-included with the master helper module 2013-10-23 16:42:13 -04:00
7 changed files with 21 additions and 35 deletions

View File

@@ -1280,8 +1280,7 @@ module ActionController #:nodoc:
end
def initialize_template_class(response)
response.template = ActionView::Base.new(self.class.view_paths, {}, self)
response.template.helpers.send :include, self.class.master_helper_module
response.template = self.class.master_helper_class.new(self.class.view_paths, {}, self)
response.redirected_to = nil
@performed_render = @performed_redirect = false
end

View File

@@ -5,8 +5,8 @@ module ActionController #:nodoc:
module Helpers #:nodoc:
def self.included(base)
# Initialize the base module to aggregate its helpers.
base.class_inheritable_accessor :master_helper_module
base.master_helper_module = Module.new
base.class_inheritable_accessor :master_helper_class
base.master_helper_class = Class.new(ActionView::Base)
# Set the default directory for helpers
base.class_inheritable_accessor :helpers_dir
@@ -73,7 +73,7 @@ module ActionController #:nodoc:
# See ActionView::Helpers (link:classes/ActionView/Helpers.html) for more about making your own helper modules
# available to the templates.
def add_template_helper(helper_module) #:nodoc:
master_helper_module.module_eval { include helper_module }
master_helper_class.class_eval { include helper_module }
end
# The +helper+ class method can take a series of helper module names, a block, or both.
@@ -141,7 +141,7 @@ module ActionController #:nodoc:
end
# Evaluate block in template class if given.
master_helper_module.module_eval(&block) if block_given?
master_helper_class.class_eval(&block) if block_given?
end
# Declare a controller method as a helper. For example, the following
@@ -162,7 +162,7 @@ module ActionController #:nodoc:
# <% if logged_in? -%>Welcome, <%= current_user.name %><% end -%>
def helper_method(*methods)
methods.flatten.each do |method|
master_helper_module.module_eval <<-end_eval
master_helper_class.class_eval <<-end_eval
def #{method}(*args, &block) # def current_user(*args, &block)
controller.send(%(#{method}), *args, &block) # controller.send(%(current_user), *args, &block)
end # end
@@ -182,8 +182,7 @@ module ActionController #:nodoc:
# Provides a proxy to access helpers methods from outside the view.
def helpers
unless @helper_proxy
@helper_proxy = ActionView::Base.new
@helper_proxy.extend master_helper_module
@helper_proxy = master_helper_class.new
else
@helper_proxy
end
@@ -207,8 +206,7 @@ module ActionController #:nodoc:
inherited_without_helper(child)
begin
child.master_helper_module = Module.new
child.master_helper_module.__send__ :include, master_helper_module
child.master_helper_class = Class.new(master_helper_class)
child.__send__ :default_helper_module!
rescue MissingSourceFile => e
raise unless e.is_missing?("helpers/#{child.controller_path}_helper")

View File

@@ -210,24 +210,10 @@ 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
@_first_render = nil

View File

@@ -91,7 +91,7 @@ module ActionView
def helper_method(*methods)
# Almost a duplicate from ActionController::Helpers
methods.flatten.each do |method|
master_helper_module.module_eval <<-end_eval
master_helper_class.class_eval <<-end_eval
def #{method}(*args, &block) # def current_user(*args, &block)
_test_case.send(%(#{method}), *args, &block) # test_case.send(%(current_user), *args, &block)
end # end
@@ -109,15 +109,14 @@ module ActionView
private
def make_test_case_available_to_view!
test_case_instance = self
master_helper_module.module_eval do
master_helper_class.class_eval do
define_method(:_test_case) { test_case_instance }
private :_test_case
end
end
def _view
view = ActionView::Base.new(ActionController::Base.view_paths, _assigns, @controller)
view.helpers.include master_helper_module
view = self.class.master_helper_class.new(ActionController::Base.view_paths, _assigns, @controller)
view.output_buffer = self.output_buffer
view
end

View File

@@ -118,7 +118,7 @@ class HelperTest < Test::Unit::TestCase
end
def test_all_helpers
methods = ApplicationController.master_helper_module.instance_methods.map(&:to_s)
methods = ApplicationController.master_helper_class.instance_methods.map(&:to_s)
# abc_helper.rb
assert methods.include?('bare_a')
@@ -134,7 +134,7 @@ class HelperTest < Test::Unit::TestCase
@controller_class.helpers_dir = File.dirname(__FILE__) + '/../fixtures/alternate_helpers'
# Reload helpers
@controller_class.master_helper_module = Module.new
@controller_class.master_helper_class = Class.new(ActionView::Base)
@controller_class.helper :all
# helpers/abc_helper.rb should not be included
@@ -166,7 +166,7 @@ class HelperTest < Test::Unit::TestCase
end
def master_helper_methods
@controller_class.master_helper_module.instance_methods.map(&:to_s)
@controller_class.master_helper_class.instance_methods.map(&:to_s)
end
def missing_methods

View File

@@ -1034,6 +1034,10 @@ class RenderTest < ActionController::TestCase
new Draggable(value, {});
});
}.gsub(/^ /, '').strip
if body != @response.body
puts "<<<<<<<\n#{body}\n=======\n#{@response.body}\n>>>>>>>>"
exit!
end
assert_equal body, @response.body
end
@@ -1113,7 +1117,7 @@ class RenderTest < ActionController::TestCase
def test_should_implicitly_render_js_template_without_layout
get :render_implicit_js_template_without_layout, :format => :js
assert_no_match /<html>/, @response.body
assert_no_match(/<html>/, @response.body)
end
def test_should_render_formatted_template

View File

@@ -122,7 +122,7 @@ module ActionView
test "named routes can be used from helper included in view" do
with_routing do |set|
set.draw { |map| map.resources :contents }
master_helper_module.module_eval do
master_helper_class.class_eval do
def render_from_helper
new_content_url
end
@@ -146,7 +146,7 @@ module ActionView
end
test "is able to make methods available to the view" do
master_helper_module.module_eval do
master_helper_class.class_eval do
def render_from_helper; from_test_case end
end
assert_equal 'Word!', render(:partial => 'test/from_helper')