mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* lib/yaml/baseemitter.rb (indent_text): was forcing a mod value
of zero at times, which kept some blocks from getting indentation. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6333 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
246b33d108
commit
620549da3f
2 changed files with 120 additions and 115 deletions
|
@ -1,3 +1,8 @@
|
|||
Mon May 17 00:36:21 2004 why the lucky stiff <why@ruby-lang.org>
|
||||
|
||||
* lib/yaml/baseemitter.rb (indent_text): was forcing a mod value
|
||||
of zero at times, which kept some blocks from getting indentation.
|
||||
|
||||
Mon May 17 00:07:00 2004 Gavin Sinclair <gsinclair@soyabean.com.au>
|
||||
|
||||
* lib/drb/drb.rb: Cosmetic documentation changes.
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue