Module: Propshaft::Compressor

Defined in:
lib/propshaft/compressor.rb,
lib/propshaft/compressor/writer.rb,
lib/propshaft/compressor/railtie.rb,
lib/propshaft/compressor/version.rb
more...

Defined Under Namespace

Modules: ZstdStreamWriterPatch Classes: BrotliWriter, GzipWriter, Railtie, Writer, ZstdWriter

Constant Summary collapse

SKIP_EXTS =
%w(jpg mp3 mp4 png webp woff woff2)
FORMATS =

{ ‘.ext’ => [GzipWriter, 9] }

{}
VERSION =
'0.2.0'

Class Method Summary collapse

Class Method Details

.compress_assets(processor) ⇒ Object

[View source]

17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/propshaft/compressor.rb', line 17

def self.compress_assets(processor)
  processor.load_path.assets.each do |asset|
    in_path = processor.output_path.join(asset.digested_path).to_s
    next if SKIP_EXTS.any?{|ext| in_path.ends_with? ".#{ext}" }

    FORMATS.each do |ext, (klass, level)|
      out_path = processor.output_path.join(asset.digested_path.to_s+ext)
      unless out_path.exist?
        Propshaft.logger.info "Writing #{asset.digested_path}#{ext}"
        klass.compress from: in_path, to: out_path, level: level
      end
    end
  end
end