Class: Roadie::Inliner Private

Inherits:
Object
  • Object
show all
Defined in:
lib/roadie/inliner.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

The Inliner inlines stylesheets to the elements of the DOM.

Inlining means that StyleBlocks and a DOM tree are combined:

a { color: red; } # StyleBlock
<a href="/"></a>  # DOM

becomes

<a href="/" style="color:red"></a>

Defined Under Namespace

Classes: StyleMap

Instance Method Summary collapse

Constructor Details

#initialize(stylesheets, dom) ⇒ Inliner

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Inliner.

Parameters:

  • stylesheets (Array<Stylesheet>)

    the stylesheets to use in the inlining

  • dom (Nokogiri::HTML::Document)


20
21
22
23
# File 'lib/roadie/inliner.rb', line 20

def initialize(stylesheets, dom)
  @stylesheets = stylesheets
  @dom = dom
end

Instance Method Details

#inline(options = {}) ⇒ nil

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Start the inlining, mutating the DOM tree.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :keep_uninlinable_css (true, false)
  • :keep_uninlinable_in (:root, :head)
  • :merge_media_queries (true, false)

Returns:

  • (nil)


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/roadie/inliner.rb', line 31

def inline(options = {})
  keep_uninlinable_css = options.fetch(:keep_uninlinable_css, true)
  keep_uninlinable_in = options.fetch(:keep_uninlinable_in, :head)
  merge_media_queries = options.fetch(:merge_media_queries, true)

  style_map, extra_blocks = consume_stylesheets

  apply_style_map(style_map)

  if keep_uninlinable_css
    add_uninlinable_styles(keep_uninlinable_in, extra_blocks, merge_media_queries)
  end

  nil
end