Class: Jekyll::Gzip::Compressor
- Inherits:
-
Object
- Object
- Jekyll::Gzip::Compressor
- Defined in:
- lib/jekyll/gzip/compressor.rb
Constant Summary collapse
- ZIPPABLE_EXTENSIONS =
[ '.html', '.css', '.js', '.txt', '.ttf', '.atom', '.stl', '.xml', '.svg', '.eot' ]
Instance Attribute Summary collapse
-
#site ⇒ Object
readonly
Returns the value of attribute site.
Instance Method Summary collapse
- #compress ⇒ Object
- #compress_file(file_name) ⇒ Object
-
#initialize(site) ⇒ Compressor
constructor
A new instance of Compressor.
Constructor Details
#initialize(site) ⇒ Compressor
Returns a new instance of Compressor.
21 22 23 |
# File 'lib/jekyll/gzip/compressor.rb', line 21 def initialize(site) @site = site end |
Instance Attribute Details
#site ⇒ Object (readonly)
Returns the value of attribute site.
19 20 21 |
# File 'lib/jekyll/gzip/compressor.rb', line 19 def site @site end |
Instance Method Details
#compress ⇒ Object
35 36 37 38 39 |
# File 'lib/jekyll/gzip/compressor.rb', line 35 def compress site.each_site_file do |file| compress_file(file.destination(site.dest)) end end |
#compress_file(file_name) ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/jekyll/gzip/compressor.rb', line 25 def compress_file(file_name) return unless ZIPPABLE_EXTENSIONS.include?(File.extname(file_name)) zipped = "#{file_name}.gz" Zlib::GzipWriter.open(zipped, Zlib::BEST_COMPRESSION) do |gz| gz.mtime = File.mtime(file_name) gz.orig_name = file_name gz.write IO.binread(file_name) end end |