Sha256: f9fe6c07842c85e80319010a0510b986a4950478bc76a46b866d26ed1d896dc3
Contents?: true
Size: 1.1 KB
Versions: 1
Compression:
Stored size: 1.1 KB
Contents
# 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
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rockit-0.7.1 | lib/rockit/prettyprint/text_renderer.rb |