Module: Premailer::Rails::CSSLoaders::PropshaftLoader

Extended by:
PropshaftLoader
Included in:
PropshaftLoader
Defined in:
lib/premailer/rails/css_loaders/propshaft_loader.rb

Instance Method Summary collapse

Instance Method Details

#file_name(url) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/premailer/rails/css_loaders/propshaft_loader.rb', line 15

def file_name(url)
  prefix = File.join(
    ::Rails.configuration.relative_url_root.to_s,
    ::Rails.configuration.assets.prefix.to_s,
    '/'
  )
  URI(url).path
    .sub(/\A#{prefix}/, '')
    .sub(/-(\h{40})\.css\z/, '.css')
end

#load(url) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/premailer/rails/css_loaders/propshaft_loader.rb', line 7

def load(url)
  return unless propshaft_present?

  file = file_name(url)
  asset = ::Rails.application.assets.load_path.find(file)
  ::Rails.application.assets.compilers.compile(asset) if asset
end

#propshaft_present?Boolean

Returns:

  • (Boolean)


26
27
28
29
# File 'lib/premailer/rails/css_loaders/propshaft_loader.rb', line 26

def propshaft_present?
  defined?(::Rails) &&
    ::Rails.try(:application).try(:assets).class.name == "Propshaft::Assembly"
end