lib/premailer/adapter/nokogiri.rb
# Create a <tt>style</tt> element with un-mergable rules (e.g. <tt>:hover</tt>)
# and write it into the <tt>body</tt>.
#
# <tt>doc</tt> is an Nokogiri document and <tt>unmergable_css_rules</tt> is a Css::RuleSet.
#
# @return [::Nokogiri::XML] a document.
Create a style element with un-mergable rules
and write it into the body.

doc is an Nokogiri document and unmergable_css_rules is a Css::RuleSet.
Create a style element with un - mergable rules and write it into the body . doc is an Nokogiri document and unmergable_css_rules is a Css :: RuleSet .
def write_unmergable_css_rules(doc, unmergable_rules) 
        styles = ''
        unmergable_rules.each_selector(:all, :force_important => true) do |selector, declarations, specificity|
          styles += "#{selector} { #{declarations} }\n"
        end
        unless styles.empty?
          style_tag = "<style type=\"text/css\">\n#{styles}></style>"
          if head = doc.search('head')
            doc.at_css('head').add_child(::Nokogiri::XML.fragment(style_tag))
          elsif body = doc.search('body')
            if doc.at_css('body').children && !doc.at_css('body').children.empty?
              doc.at_css('body').children.before(::Nokogiri::XML.fragment(style_tag))
            else
              doc.at_css('body').add_child(::Nokogiri::XML.fragment(style_tag))
            end
          else
            doc.inner_html = style_tag += doc.inner_html
          end
        end
        doc
      end
def write_unmergable_css_rules ( doc , unmergable_rules ) styles = '' unmergable_rules . each_selector ( :all , :force_important => true ) do | selector , declarations , specificity | styles += "#{selector} { #{declarations} }\n" end unless styles . empty? style_tag = "<style type=\"text/css\">\n#{styles}></style>" if head = doc . search ( 'head' ) doc . at_css ( 'head' ) . add_child ( :: Nokogiri :: XML . fragment ( style_tag ) ) elsif body = doc . search ( 'body' ) if doc . at_css ( 'body' ) . children && ! doc . at_css ( 'body' ) . children . empty? doc . at_css ( 'body' ) . children . before ( :: Nokogiri :: XML . fragment ( style_tag ) ) else doc . at_css ( 'body' ) . add_child ( :: Nokogiri :: XML . fragment ( style_tag ) ) end else doc . inner_html = style_tag += doc . inner_html end end doc end
Create a <tt>style</tt> element with un-mergable rules (e.g.
Create a <tt > style< / tt > element with un - mergable rules ( e . g .
# :nodoc:
None
::Nokogiri::XML
doc
<not_specific>
unmergable_rules
<not_specific>