lib/roadie/document.rb in roadie-5.0.1 vs lib/roadie/document.rb in roadie-5.1.0

- old
+ new

@@ -40,17 +40,24 @@ # @media(max-width: 600px) { .col-6 { display: block; } .col-12 { display: block; } } # @media(max-width: 400px) { .col-12 { display: inline-block; } } # which would change the styling on the page attr_accessor :merge_media_queries + # Integer representing a bitmap set of options used by Nokogiri during serialization. + # For the complete set of available options look into +Nokogiri::XML::Node::SaveOptions+. + attr_reader :serialization_options + # The mode to generate markup in. Valid values are `:html` (default) and `:xhtml`. attr_reader :mode # @param [String] html the input HTML def initialize(html) @keep_uninlinable_css = true @merge_media_queries = true + @serialization_options = + Nokogiri::XML::Node::SaveOptions::NO_DECLARATION | + Nokogiri::XML::Node::SaveOptions::NO_EMPTY_TAGS @html = html @asset_providers = ProviderList.wrap(FilesystemProvider.new) @external_asset_providers = ProviderList.empty @css = +"" @mode = :html @@ -135,10 +142,17 @@ # Assign new external asset providers. The supplied list will be wrapped in a {ProviderList} using {ProviderList.wrap}. def external_asset_providers=(list) @external_asset_providers = ProviderList.wrap(list) end + # Integer representing a bitmap set of options used by Nokogiri during serialization. + # For the complete set of available options look into +Nokogiri::XML::Node::SaveOptions+. + # (To change the mode in which the document is generated use {#mode=} however.) + def serialization_options=(options) + @serialization_options = options || 0 + end + # Change the mode. The mode affects how the resulting markup is generated. # # Valid modes: # `:html` (default) # `:xhtml` @@ -185,16 +199,10 @@ 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 - ) - ) + dom.dup.to_html(save_with: (serialization_options | format)) end def make_url_rewriter if url_options UrlRewriter.new(UrlGenerator.new(url_options))