Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Refactor GZiping of assets

  • Loading branch information...
commit b875c1fd8f9a78673b02f677c976dc7d12600e01 1 parent 5628cd1
Aleksey V. Zapparov authored
24 README.md
Source Rendered
@@ -452,21 +452,14 @@ assets:
452 452 #
453 453 cachebust: hard
454 454 #
455   - # Saves gzipped versions of the assets next to the un-compressed files.
  455 + # Specifies list of MIME types that needs to have gzipped versions.
  456 + # You can set it to `false` to disable gzipping. Only javascripts and
  457 + # stylesheets are gzipped by default.
456 458 #
457   - gzip: true
  459 + gzip: [ text/css, application/javascript ]
458 460 ```
459 461
460 462
461   -## Contributing
462   -
463   -1. Fork it
464   -2. Create your feature branch (`git checkout -b my-new-feature`)
465   -3. Commit your changes (`git commit -am 'Added some feature'`)
466   -4. Push to the branch (`git push origin my-new-feature`)
467   -5. Create new Pull Request
468   -
469   -
470 463 ## "Th-th-th-that's all folks!"
471 464
472 465 Feel free to follow me on [twitter][twitter], chat via [jabber][jabber] or
@@ -477,6 +470,15 @@ write an [e-mail][e-mail]. :D
477 470 [e-mail]: mailto://ixti@member.fsf.org
478 471
479 472
  473 +## Contributing
  474 +
  475 +1. Fork it
  476 +2. Create your feature branch (`git checkout -b my-new-feature`)
  477 +3. Commit your changes (`git commit -am 'Added some feature'`)
  478 +4. Push to the branch (`git push origin my-new-feature`)
  479 +5. Create new Pull Request
  480 +
  481 +
480 482 ## License
481 483
482 484 Copyright (C) 2012 Aleksey V Zapparov (http://ixti.net/)
27 lib/jekyll/assets_plugin/asset_file.rb
... ... @@ -1,30 +1,39 @@
  1 +# stdlib
  2 +require "forwardable"
  3 +
  4 +
1 5 module Jekyll
2 6 module AssetsPlugin
3 7 class AssetFile
4 8
  9 + extend Forwardable
  10 +
  11 +
5 12 @@mtimes = Hash.new
6 13
7 14
8 15 attr_reader :asset
9 16
10 17
  18 + def_delegator :@site, :assets_config, :config
  19 + def_delegator :@asset, :content_type
  20 +
  21 +
11 22 def initialize site, asset
12 23 @site, @asset = site, asset
13 24 end
14 25
15 26
16 27 def destination dest
17   - File.join dest, @site.assets_config.dirname, filename
  28 + File.join dest, config.dirname, filename
18 29 end
19 30
20 31
21 32 def filename
22   - cachebust = @site.assets_config.cachebust
23   -
24   - case cachebust
  33 + case config.cachebust
25 34 when :none, :soft then asset.logical_path
26 35 when :hard then asset.digest_path
27   - else raise "Unknown cachebust strategy: #{cachebust.inspect}"
  36 + else raise "Unknown cachebust strategy: #{config.cachebust.inspect}"
28 37 end
29 38 end
30 39
@@ -51,7 +60,8 @@ def write dest
51 60 @@mtimes[path] = mtime
52 61
53 62 @asset.write_to dest_path
54   - @asset.write_to dest_path + '.gz' if @site.assets_config.gzip
  63 + @asset.write_to "#{dest_path}.gz" if gzip?
  64 +
55 65 true
56 66 end
57 67
@@ -65,6 +75,11 @@ def == other
65 75 end
66 76
67 77
  78 + def gzip?
  79 + config.gzip && config.gzip.include?(content_type)
  80 + end
  81 +
  82 +
68 83 def to_s
69 84 "#<Jekyll::AssetsPlugin::AssetFile:#{asset.logical_path}>"
70 85 end
7 lib/jekyll/assets_plugin/configuration.rb
@@ -10,7 +10,7 @@ class Configuration
10 10 :sources => %w{_assets/javascripts _assets/stylesheets _assets/images},
11 11 :compress => { :css => nil, :js => nil },
12 12 :cachebust => :hard,
13   - :gzip => true
  13 + :gzip => %w{ text/css application/javascript }
14 14 }.freeze
15 15
16 16
@@ -45,6 +45,11 @@ def cachebust
45 45 none?(@data.cachebust) ? :none : @data.cachebust.to_sym
46 46 end
47 47
  48 + def gzip
  49 + return @data.gzip if @data.gzip.is_a? Array
  50 + @data.gzip ? DEFAULTS[:gzip] : false
  51 + end
  52 +
48 53
49 54 def method_missing name, *args, &block
50 55 @data.send name, *args, &block
2  spec/lib/jekyll/assets_plugin/configuration_spec.rb
@@ -38,7 +38,7 @@ module Jekyll::AssetsPlugin
38 38
39 39 context "gzip" do
40 40 subject { config.gzip }
41   - it { should == true }
  41 + it { should =~ %w{ text/css application/javascript } }
42 42 end
43 43
44 44 end

0 comments on commit b875c1f

Please sign in to comment.
Something went wrong with that request. Please try again.