Sha256: 92d1d6a8c38ae73ce05cc4677f3e314a8f2cb8ca22dd62035cb2dc6146655eb3

Contents?: true

Size: 525 Bytes

Versions: 24

Compression:

Stored size: 525 Bytes

Contents

module CSL
  module PrettyPrinter
    
    def tags
      raise 'not implemened by base class'
    end
    
    def to_xml
      tags.flatten.join
    end

    def pretty_print
      preamble << tags.map { |t| pp t }.join("\n")
    end

    private
    
    def tabwidth
      2
    end
    
    def preamble
      ''
    end
    
    def pp(tag, level = 0)
      if tag.is_a?(Array)
        tag.map { |t| pp t, level + 1 }.join("\n")
      else
        (' ' * (level * tabwidth)) << tag.to_s
      end
    end
    
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
csl-1.0.1 lib/csl/pretty_printer.rb
csl-1.0.0 lib/csl/pretty_printer.rb
csl-1.0.0.pre23 lib/csl/pretty_printer.rb
csl-1.0.0.pre22 lib/csl/pretty_printer.rb