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, except for having the attribute itself removed.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dom, normal_asset_provider, external_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)
  • normal_asset_provider (#find_stylesheet!)
  • external_asset_provider (#find_stylesheet!)


18
19
20
21
22
# File 'lib/roadie/asset_scanner.rb', line 18

def initialize(dom, normal_asset_provider, external_asset_provider)
  @dom = dom
  @normal_asset_provider = normal_asset_provider
  @external_asset_provider = external_asset_provider
end

Instance Attribute Details

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



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

def dom
  @dom
end

#external_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.



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

def external_asset_provider
  @external_asset_provider
end

#normal_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.



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

def normal_asset_provider
  @normal_asset_provider
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:



45
46
47
48
49
50
51
# File 'lib/roadie/asset_scanner.rb', line 45

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:



32
33
34
# File 'lib/roadie/asset_scanner.rb', line 32

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