Class: Roadie::AssetScanner Private

Inherits:
Object
  • Object
show all
Defined in:
lib/roadie/asset_scanner.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 asset scanner’s main usage is finding and/or extracting styles from a DOM tree. Referenced styles will be found using the provided asset provider.

Any style declaration tagged with data-roadie-ignore will be ignored.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dom, asset_provider) ⇒ AssetScanner

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 AssetScanner.

Parameters:

  • dom (Nokogiri::HTML::Document)
  • asset_provider (#find_stylesheet!)


14
15
16
17
# File 'lib/roadie/asset_scanner.rb', line 14

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

Instance Attribute Details

#asset_providerObject (readonly)

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.



10
11
12
# File 'lib/roadie/asset_scanner.rb', line 10

def asset_provider
  @asset_provider
end

#domObject (readonly)

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.



10
11
12
# File 'lib/roadie/asset_scanner.rb', line 10

def dom
  @dom
end

Instance Method Details

#extract_cssEnumerable<Stylesheet>

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.

Looks for all non-ignored stylesheets, removes their references from the DOM and then returns them.

This will mutate the DOM tree.

The order of the array corresponds with the document order in the DOM.

Returns:

  • (Enumerable<Stylesheet>)

    every extracted stylesheet

See Also:



40
41
42
43
44
45
46
# File 'lib/roadie/asset_scanner.rb', line 40

def extract_css
  @dom.css(STYLE_ELEMENT_QUERY).map { |element|
    stylesheet = read_stylesheet(element)
    element.remove if stylesheet
    stylesheet
  }.compact
end

#find_cssEnumerable<Stylesheet>

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.

Looks for all non-ignored stylesheets and returns them.

This method will not mutate the DOM and is safe to call multiple times.

The order of the array corresponds with the document order in the DOM.

Returns:

  • (Enumerable<Stylesheet>)

    every found stylesheet

See Also:



27
28
29
# File 'lib/roadie/asset_scanner.rb', line 27

def find_css
  @dom.css(STYLE_ELEMENT_QUERY).map { |element| read_stylesheet(element) }.compact
end