From ab3c4962acfcbb3c259e09902c655aaf413d295b Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Mon, 6 Mar 2023 17:05:40 -0500 Subject: [PATCH] doc: update CHANGELOG and Node#write_to docstring --- CHANGELOG.md | 3 +++ lib/nokogiri/xml/node.rb | 31 +++++++++++++++++++------------ 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c9884d7e040..b0623456b9f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,9 @@ Nokogiri follows [Semantic Versioning](https://semver.org/), please see the [REA ### Added +* Serialization methods like `#to_xml`, `#to_html`, `#serialize`, and `#write_to` now accept `Encoding` objects specifying the output encoding. Previously only encoding names (strings) were accepted. [[#2774](https://github.com/sparklemotion/nokogiri/issues/2774), [#2798](https://github.com/sparklemotion/nokogiri/issues/2798)] (Thanks, [@ellaklara](https://github.com/ellaklara)!) + + ### Changed ### Fixed diff --git a/lib/nokogiri/xml/node.rb b/lib/nokogiri/xml/node.rb index 3dc97b4d8bb..d106651e6de 100644 --- a/lib/nokogiri/xml/node.rb +++ b/lib/nokogiri/xml/node.rb @@ -1269,11 +1269,11 @@ def <=>(other) # # These two statements are equivalent: # - # node.serialize(:encoding => 'UTF-8', :save_with => FORMAT | AS_XML) + # node.serialize(encoding: 'UTF-8', save_with: FORMAT | AS_XML) # # or # - # node.serialize(:encoding => 'UTF-8') do |config| + # node.serialize(encoding: 'UTF-8') do |config| # config.format.as_xml # end # @@ -1310,7 +1310,7 @@ def to_html(options = {}) ### # Serialize this Node to XML using +options+ # - # doc.to_xml(:indent => 5, :encoding => 'UTF-8') + # doc.to_xml(indent: 5, encoding: 'UTF-8') # # See Node#write_to for a list of +options+ def to_xml(options = {}) @@ -1321,7 +1321,7 @@ def to_xml(options = {}) ### # Serialize this Node to XHTML using +options+ # - # doc.to_xhtml(:indent => 5, :encoding => 'UTF-8') + # doc.to_xhtml(indent: 5, encoding: 'UTF-8') # # See Node#write_to for a list of +options+ def to_xhtml(options = {}) @@ -1329,21 +1329,28 @@ def to_xhtml(options = {}) end ### - # Write Node to +io+ with +options+. +options+ modify the output of - # this method. Valid options are: + # :call-seq: + # write_to(io, *options) + # + # Serialize this node or document to +io+. + # + # [Parameters] + # - +io+ (IO) An IO-like object to which the serialized content will be written. + # - +options+ (Hash) See below # - # * +:encoding+ for changing the encoding - # * +:indent_text+ the indentation text, defaults to one space - # * +:indent+ the number of +:indent_text+ to use, defaults to 2 - # * +:save_with+ a combination of SaveOptions constants. + # [Options] + # * +:encoding+ (String or Encoding) specify the encoding of the output (defaults to document encoding) + # * +:indent_text+ (String) the indentation text (defaults to " ") + # * +:indent+ (Integer) the number of +:indent_text+ to use (defaults to +2+) + # * +:save_with+ (Integer) a combination of SaveOptions constants # # To save with UTF-8 indented twice: # - # node.write_to(io, :encoding => 'UTF-8', :indent => 2) + # node.write_to(io, encoding: 'UTF-8', indent: 2) # # To save indented with two dashes: # - # node.write_to(io, :indent_text => '-', :indent => 2) + # node.write_to(io, indent_text: '-', indent: 2) # def write_to(io, *options) options = options.first.is_a?(Hash) ? options.shift : {}