diff options
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | ext/psych/emitter.c | 28 | ||||
-rw-r--r-- | ext/psych/lib/psych/visitors/yaml_tree.rb | 2 | ||||
-rw-r--r-- | test/psych/test_emitter.rb | 6 |
4 files changed, 42 insertions, 1 deletions
@@ -1,3 +1,10 @@ +Fri Jul 9 00:49:46 2010 Aaron Patterson <aaron@tenderlovemaking.com> + + * ext/psych/emitter.c (line_width, set_line_width): preferred line may + be set on the emitter. + + * test/psych/test_emitter.rb: corresponding tests. + Thu Jul 8 15:47:34 2010 NARUSE, Yui <naruse@ruby-lang.org> * string.c (rb_str_conv_enc_opts): fix infinite loop because diff --git a/ext/psych/emitter.c b/ext/psych/emitter.c index 189b865ea3..a85fa45ef5 100644 --- a/ext/psych/emitter.c +++ b/ext/psych/emitter.c @@ -460,6 +460,32 @@ static VALUE indentation(VALUE self) return INT2NUM(emitter->best_indent); } +/* call-seq: emitter.line_width + * + * Get the preferred line width. + */ +static VALUE line_width(VALUE self) +{ + yaml_emitter_t * emitter; + Data_Get_Struct(self, yaml_emitter_t, emitter); + + return INT2NUM(emitter->best_width); +} + +/* call-seq: emitter.line_width = width + * + * Set the preferred line with to +width+. + */ +static VALUE set_line_width(VALUE self, VALUE width) +{ + yaml_emitter_t * emitter; + Data_Get_Struct(self, yaml_emitter_t, emitter); + + yaml_emitter_set_width(emitter, NUM2INT(width)); + + return width; +} + void Init_psych_emitter() { VALUE psych = rb_define_module("Psych"); @@ -483,6 +509,8 @@ void Init_psych_emitter() rb_define_method(cPsychEmitter, "canonical=", set_canonical, 1); rb_define_method(cPsychEmitter, "indentation", indentation, 0); rb_define_method(cPsychEmitter, "indentation=", set_indentation, 1); + rb_define_method(cPsychEmitter, "line_width", line_width, 0); + rb_define_method(cPsychEmitter, "line_width=", set_line_width, 1); id_write = rb_intern("write"); } diff --git a/ext/psych/lib/psych/visitors/yaml_tree.rb b/ext/psych/lib/psych/visitors/yaml_tree.rb index 8a12086458..620b520a75 100644 --- a/ext/psych/lib/psych/visitors/yaml_tree.rb +++ b/ext/psych/lib/psych/visitors/yaml_tree.rb @@ -54,7 +54,7 @@ module Psych version = @options[:version].split('.').map { |x| x.to_i } else version = [1,1] - end if @options[:version] + end if @options.key? :version @emitter.start_document version, [], false accept object diff --git a/test/psych/test_emitter.rb b/test/psych/test_emitter.rb index d7c6fff4ec..0554ae5f85 100644 --- a/test/psych/test_emitter.rb +++ b/test/psych/test_emitter.rb @@ -10,6 +10,12 @@ module Psych @emitter = Psych::Emitter.new @out end + def test_line_width + assert_equal 0, @emitter.line_width + assert_equal 10, @emitter.line_width = 10 + assert_equal 10, @emitter.line_width + end + def test_set_canonical @emitter.canonical = true assert_equal true, @emitter.canonical |