lib/luobo/base.rb in luobo-0.0.1 vs lib/luobo/base.rb in luobo-0.0.2

- old
+ new

@@ -7,12 +7,17 @@ class Base attr_accessor :driver def initialize file, output @source_file = file - @output = output.is_a?(IO) ? output : File.open(output, "w") - + if output.is_a?(IO) + @output = output + elsif output.is_a?(String) + @output_file = output + @output = File.open(output, "w") + end + # initialize: @token_stack = Array.new # initialize loop template and examples self.reset_loop @@ -45,11 +50,11 @@ # clear up holders self.reset_loop end def dump contents - @output.print contents if contents + @driver.dump(@output, contents) end # travel up through the token stack, close all token with # indent level larger or equal to the parameter def close_stack indent_level @@ -155,11 +160,11 @@ line.gsub!("\t", " ") # convert tab to 2 spaces # ensure first line as driver definition unless @driver if matches = /^#{regex_proc_head}DRIVER#{regex_proc_end}(?<dname_>\w+)\s*$/.match(line) - @driver = Driver.create(matches["dname_"]) + @driver = Driver.create(matches["dname_"]) self.dump(@driver.setup) next else raise "You must specify a driver on the first line" end @@ -202,10 +207,10 @@ # close all remain stacks self.close_stack 0 self.dump(@driver.exit) - @output.close + @output.close if @output_file self end end end