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

Conflicts:

	CHANGELOG.rdoc
  • Loading branch information
flavorjones committed Mar 9, 2011
1 parent e88eb51 commit 5bbed7e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 25 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rdoc
Expand Up @@ -3,6 +3,7 @@
* New Features

* Nokogiri::HTML::Document#title accessor gets and sets the document title.
* extracted sets of Node::SaveOptions into Node::SaveOptions::DEFAULT_{X,H,XH}TML (refactor)

* Bugfixes

Expand Down
5 changes: 1 addition & 4 deletions lib/nokogiri/html/document.rb
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
Expand Up @@ -740,11 +740,7 @@ def to_html options = {}
# FIXME: this is a hack around broken libxml versions
return dump_html if %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 @@ -755,8 +751,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 @@ -770,11 +765,7 @@ def to_xhtml options = {}
# FIXME: this is a hack around broken libxml versions
return dump_html if %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 @@ -817,10 +808,7 @@ def write_html_to io, options = {}
# FIXME: this is a hack around broken libxml versions
return (io << dump_html) if %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 @@ -832,10 +820,7 @@ def write_xhtml_to io, options = {}
# FIXME: this is a hack around broken libxml versions
return (io << dump_html) if %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 @@ -846,7 +831,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
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 5bbed7e

Please sign in to comment.