Class: Roadie::Rails::AssetPropshaftProvider

Inherits:
Object
  • Object
show all
Includes:
AssetProvider
Defined in:
lib/roadie/rails/asset_propshaft_provider.rb

Instance Method Summary collapse

Constructor Details

#initialize(assembly) ⇒ AssetPropshaftProvider

Returns a new instance of AssetPropshaftProvider.



8
9
10
11
# File 'lib/roadie/rails/asset_propshaft_provider.rb', line 8

def initialize(assembly)
  @assembly = assembly
  @stylesheets = {}
end

Instance Method Details

#find_stylesheet(stylesheet_asset_path) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/roadie/rails/asset_propshaft_provider.rb', line 13

def find_stylesheet(stylesheet_asset_path)
  stylesheet = @stylesheets[stylesheet_asset_path]
  return stylesheet if stylesheet.present?

  path, digest = extract_path_and_digest(stylesheet_asset_path)

  asset = @assembly.load_path.find(path)
  if asset.present? && asset.fresh?(digest)
    compiled_content = @assembly.compilers.compile(asset)

    stylesheet = Stylesheet.new(stylesheet_asset_path, compiled_content.force_encoding("UTF-8"))
    @stylesheets[stylesheet_asset_path] = stylesheet
  end

  stylesheet
end