Skip to content

Commit

Permalink
extracted sets of Node::SaveOptions into Node::SaveOptions::DEFAULT_{…
Browse files Browse the repository at this point in the history
…X,H,XH}TML
  • Loading branch information
flavorjones committed Mar 9, 2011
1 parent a5bf3b2 commit fa671aa
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 25 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.rdoc
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
== 1.5.0 / unreleased

* Features

* extracted sets of Node::SaveOptions into Node::SaveOptions::DEFAULT_{X,H,XH}TML (refactor)

== 1.5.0 beta3 / 2010/12/02

* Notes
Expand Down
5 changes: 1 addition & 4 deletions lib/nokogiri/html/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,7 @@ def title=(text)
# end
#
def serialize options = {}
options[:save_with] ||= XML::Node::SaveOptions::FORMAT |
XML::Node::SaveOptions::AS_HTML |
XML::Node::SaveOptions::NO_DECLARATION |
XML::Node::SaveOptions::NO_EMPTY_TAGS
options[:save_with] ||= XML::Node::SaveOptions::DEFAULT_HTML
super
end

Expand Down
27 changes: 6 additions & 21 deletions lib/nokogiri/xml/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -742,11 +742,7 @@ def to_html options = {}
# FIXME: this is a hack around broken libxml versions
return dump_html if Nokogiri.uses_libxml? && %w[2 6] === LIBXML_VERSION.split('.')[0..1]

options[:save_with] ||= SaveOptions::FORMAT |
SaveOptions::NO_DECLARATION |
SaveOptions::NO_EMPTY_TAGS |
SaveOptions::AS_HTML

options[:save_with] ||= SaveOptions::DEFAULT_HTML
serialize(options)
end

Expand All @@ -757,8 +753,7 @@ def to_html options = {}
#
# See Node#write_to for a list of +options+
def to_xml options = {}
options[:save_with] ||= SaveOptions::FORMAT | SaveOptions::AS_XML

options[:save_with] ||= SaveOptions::DEFAULT_XML
serialize(options)
end

Expand All @@ -772,11 +767,7 @@ def to_xhtml options = {}
# FIXME: this is a hack around broken libxml versions
return dump_html if Nokogiri.uses_libxml? && %w[2 6] === LIBXML_VERSION.split('.')[0..1]

options[:save_with] ||= SaveOptions::FORMAT |
SaveOptions::NO_DECLARATION |
SaveOptions::NO_EMPTY_TAGS |
SaveOptions::AS_XHTML

options[:save_with] ||= SaveOptions::DEFAULT_XHTML
serialize(options)
end

Expand Down Expand Up @@ -818,10 +809,7 @@ def write_html_to io, options = {}
# FIXME: this is a hack around broken libxml versions
return (io << dump_html) if Nokogiri.uses_libxml? && %w[2 6] === LIBXML_VERSION.split('.')[0..1]

options[:save_with] ||= SaveOptions::FORMAT |
SaveOptions::NO_DECLARATION |
SaveOptions::NO_EMPTY_TAGS |
SaveOptions::AS_HTML
options[:save_with] ||= SaveOptions::DEFAULT_HTML
write_to io, options
end

Expand All @@ -833,10 +821,7 @@ def write_xhtml_to io, options = {}
# FIXME: this is a hack around broken libxml versions
return (io << dump_html) if Nokogiri.uses_libxml? && %w[2 6] === LIBXML_VERSION.split('.')[0..1]

options[:save_with] ||= SaveOptions::FORMAT |
SaveOptions::NO_DECLARATION |
SaveOptions::NO_EMPTY_TAGS |
SaveOptions::AS_XHTML
options[:save_with] ||= SaveOptions::DEFAULT_XHTML
write_to io, options
end

Expand All @@ -847,7 +832,7 @@ def write_xhtml_to io, options = {}
#
# See Node#write_to for a list of options
def write_xml_to io, options = {}
options[:save_with] ||= SaveOptions::FORMAT | SaveOptions::AS_XML
options[:save_with] ||= SaveOptions::DEFAULT_XML
write_to io, options
end

Expand Down
7 changes: 7 additions & 0 deletions lib/nokogiri/xml/node/save_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ class SaveOptions
# Save as HTML
AS_HTML = 64

# the default for XML documents
DEFAULT_XML = FORMAT | AS_XML
# the default for HTML document
DEFAULT_HTML = FORMAT | NO_DECLARATION | NO_EMPTY_TAGS | AS_HTML
# the default for XHTML document
DEFAULT_XHTML = FORMAT | NO_DECLARATION | NO_EMPTY_TAGS | AS_XHTML

# Integer representation of the SaveOptions
attr_reader :options

Expand Down

0 comments on commit fa671aa

Please sign in to comment.