lib/roadie/document.rb in roadie-4.0.0 vs lib/roadie/document.rb in roadie-5.0.0

- old
+ new

@@ -140,20 +140,22 @@ # Change the mode. The mode affects how the resulting markup is generated. # # Valid modes: # `:html` (default) # `:xhtml` + # `:xml` def mode=(mode) if VALID_MODES.include?(mode) @mode = mode else raise ArgumentError, "Invalid mode #{mode.inspect}. Valid modes are: #{VALID_MODES.inspect}" end end private - VALID_MODES = %i[html xhtml].freeze + + VALID_MODES = %i[html xhtml xml].freeze private_constant :VALID_MODES def stylesheet Stylesheet.new "(Document styles)", @css end @@ -166,11 +168,11 @@ keep_uninlinable_in = options.fetch(:keep_uninlinable_in) dom_stylesheets = AssetScanner.new(dom, asset_providers, external_asset_providers).extract_css Inliner.new(dom_stylesheets + [stylesheet], dom).inline( keep_uninlinable_css: keep_uninlinable_css, keep_uninlinable_in: keep_uninlinable_in, - merge_media_queries: merge_media_queries, + merge_media_queries: merge_media_queries ) end def rewrite_urls(dom) make_url_rewriter.transform_dom(dom) @@ -180,18 +182,19 @@ # #dup is called since it fixed a few segfaults in certain versions of Nokogiri save_options = Nokogiri::XML::Node::SaveOptions format = { html: save_options::AS_HTML, xhtml: save_options::AS_XHTML, + xml: save_options::AS_XML }.fetch(mode) dom.dup.to_html( save_with: ( save_options::NO_DECLARATION | save_options::NO_EMPTY_TAGS | format - ), + ) ) end def make_url_rewriter if url_options @@ -201,16 +204,10 @@ end end def callback(callable, dom) if callable.respond_to?(:call) - # Arity checking is to support the API without bumping a major version. - # TODO: Remove on next major version (v4.0) - if !callable.respond_to?(:parameters) || callable.parameters.size == 1 - callable.(dom) - else - callable.(dom, self) - end + callable.call(dom, self) end end def remove_ignore_markers(dom) dom.css("[data-roadie-ignore]").each do |node|