Skip to content

Commit

Permalink
doc: update CHANGELOG and Node#write_to docstring
Browse files Browse the repository at this point in the history
  • Loading branch information
flavorjones committed Mar 6, 2023
1 parent a978f75 commit ab3c496
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 19 additions & 12 deletions lib/nokogiri/xml/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand Down Expand Up @@ -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 = {})
Expand All @@ -1321,29 +1321,36 @@ 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 = {})
to_format(SaveOptions::DEFAULT_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 <code>" "</code>)
# * +: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 : {}
Expand Down

0 comments on commit ab3c496

Please sign in to comment.