class Roadie::Rails::AssetPropshaftProvider

Public Class Methods

new(assembly) click to toggle source
# File lib/roadie/rails/asset_propshaft_provider.rb, line 8
def initialize(assembly)
  @assembly = assembly
  @stylesheets = {}
end

Public Instance Methods

find_stylesheet(stylesheet_asset_path) click to toggle source
# 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

Private Instance Methods

extract_path_and_digest(stylesheet_asset_path) click to toggle source
# File lib/roadie/rails/asset_propshaft_provider.rb, line 32
def extract_path_and_digest(stylesheet_asset_path)
  full_path = stylesheet_asset_path.sub(%r{#{::Rails.configuration.assets.prefix}/}, "")
  digest = full_path[/-([0-9a-zA-Z]{7,128})\.(?!digested)[^.]+\z/, 1]
  path = digest ? full_path.sub("-#{digest}", "") : full_path

  [path, digest]
end