lib/tracksperanto/flame_builder.rb in tracksperanto-1.8.1 vs lib/tracksperanto/flame_builder.rb in tracksperanto-1.8.2

- old
+ new

@@ -10,10 +10,15 @@ value.nil? ? write_loose!(name) : write_tuple!(name, value) yield(self.class.new(@io, @indent + 1)) @io.puts(INDENT * (@indent + 1) + "End") end + def write_unterminated_block!(name, value = nil, &blk) + value.nil? ? write_loose!(name) : write_tuple!(name, value) + yield(self.class.new(@io, @indent + 1)) + end + def write_tuple!(key, value) @io.puts("%s%s %s" % [INDENT * @indent, __camelize(key), __flameize(value)]) end def write_loose!(value) @@ -23,37 +28,39 @@ def linebreak!(how_many = 1) @io.write("\n" * how_many) end def color_hash!(name, red, green, blue) - write_loose!(name) - n = self.class.new(@io, @indent + 1) - n.red(red) - n.green(green) - n.blue(blue) + write_unterminated_block!(name) do | b | + b.red(red) + b.green(green) + b.blue(blue) + end end + def <<(some_verbatim_string) + some_verbatim_string.split("\n").each do | line | + @io.puts(["\t" * @indent, line].join) + end + end + private def method_missing(meth, arg = nil) - self.class.send(:alias_method, meth, :__generic) if block_given? - __generic(meth, arg) {|*a| yield(*a) if block_given? } + write_block!(meth, arg) {|c| yield(c) } else - __generic(meth, arg) + if arg.nil? + write_loose!(meth) + else + write_tuple!(meth, arg) + end end end - def __generic(meth, arg = nil) - if block_given? - write_block!(meth, arg) { |c| yield(c) } - else - arg.nil? ? write_loose!(meth) : write_tuple!(meth, arg) - end - end - def __camelize(s) - s.to_s.gsub(/(^|_)(.)/) { $2.upcase } + @@camelizations ||= {} + @@camelizations[s] ||= s.to_s.gsub(/(^|_)(.)/) { $2.upcase } end def __flameize(v) case v when Float \ No newline at end of file