aboutsummaryrefslogtreecommitdiffstats
path: root/lib/yaml/baseemitter.rb
diff options
context:
space:
mode:
authorwhy <why@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-05-06 06:29:56 +0000
committerwhy <why@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-05-06 06:29:56 +0000
commit2fa9a0b08c7d2c672d2ae2ac8b76a66cfc1c5082 (patch)
tree0f783680b6f2a9d2cd9848b98bfd0bce55d81993 /lib/yaml/baseemitter.rb
parentf77db2ed9ca3f9c404594787b456b1cabee351c7 (diff)
downloadruby-2fa9a0b08c7d2c672d2ae2ac8b76a66cfc1c5082.tar.gz
* lib/yaml/rubytypes.rb (to_yaml): added instance variable handling
for Ranges, Strings, Structs, Regexps. * lib/yaml/rubytypes.rb (to_yaml_fold): new method for setting a String's flow style. * lib/yaml.rb (YAML::object_maker): now uses Object.allocate. * ext/syck/gram.c: fixed transfer methods on structs, broke it last commit. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6252 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/yaml/baseemitter.rb')
-rw-r--r--lib/yaml/baseemitter.rb46
1 files changed, 27 insertions, 19 deletions
diff --git a/lib/yaml/baseemitter.rb b/lib/yaml/baseemitter.rb
index 007ee7be5e..1072f75533 100644
--- a/lib/yaml/baseemitter.rb
+++ b/lib/yaml/baseemitter.rb
@@ -36,28 +36,36 @@ module YAML
def node_text( value, block = '>' )
@seq_map = false
valx = value.dup
- if options(:UseBlock)
- block = '|'
- elsif not options(:UseFold) and valx =~ /\n[ \t]/ and not valx =~ /#{YAML::ESCAPE_CHAR}/
- block = '|'
- end
- str = block.dup
- if valx =~ /\n\Z\n/
- str << "+"
- elsif valx =~ /\Z\n/
- else
- str << "-"
- end
+ unless block
+ block =
+ if options(:UseBlock)
+ '|'
+ elsif not options(:UseFold) and valx =~ /\n[ \t]/ and not valx =~ /#{YAML::ESCAPE_CHAR}/
+ '|'
+ else
+ '>'
+ end
+ block +=
+ if valx =~ /\n\Z\n/
+ "+"
+ elsif valx =~ /\Z\n/
+ ""
+ else
+ "-"
+ end
+ if valx =~ /\A[ \t#]/
+ block += options(:Indent).to_s
+ end
+ end
if valx =~ /#{YAML::ESCAPE_CHAR}/
valx = YAML::escape( valx )
end
- if valx =~ /\A[ \t#]/
- str << options(:Indent).to_s
- end
- if block == '>'
+ if block[0] == ?>
valx = fold( valx )
end
- self << str + indent_text( valx ) + "\n"
+ indt = nil
+ indt = $&.to_i if block =~ /\d+/
+ self << block + indent_text( valx, indt ) + "\n"
end
#
@@ -85,9 +93,9 @@ module YAML
#
# Write a text block with the current indent
#
- def indent_text( text )
+ def indent_text( text, indt = nil )
return "" if text.to_s.empty?
- spacing = " " * ( level * options(:Indent) )
+ spacing = " " * ( level * ( indt || options(:Indent) ) )
return "\n" + text.gsub( /^([^\n])/, "#{spacing}\\1" )
end