diff options
| author | why <why@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-05-06 06:39:45 +0000 |
|---|---|---|
| committer | why <why@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-05-06 06:39:45 +0000 |
| commit | 4aeb2bbc60d75d9490536fc080ddee50267a8c6d (patch) | |
| tree | 77ab105fb4d3d964ac9b3f06b971d0c2d1a6b76f /lib/yaml/baseemitter.rb | |
| parent | 22cd153014ce943970112c62649e2da3315db23f (diff) | |
| download | ruby-4aeb2bbc60d75d9490536fc080ddee50267a8c6d.tar.gz ruby-4aeb2bbc60d75d9490536fc080ddee50267a8c6d.tar.xz ruby-4aeb2bbc60d75d9490536fc080ddee50267a8c6d.zip | |
* 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: http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8@6253 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/yaml/baseemitter.rb')
| -rw-r--r-- | lib/yaml/baseemitter.rb | 46 |
1 files changed, 27 insertions, 19 deletions
diff --git a/lib/yaml/baseemitter.rb b/lib/yaml/baseemitter.rb index 007ee7be5..1072f7553 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 |
