Skip to content

Commit c74e1d3

Browse files
committed
Merge pull request #512 from k0kubun/ruby-head
Force ERB in Thor::Actions to use String buffer
2 parents 60963b2 + 9382996 commit c74e1d3

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

lib/thor/actions/file_manipulation.rb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def template(source, *args, &block)
113113
context = config.delete(:context) || instance_eval("binding")
114114

115115
create_file destination, nil, config do
116-
content = ERB.new(::File.binread(source), nil, "-", "@output_buffer").result(context)
116+
content = CapturableERB.new(::File.binread(source), nil, "-", "@output_buffer").result(context)
117117
content = block.call(content) if block
118118
content
119119
end
@@ -312,5 +312,16 @@ def with_output_buffer(buf = "") #:nodoc:
312312
ensure
313313
self.output_buffer = old_buffer
314314
end
315+
316+
# Thor::Actions#capture depends on what kind of buffer is used in ERB.
317+
# Thus CapturableERB fixes ERB to use String buffer.
318+
class CapturableERB < ERB
319+
def set_eoutvar(compiler, eoutvar = '_erbout')
320+
compiler.put_cmd = "#{eoutvar}.concat"
321+
compiler.insert_cmd = "#{eoutvar}.concat"
322+
compiler.pre_cmd = ["#{eoutvar} = ''"]
323+
compiler.post_cmd = [eoutvar]
324+
end
325+
end
315326
end
316327
end

0 commit comments

Comments
 (0)