Class: RubyToBlock::Formatter
- Inherits:
-
REXML::Formatters::Pretty
- Object
- REXML::Formatters::Pretty
- RubyToBlock::Formatter
- Defined in:
- app/models/concerns/ruby_to_block/formatter.rb
Overview
XMLをフォーマットするクラス
REXML::Formatters::Prettyでは行頭、行末などのスペースが1つになって しまうため、このクラスではそれらを修正している
Instance Method Summary collapse
-
#initialize ⇒ Formatter
constructor
A new instance of Formatter.
- #write_text(node, output) ⇒ Object
Constructor Details
#initialize ⇒ Formatter
Returns a new instance of Formatter.
9 10 11 12 |
# File 'app/models/concerns/ruby_to_block/formatter.rb', line 9 def initialize super(2, true) self.compact = true end |
Instance Method Details
#write_text(node, output) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'app/models/concerns/ruby_to_block/formatter.rb', line 14 def write_text(node, output) s = node.to_s s.gsub!(/\s/, ' ') if !node.is_a?(REXML::Text) || node.is_a?(REXML::Text) && !node.parent.whitespace s.squeeze!(' ') end s = wrap(s, @width - @level) s = indent_text(s, @level, ' ', true) output << (' ' * @level + s) end |