1 # frozen_string_literal: true
5 # A subclass of ERB that writes directly to an IO. Credit to Aaron Patterson
10 # erbio = RDoc::ERBIO.new '<%= "hello world" %>', nil, nil
12 # File.open 'hello.txt', 'w' do |io|
13 # erbio.result binding
16 # Note that binding must enclose the io you wish to output on.
18 class RDoc::ERBIO < ERB
21 # Defaults +eoutvar+ to 'io', otherwise is identical to ERB's initialize
23 def initialize str, trim_mode: nil, eoutvar: 'io'
24 super(str, trim_mode: trim_mode, eoutvar: eoutvar)
28 # Instructs +compiler+ how to write to +io_variable+
30 def set_eoutvar compiler, io_variable
31 compiler.put_cmd = "#{io_variable}.write"
32 compiler.insert_cmd = "#{io_variable}.write"
34 compiler.post_cmd = []