Skip to content
Browse files

Fixed suite for Rails 2.0.2 and 1.99.0.

  • Loading branch information...
1 parent 2a65c8a commit 91e55ba2af01a829a47e82354ed6a188798d9b16 Brian Takita committed
View
28 lib/erector/rails/template_handlers/1.2.5/action_view_template_handler.rb
@@ -1,12 +1,12 @@
module ActionView #:nodoc:
module TemplateHandlers #:nodoc:
- class Erector < TemplateHandler
+ class Erector
def self.line_offset
2
end
attr_reader :view
- def initialize(*view)
+ def initialize(view)
@view = view
end
@@ -14,27 +14,7 @@ def compilable?
true
end
- ActionView::Base.instance_eval do
- if respond_to?(:register_template_handler)
- register_template_handler :rb, ActionView::TemplateHandlers::Erector
- end
- end
-
- def compile(template)
- relative_path_parts = view.first_render.split('/')
- require_dependency view.template_file_path
-
- dot_rb = /\.rb$/
- widget_class_parts = relative_path_parts.inject(['Views']) do |class_parts, node|
- class_parts << node.gsub(dot_rb, '').camelize
- class_parts
- end
- widget_class_name = widget_class_parts.join("::")
- render_method = view.is_partial_template? ? 'render_partial' : 'render'
-
- erb_template = "<% #{widget_class_name}.new(self, controller.assigns, _erbout).#{render_method} %>"
- ::ERB.new(erb_template, nil, @view.erb_trim_mode).src
- end
+ ActionView::Base.register_template_handler :rb, ActionView::TemplateHandlers::Erector
def render(template, local_assigns)
relative_path_parts = view.first_render.split('/')
@@ -42,7 +22,7 @@ def render(template, local_assigns)
dot_rb = /\.rb$/
widget_class = relative_path_parts.inject(Views) do |mod, node|
- mod.const_get(node.gsub(dot_rb, '').camelize)
+ mod.const_get(node.gsub(dot_rb, '').gsub(".html", "").camelize)
end
render_method = view.is_partial_template? ? 'render_partial' : 'render'
widget_class.new(view, view.assigns).to_s(render_method)
View
45 lib/erector/rails/template_handlers/2.0.0/action_view_template_handler.rb
@@ -6,52 +6,31 @@ def self.line_offset
end
attr_reader :view
- def initialize(*view)
+ def initialize(view)
@view = view
end
def compilable?
true
end
+ undef :compile
- ActionView::Template.instance_eval do
- register_template_handler :rb, ActionView::TemplateHandlers::Erector
- end
-
- def compile_template(template)
- relative_path_parts = template.path.split('/')
- require_dependency view.finder.pick_template(
- template.path,
- view.finder.pick_template_extension(template.path)
- )
-
- dot_rb = /\.rb$/
- widget_class_parts = relative_path_parts.inject(['Views']) do |class_parts, node|
- class_parts << node.gsub(dot_rb, '').camelize
- class_parts
- end
- widget_class_name = widget_class_parts.join("::")
- render_method = template.is_a?(ActionView::PartialTemplate) ? 'render_partial' : 'render'
-
- erb_template = "<% #{widget_class_name}.new(self, controller.assigns, _erbout).#{render_method} %>"
- ::ERB.new(erb_template, nil, @view.erb_trim_mode).src
- end
- alias_method :compile, :compile_template
+ ActionView::Base.register_template_handler :rb, ActionView::TemplateHandlers::Erector
- def render(template)
- relative_path_parts = template.path.split('/')
- require_dependency view.finder.pick_template(
- template.path,
- view.finder.pick_template_extension(template.path)
- )
+ def render(template, local_assigns)
+ relative_path_parts = view.first_render.split('/')
+ file_name = relative_path_parts.last
+ require_dependency(view.template_file_path)
dot_rb = /\.rb$/
widget_class = relative_path_parts.inject(Views) do |mod, node|
- mod.const_get(node.gsub(dot_rb, '').camelize)
+ mod.const_get(node.gsub(dot_rb, '').gsub(".html", "").camelize)
end
- render_method = template.is_a?(ActionView::PartialTemplate) ? 'render_partial' : 'render'
- widget_class.new(view, view.assigns).to_s(render_method)
+ render_method = view.is_partial_template? ? 'render_partial' : 'render'
+ widget = widget_class.new(view, view.assigns)
+ widget.to_s(render_method)
end
end
end
end
+
View
4 lib/erector/rails/template_handlers/action_view_template_handler.rb
@@ -1,6 +1,6 @@
dir = File.dirname(__FILE__)
-if ActionView.const_defined?(:Template)
- if ActionView.const_defined?(:TemplateHandlers) && ::ActionView::TemplateHandlers::const_defined?(:Compilable)
+if ActionView.const_defined?(:TemplateHandlers)
+ if ::ActionView::TemplateHandlers::const_defined?(:Compilable)
if ActionView.const_defined?(:TemplateHandlers) && ::ActionView::TemplateHandlers::ERB.respond_to?(:erb_trim_mode)
require File.expand_path("#{dir}/2.2.0/action_view_template_handler")
else

0 comments on commit 91e55ba

Please sign in to comment.
Something went wrong with that request. Please try again.