Class: Sprockets::ExportersPack::BrotliExporter
- Inherits:
-
Sprockets::Exporters::Base
- Object
- Sprockets::Exporters::Base
- Sprockets::ExportersPack::BrotliExporter
- Defined in:
- lib/sprockets/exporters_pack/brotli_exporter.rb
Class Attribute Summary collapse
Instance Method Summary collapse
Class Attribute Details
.font_regex ⇒ Object
47 48 49 |
# File 'lib/sprockets/exporters_pack/brotli_exporter.rb', line 47 def font_regex @font_regex || /font|otf/ end |
.quality ⇒ Object
43 44 45 |
# File 'lib/sprockets/exporters_pack/brotli_exporter.rb', line 43 def quality @quality || 9 end |
.text_regex ⇒ Object
51 52 53 |
# File 'lib/sprockets/exporters_pack/brotli_exporter.rb', line 51 def text_regex @text_regex || /text|(application\/(javascript|json|xml))/ end |
Instance Method Details
#call ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/sprockets/exporters_pack/brotli_exporter.rb', line 21 def call data = File.binread(target) mode = if asset.content_type.match self.class.font_regex :font elsif asset.content_type.match self.class.text_regex :text else :generic end brotli = Brotli.deflate(data, mode: mode, quality: self.class.quality) write(@brotli_target) do |file| file.write(brotli) file.close end end |
#setup ⇒ Object
7 8 9 |
# File 'lib/sprockets/exporters_pack/brotli_exporter.rb', line 7 def setup @brotli_target = "#{ target }.br" end |
#skip?(logger) ⇒ Boolean
11 12 13 14 15 16 17 18 19 |
# File 'lib/sprockets/exporters_pack/brotli_exporter.rb', line 11 def skip?(logger) if ::File.exist?(@brotli_target) logger.debug "Skipping #{ @brotli_target }, already exists" true else logger.info "Writing #{ @brotli_target }" false end end |