# Basic Text Renderer for Box # require 'rockit/prettyprint/renderer' module Rockit module PrettyPrint module Box class TextRenderer < Renderer attr_reader :max_horizontal attr_reader :horizontal_delim, :vertical_delim def initialize(maxHorizontal = 80, horizontalDelim = " ", verticalDelim = "\n") @max_horizontal = maxHorizontal @horizontal_delim = horizontalDelim @vertical_delim = verticalDelim end def render_term(term) # Instead of fiddling with visitors we simply add a uniquely named # method render_as_text to each Box term we support. term.render_as_text(self) end end class H < Term def render_as_text(renderer) elements[0..-2].each do |e| renderer.render_term(e) renderer.render_hdelim(num_spaces) end renderer.render_term(elements[-1]) end end class V < Term def render_as_text(renderer) elements[0..-2].each do |e| renderer.render_term(e) renderer << "\n" end renderer.render_term(elements[-1]) end end end end end