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(keep_extra_blocks = true) ⇒ 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:

  • keep_extra_blocks (true, false) (defaults to: true)

Returns:

  • (nil)


29
30
31
32
33
34
35
36
# File 'lib/roadie/inliner.rb', line 29

def inline(keep_extra_blocks = true)
  style_map, extra_blocks = consume_stylesheets

  apply_style_map(style_map)
  add_styles_to_head(extra_blocks) if keep_extra_blocks

  nil
end