Module: CSSInliner

Defined in:
lib/css_inliner.rb,
lib/css_inliner/inliner.rb,
lib/css_inliner/version.rb,
lib/css_inliner/extractor.rb

Defined Under Namespace

Classes: CSSDocument, CSSDocumentHandler, Extractor, Inliner

Constant Summary collapse

VERSION =
"0.3.2"

Class Method Summary collapse

Class Method Details

.process(html, basedir = '.', element = nil, format = 'html') ⇒ String

Returns HTML source.

Parameters:

  • html (Nokogiri::XML::Document, String)
  • basedir (String) (defaults to: '.')

    Base directory or URI to traverse relative URI for images

  • element (String) (defaults to: nil)

    Element name to be returned. Returns whole document when nil

  • format (String) (defaults to: 'html')

    Format to output, html or xhtml

Returns:

  • (String)

    HTML source



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/css_inliner.rb', line 16

def process(html, basedir = '.', element = nil, format = 'html')
  doc = html.instance_of?(Nokogiri::XML::Document) ? html : Nokogiri.HTML(html)
  doc = Inliner.new(doc, basedir).inline
  doc = doc.css(element)[0] if element
  case format
  when 'xhtml'
    doc.to_xhtml
  when 'html'
    doc.to_html
  when 'xml'
    doc.to_xml
  else
    doc.to_s
  end
end