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
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/premailer/rails/css_loaders/propshaft_loader.rb', line 16 def file_name(url) prefix = File.join( ::Rails.configuration.relative_url_root.to_s, ::Rails.configuration.assets.prefix.to_s, '/' ) # Path extraction logic from Propshaft. # See https://github.com/rails/propshaft/blob/390381548b125e8721c8aef1b9d894b7cc8bd868/lib/propshaft/server.rb#L35-L41 full_path = URI(url).path.sub(/\A#{prefix}/, '') digest = full_path[/-([0-9a-zA-Z]{7,128}(?:\.digested)?)\.[^.]+\z/, 1] path = digest ? full_path.sub("-#{digest}", "") : full_path path end |
#load(url) ⇒ Object
7 8 9 10 11 12 13 14 |
# 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
32 33 34 |
# File 'lib/premailer/rails/css_loaders/propshaft_loader.rb', line 32 def propshaft_present? defined?(::Propshaft) && defined?(::Rails) end |