diff options
Diffstat (limited to 'lib/psych/visitors/yaml_tree.rb')
-rw-r--r-- | lib/psych/visitors/yaml_tree.rb | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/lib/psych/visitors/yaml_tree.rb b/lib/psych/visitors/yaml_tree.rb index e24b655..976ea8d 100644 --- a/lib/psych/visitors/yaml_tree.rb +++ b/lib/psych/visitors/yaml_tree.rb @@ -309,19 +309,20 @@ module Psych style = Nodes::Scalar::LITERAL plain = false quote = false - elsif o =~ /\n/ + elsif o =~ /\n[^\Z]/ # match \n except blank line at the end of string style = Nodes::Scalar::LITERAL elsif o == '<<' style = Nodes::Scalar::SINGLE_QUOTED tag = 'tag:yaml.org,2002:str' plain = false quote = false + elsif line_width != 0 && o.length > line_width + style = Nodes::Scalar::FOLDED + o += "\n" unless o =~ /\n\Z/ # to avoid non-default chomping indicator elsif o =~ /^[^[:word:]][^"]*$/ style = Nodes::Scalar::DOUBLE_QUOTED - else - unless String === @ss.tokenize(o) - style = Nodes::Scalar::SINGLE_QUOTED - end + elsif not String === @ss.tokenize(o) + style = Nodes::Scalar::SINGLE_QUOTED end ivars = find_ivars o @@ -588,6 +589,10 @@ module Psych accept target.instance_variable_get(iv) end end + + def line_width + @line_width ||= (@options[:line_width] || 0) + end end end end |