diff options
Diffstat (limited to 'actionpack/lib/action_view')
-rw-r--r-- | actionpack/lib/action_view/paths.rb | 4 | ||||
-rw-r--r-- | actionpack/lib/action_view/renderable.rb | 5 | ||||
-rw-r--r-- | actionpack/lib/action_view/template.rb | 12 | ||||
-rw-r--r-- | actionpack/lib/action_view/template_handlers.rb | 25 | ||||
-rw-r--r-- | actionpack/lib/action_view/test_case.rb | 25 |
5 files changed, 56 insertions, 15 deletions
diff --git a/actionpack/lib/action_view/paths.rb b/actionpack/lib/action_view/paths.rb index 9c8b8ade1e..623b9ff6b0 100644 --- a/actionpack/lib/action_view/paths.rb +++ b/actionpack/lib/action_view/paths.rb @@ -57,6 +57,10 @@ module ActionView #:nodoc: end end + def to_str + path.to_str + end + def ==(path) to_str == path.to_str end diff --git a/actionpack/lib/action_view/renderable.rb b/actionpack/lib/action_view/renderable.rb index 7258ad04bf..7c0e62f1d7 100644 --- a/actionpack/lib/action_view/renderable.rb +++ b/actionpack/lib/action_view/renderable.rb @@ -28,11 +28,6 @@ module ActionView stack = view.instance_variable_get(:@_render_stack) stack.push(self) - # This is only used for TestResponse to set rendered_template - unless is_a?(InlineTemplate) || view.instance_variable_get(:@_first_render) - view.instance_variable_set(:@_first_render, self) - end - view.send(:_evaluate_assigns_and_ivars) view.send(:_set_controller_content_type, mime_type) if respond_to?(:mime_type) diff --git a/actionpack/lib/action_view/template.rb b/actionpack/lib/action_view/template.rb index e32b7688d0..8f4ca433c0 100644 --- a/actionpack/lib/action_view/template.rb +++ b/actionpack/lib/action_view/template.rb @@ -98,14 +98,10 @@ module ActionView #:nodoc: end private - def valid_extension?(extension) - Template.template_handler_extensions.include?(extension) - end - def find_full_path(path, load_paths) load_paths = Array(load_paths) + [nil] load_paths.each do |load_path| - file = [load_path, path].compact.join('/') + file = load_path ? "#{load_path.to_str}/#{path}" : path return load_path, file if File.file?(file) end raise MissingTemplate.new(load_paths, path) @@ -115,11 +111,11 @@ module ActionView #:nodoc: # [base_path, name, format, extension] def split(file) if m = file.match(/^(.*\/)?([^\.]+)\.?(\w+)?\.?(\w+)?\.?(\w+)?$/) - if valid_extension?(m[5]) # Multipart formats + if Template.valid_extension?(m[5]) # Multipart formats [m[1], m[2], "#{m[3]}.#{m[4]}", m[5]] - elsif valid_extension?(m[4]) # Single format + elsif Template.valid_extension?(m[4]) # Single format [m[1], m[2], m[3], m[4]] - elsif valid_extension?(m[3]) # No format + elsif Template.valid_extension?(m[3]) # No format [m[1], m[2], nil, m[3]] else # No extension [m[1], m[2], m[3], nil] diff --git a/actionpack/lib/action_view/template_handlers.rb b/actionpack/lib/action_view/template_handlers.rb index d06ddd5fb5..c50a51b0d1 100644 --- a/actionpack/lib/action_view/template_handlers.rb +++ b/actionpack/lib/action_view/template_handlers.rb @@ -28,6 +28,10 @@ module ActionView #:nodoc: @@template_handlers[extension.to_sym] = klass end + def valid_extension?(extension) + template_handler_extensions.include?(extension) || init_path_for_extension(extension) + end + def template_handler_extensions @@template_handlers.keys.map(&:to_s).sort end @@ -38,7 +42,26 @@ module ActionView #:nodoc: end def handler_class_for_extension(extension) - (extension && @@template_handlers[extension.to_sym]) || @@default_template_handlers + (extension && @@template_handlers[extension.to_sym] || autoload_handler_class(extension)) || + @@default_template_handlers end + + private + def autoload_handler_class(extension) + return if Gem.loaded_specs[extension] + return unless init_path = init_path_for_extension(extension) + Gem.activate(extension) + load(init_path) + handler_class_for_extension(extension) + end + + # Returns the path to the rails/init.rb file for the given extension, + # or nil if no gem provides it. + def init_path_for_extension(extension) + return unless spec = Gem.searcher.find(extension.to_s) + returning File.join(spec.full_gem_path, 'rails', 'init.rb') do |path| + return unless File.file?(path) + end + end end end diff --git a/actionpack/lib/action_view/test_case.rb b/actionpack/lib/action_view/test_case.rb index 4ab4ed233f..1a9ef983a5 100644 --- a/actionpack/lib/action_view/test_case.rb +++ b/actionpack/lib/action_view/test_case.rb @@ -1,4 +1,24 @@ module ActionView + class Base + alias_method :initialize_without_template_tracking, :initialize + def initialize(*args) + @_rendered = { :template => nil, :partials => Hash.new(0) } + initialize_without_template_tracking(*args) + end + end + + module Renderable + alias_method :render_without_template_tracking, :render + def render(view, local_assigns = {}) + if respond_to?(:path) && !is_a?(InlineTemplate) + rendered = view.instance_variable_get(:@_rendered) + rendered[:partials][self] += 1 if is_a?(RenderablePartial) + rendered[:template] ||= self + end + render_without_template_tracking(view, local_assigns) + end + end + class TestCase < ActiveSupport::TestCase include ActionController::TestCase::Assertions @@ -40,11 +60,14 @@ module ActionView end class TestController < ActionController::Base - attr_accessor :request, :response + attr_accessor :request, :response, :params def initialize @request = ActionController::TestRequest.new @response = ActionController::TestResponse.new + + @params = {} + send(:initialize_current_url) end end |