90a91
> puts "TemplateConverter._convert_template"
105a107
> puts "conversion done"
139a142,235
> if ActionPack::VERSION::MINOR >=2 ### Rails 2.2 or higher
> # TODO: Make this work for Rails 2.2
> # NOTES:
> # @view is no longer initialized to TemplateHandlers in 2.2
> module ActionView
> class Template
> attr_accessor :view
> end
> class Base
> private
> def _pick_template(template_path)
> if template_path.respond_to?(:render)
> template_path.view = self
> return template_path
> end
>
> path = template_path.sub(/^\//, '')
> if m = path.match(/(.*)\.(\w+)$/)
> template_file_name, template_file_extension = m[1], m[2]
> else
> template_file_name = path
> end
>
> # OPTIMIZE: Checks to lookup template in view path
> template = if template = self.view_paths["#{template_file_name}.#{template_format}"]
> template
> elsif template = self.view_paths[template_file_name]
> template
> elsif (first_render = @_render_stack.first) && first_render.respond_to?(:format_and_extension) &&
> (template = self.view_paths["#{template_file_name}.#{first_render.format_and_extension}"])
> template
> elsif template_format == :js && template = self.view_paths["#{template_file_name}.html"]
> @template_format = :html
> template
> else
> template = Template.new(template_path, view_paths)
> if self.class.warn_cache_misses && logger
> logger.debug "[PERFORMANCE] Rendering a template that was " +
> "not found in view path. Templates outside the view path are " +
> "not cached and result in expensive disk operations. Move this " +
> "file into #{view_paths.join(':')} or add the folder to your " +
> "view path list"
> end
> template
> end
> template.view = self
> template
> end
> memoize(:_pick_template)
>
> # # TODO: This really should work, but i'm having issues with aliasing memoized methods
> # # The method then returns a nil view
> # alias :_orig__pick_template :_pick_template
> # def _pick_template(template_path)
> # template = _orig__pick_template(template_path)
> # template.view = self
> # template
> # end
> end
> module TemplateHandlers # :nodoc:
> class ErubisHandler < TemplateHandler
> include Compilable
> include Erubis::Helpers::RailsHelper::TemplateConverter
> include Erubis::PreprocessingHelper
> attr_accessor :view
>
> def compile(template)
> puts "ErubisHandler.compile #{template}"
> puts Kernel.caller.first
> self.view = template.view
> src = _convert_template(template.source)
> src.insert(0, '__in_erb_template = true; ')
> src.gsub!('_buf', '@output_buffer')
> src.insert(0, "@output_buffer ||= ''; ")
> return src
> end
> def logger #:nodoc:
> return Logger.new
> end
> def _preprocessing_context_object #:nodoc:
> view.controller.instance_variable_get('@_template')
> end
> #
> def cache_fragment(block, name = {}, options = nil) #:nodoc:
> view.fragment_for(block, name, options) do
> eval('@output_buffer', block.binding)
> end
> end
> end
> end
> handler_klass = TemplateHandlers::ErubisHandler
> Template.register_default_template_handler :erb, handler_klass
> Template.register_template_handler :rhtml, handler_klass
> end
141c237
< if ActionPack::VERSION::MINOR >=1 ### Rails 2.1 or higher
---
> elsif ActionPack::VERSION::MINOR =1 ### Rails 2.1