1require 'erb'
2
3##
4# A subclass of ERB that writes directly to an IO.  Credit to Aaron Patterson
5# and Masatoshi SEKI.
6#
7# To use:
8#
9#   erbio = RDoc::ERBIO.new '<%= "hello world" %>', nil, nil
10#
11#   open 'hello.txt', 'w' do |io|
12#     erbio.result binding
13#   end
14#
15# Note that binding must enclose the io you wish to output on.
16
17class RDoc::ERBIO < ERB
18
19  ##
20  # Defaults +eoutvar+ to 'io', otherwise is identical to ERB's initialize
21
22  def initialize str, safe_level = nil, trim_mode = nil, eoutvar = 'io'
23    super
24  end
25
26  ##
27  # Instructs +compiler+ how to write to +io_variable+
28
29  def set_eoutvar compiler, io_variable
30    compiler.put_cmd    = "#{io_variable}.write"
31    compiler.insert_cmd = "#{io_variable}.write"
32    compiler.pre_cmd    = []
33    compiler.post_cmd   = []
34  end
35
36end
37
38