Skip to content

Commit

Permalink
Merge pull request #45678 from Shopify/action-view-fire-erubi-evaluate
Browse files Browse the repository at this point in the history
Get rid of Erubi#evaluate
  • Loading branch information
byroot committed Jul 28, 2022
2 parents b712fc9 + 55756ea commit b8964e5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
9 changes: 0 additions & 9 deletions actionview/lib/action_view/template/handlers/erb/erubi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,6 @@ def initialize(input, properties = {})
super
end

def evaluate(action_view_erb_handler_context)
src = @src
view = Class.new(ActionView::Base) {
include action_view_erb_handler_context._routes.url_helpers
class_eval("define_method(:_template) { |local_assigns, output_buffer| #{src} }", defined?(@filename) ? @filename : "(erubi)", 0)
}.empty
view._run(:_template, nil, {}, ActionView::OutputBuffer.new)
end

private
def add_text(text)
return if text.empty?
Expand Down
20 changes: 15 additions & 5 deletions actionview/test/template/erb/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,25 @@ def protect_against_forgery?() false end
end

class BlockTestCase < ActiveSupport::TestCase
class Context < ActionView::Base
end

def render_content(start, inside, routes = nil)
routes ||= ActionDispatch::Routing::RouteSet.new.tap do |rs|
rs.draw { }
end
context = Class.new(ViewContext) {
include routes.url_helpers
}.new
template = block_helper(start, inside)
ActionView::Template::Handlers::ERB.erb_implementation.new(template).evaluate(context)

view = Class.new(Context)
view.include routes.url_helpers

ActionView::Template.new(
block_helper(start, inside),
"test#{rand}",
ActionView::Template::Handlers::ERB.new,
virtual_path: "partial",
format: :html,
locals: []
).render(view.with_empty_template_cache.empty, {})
end

def block_helper(str, rest)
Expand Down

0 comments on commit b8964e5

Please sign in to comment.