summaryrefslogtreecommitdiff
path: root/lib/yaml/baseemitter.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/yaml/baseemitter.rb')
-rw-r--r--lib/yaml/baseemitter.rb230
1 files changed, 115 insertions, 115 deletions
diff --git a/lib/yaml/baseemitter.rb b/lib/yaml/baseemitter.rb
index c2c68752a8..da908d98dc 100644
--- a/lib/yaml/baseemitter.rb
+++ b/lib/yaml/baseemitter.rb
@@ -30,121 +30,121 @@ module YAML
self.node_text( [value].pack("m"), '|' )
end
- #
- # Emit plain, normal flowing text
- #
- def node_text( value, block = '>' )
+ #
+ # Emit plain, normal flowing text
+ #
+ def node_text( value, block = nil )
@seq_map = false
- valx = value.dup
+ valx = value.dup
unless block
- block =
- if options(:UseBlock)
- '|'
- elsif not options(:UseFold) and valx =~ /\n[ \t]/ and not valx =~ /#{YAML::ESCAPE_CHAR}/
- '|'
- else
- '>'
- end
+ block =
+ if options(:UseBlock)
+ '|'
+ elsif not options(:UseFold) and valx =~ /\n[ \t]/ and not valx =~ /#{YAML::ESCAPE_CHAR}/
+ '|'
+ else
+ '>'
+ end
if valx =~ /\A[ \t#]/
block += options(:Indent).to_s
end
- block +=
- if valx =~ /\n\Z\n/
- "+"
- elsif valx =~ /\Z\n/
- ""
- else
- "-"
- end
- end
- if valx =~ /#{YAML::ESCAPE_CHAR}/
- valx = YAML::escape( valx )
- end
- if block[0] == ?>
- valx = fold( valx )
+ block +=
+ if valx =~ /\n\Z\n/
+ "+"
+ elsif valx =~ /\Z\n/
+ ""
+ else
+ "-"
+ end
end
+ if valx =~ /#{YAML::ESCAPE_CHAR}/
+ valx = YAML::escape( valx )
+ end
+ if block[0] == ?>
+ valx = fold( valx )
+ end
indt = nil
indt = $&.to_i if block =~ /\d+/
- self << block + indent_text( valx, indt ) + "\n"
- end
+ #p [block, indt]
+ self << block + indent_text( valx, indt ) + "\n"
+ end
- #
- # Emit a simple, unqouted string
- #
- def simple( value )
+ #
+ # Emit a simple, unqouted string
+ #
+ def simple( value )
@seq_map = false
self << value.to_s
- end
+ end
- #
- # Emit double-quoted string
- #
- def double( value )
- "\"#{YAML.escape( value )}\""
- end
+ #
+ # Emit double-quoted string
+ #
+ def double( value )
+ "\"#{YAML.escape( value )}\""
+ end
- #
- # Emit single-quoted string
- #
- def single( value )
- "'#{value}'"
- end
+ #
+ # Emit single-quoted string
+ #
+ def single( value )
+ "'#{value}'"
+ end
- #
- # Write a text block with the current indent
- #
- def indent_text( text, indt = nil )
- return "" if text.to_s.empty?
- indt ||= 0
- spacing = indent( indt )
- return "\n" + text.gsub( /^([^\n])/, "#{spacing}\\1" )
- end
+ #
+ # Write a text block with the current indent
+ #
+ def indent_text( text, mod = nil )
+ return "" if text.to_s.empty?
+ spacing = indent( mod )
+ return "\n" + text.gsub( /^([^\n])/, "#{spacing}\\1" )
+ end
- #
- # Write a current indent
- #
+ #
+ # Write a current indent
+ #
def indent( mod = nil )
- #p [ self.id, @level, :INDENT ]
- if level.zero?
+ #p [ self.id, level, mod, :INDENT ]
+ if level <= 0
mod ||= 0
else
mod ||= options(:Indent)
mod += ( level - 1 ) * options(:Indent)
end
return " " * mod
- end
+ end
- #
- # Add indent to the buffer
- #
- def indent!
- self << indent
- end
+ #
+ # Add indent to the buffer
+ #
+ def indent!
+ self << indent
+ end
- #
- # Folding paragraphs within a column
- #
- def fold( value )
- value.gsub!( /\A\n+/, '' )
- folded = $&.to_s
- width = (0..options(:BestWidth))
- while not value.empty?
- last = value.index( /(\n+)/ )
- chop_s = false
- if width.include?( last )
- last += $1.length - 1
- elsif width.include?( value.length )
- last = value.length
- else
- last = value.rindex( /[ \t]/, options(:BestWidth) )
- chop_s = true
- end
- folded += value.slice!( 0, width.include?( last ) ? last + 1 : options(:BestWidth) )
- folded.chop! if chop_s
- folded += "\n" unless value.empty?
- end
- folded
- end
+ #
+ # Folding paragraphs within a column
+ #
+ def fold( value )
+ value.gsub!( /\A\n+/, '' )
+ folded = $&.to_s
+ width = (0..options(:BestWidth))
+ while not value.empty?
+ last = value.index( /(\n+)/ )
+ chop_s = false
+ if width.include?( last )
+ last += $1.length - 1
+ elsif width.include?( value.length )
+ last = value.length
+ else
+ last = value.rindex( /[ \t]/, options(:BestWidth) )
+ chop_s = true
+ end
+ folded += value.slice!( 0, width.include?( last ) ? last + 1 : options(:BestWidth) )
+ folded.chop! if chop_s
+ folded += "\n" unless value.empty?
+ end
+ folded
+ end
#
# Quick mapping
@@ -152,18 +152,18 @@ module YAML
def map( type, &e )
val = Mapping.new
e.call( val )
- self << "#{type} " if type.length.nonzero?
+ self << "#{type} " if type.length.nonzero?
- #
- # Empty hashes
- #
- if val.length.zero?
- self << "{}"
+ #
+ # Empty hashes
+ #
+ if val.length.zero?
+ self << "{}"
@seq_map = false
- else
+ else
# FIXME
# if @buffer.length == 1 and options(:UseHeader) == false and type.length.zero?
- # @headless = 1
+ # @headless = 1
# end
defkey = @options.delete( :DefaultKey )
@@ -173,9 +173,9 @@ module YAML
defkey.to_yaml( :Emitter => self )
end
- #
- # Emit the key and value
- #
+ #
+ # Emit the key and value
+ #
val.each { |v|
seq_map_shortcut
if v[0].is_complex_yaml?
@@ -189,7 +189,7 @@ module YAML
self << ": "
v[1].to_yaml( :Emitter => self )
}
- end
+ end
end
def seq_map_shortcut
@@ -210,22 +210,22 @@ module YAML
@seq_map = false
val = Sequence.new
e.call( val )
- self << "#{type} " if type.length.nonzero?
+ self << "#{type} " if type.length.nonzero?
- #
- # Empty arrays
- #
- if val.length.zero?
- self << "[]"
- else
+ #
+ # Empty arrays
+ #
+ if val.length.zero?
+ self << "[]"
+ else
# FIXME
# if @buffer.length == 1 and options(:UseHeader) == false and type.length.zero?
- # @headless = 1
+ # @headless = 1
# end
- #
- # Emit the key and value
- #
+ #
+ # Emit the key and value
+ #
val.each { |v|
self << "\n"
indent!
@@ -233,7 +233,7 @@ module YAML
@seq_map = true if v.class == Hash
v.to_yaml( :Emitter => self )
}
- end
+ end
end
end