1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #39391 from jonathanhefner/erubi-configure-bufvar

Allow Erubi bufvar to be configured
This commit is contained in:
Rafael França 2020-05-21 19:21:29 -04:00 committed by GitHub
commit 598dc9f147
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 6 deletions

View file

@ -14,10 +14,10 @@ module ActionView
# Dup properties so that we don't modify argument
properties = Hash[properties]
properties[:bufvar] ||= "@output_buffer"
properties[:preamble] ||= ""
properties[:postamble] ||= "@output_buffer.to_s"
properties[:postamble] ||= "#{properties[:bufvar]}.to_s"
properties[:bufvar] = "@output_buffer"
properties[:escapefunc] = ""
super
@ -39,7 +39,7 @@ module ActionView
if text == "\n"
@newline_pending += 1
else
src << "@output_buffer.safe_append='"
src << bufvar << ".safe_append='"
src << "\n" * @newline_pending if @newline_pending > 0
src << text.gsub(/['\\]/, '\\\\\&')
src << "'.freeze;"
@ -54,9 +54,9 @@ module ActionView
flush_newline_if_pending(src)
if (indicator == "==") || @escape
src << "@output_buffer.safe_expr_append="
src << bufvar << ".safe_expr_append="
else
src << "@output_buffer.append="
src << bufvar << ".append="
end
if BLOCK_EXPR.match?(code)
@ -78,7 +78,7 @@ module ActionView
def flush_newline_if_pending(src)
if @newline_pending > 0
src << "@output_buffer.safe_append='#{"\n" * @newline_pending}'.freeze;"
src << bufvar << ".safe_append='#{"\n" * @newline_pending}'.freeze;"
@newline_pending = 0
end
end

View file

@ -0,0 +1,21 @@
# frozen_string_literal: true
require "abstract_unit"
require "action_view/template/handlers/erb/erubi"
class ErubiTest < ActiveSupport::TestCase
test "can configure bufvar" do
template = <<~ERB
foo
<%= "foo".upcase %>
<%== "foo".length %>
ERB
baseline = ActionView::Template::Handlers::ERB::Erubi.new(template)
erubi = ActionView::Template::Handlers::ERB::Erubi.new(template, bufvar: "boofer")
assert_equal baseline.src.gsub("#{baseline.bufvar}.", "boofer."), erubi.src
end
end