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!)


16
17
18
19
20
# File 'lib/roadie/asset_scanner.rb', line 16

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.



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

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.



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

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.



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

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:



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

def extract_css
  stylesheets = @dom.css(STYLE_ELEMENT_QUERY).map { |element|
    stylesheet = read_stylesheet(element)
    element.remove if stylesheet
    stylesheet
  }.compact
  stylesheets
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:



30
31
32
# File 'lib/roadie/asset_scanner.rb', line 30

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