rack-zippy 2.0.2 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 3.0.0 / 2015-04-18
2
+ - Make static extensions list configurable ([#45](https://github.com/eliotsykes/rack-zippy/pull/45/files)) Anton Petrunich
3
+
1
4
  ## 2.0.2 / 2014-12-15
2
5
  - Remove binstub bin/rake permanently, may be causing Heroku issues
3
6
 
data/README.md CHANGED
@@ -85,6 +85,21 @@ Any files given the `max_age_fallback` would have the following `Cache-Control`
85
85
  Cache-Control: public, max-age=600
86
86
  ```
87
87
 
88
+ ### Configuration
89
+
90
+ #### static_extensions
91
+
92
+ rack-zippy handles only files with whitelisted extensions. Default extensions list:
93
+ `css js html htm txt ico png jpg jpeg gif pdf svg zip gz eps psd ai woff woff2 ttf eot otf swf`
94
+
95
+ You can modify this list:
96
+
97
+ ```ruby
98
+ Rack::Zippy.configure do |config|
99
+ config.static_extensions << 'csv'
100
+ end
101
+ ```
102
+
88
103
  ## Troubleshooting
89
104
 
90
105
  ##### 'assert_index': No such middleware to insert before: ActionDispatch::Static (RuntimeError)
@@ -139,13 +154,14 @@ Cleanup time! When you’re finished testing, delete the local override and set
139
154
  - Eliot Sykes https://eliotsykes.com
140
155
  - Kieran Topping https://github.com/ktopping
141
156
  - Luke Wendling https://github.com/lukewendling
142
-
157
+ - Anton Petrunich https://github.com/solenko
143
158
 
144
159
  ## Releasing a new gem
145
160
 
146
161
  1. Update pre-release version to the release version in `lib/rack-zippy/version.rb`, e.g. `1.0.1.pre` becomes `1.0.1`
147
162
  2. Update `CHANGELOG.md` version and date. Update Contributors in `README.md`.
148
163
  3. Tests pass? (`rake test`)
164
+ 4. Commit and push changes to origin.
149
165
  4. Build the gem (`rake build`)
150
166
  5. Release on rubygems.org (`rake release`)
151
167
  6. Update version to the next pre-release version in `lib/rack-zippy/version.rb`, e.g. `1.0.1` becomes `1.0.2.pre`.
data/lib/rack-zippy.rb CHANGED
@@ -1,17 +1,18 @@
1
1
  require 'rack-zippy/version'
2
2
  require 'rack-zippy/asset_compiler'
3
3
  require 'rack-zippy/serveable_file'
4
+ require 'rack-zippy/configuration'
4
5
 
5
6
  module Rack
6
7
  module Zippy
8
+ extend Configuration
9
+
10
+ define_setting :static_extensions, %w(css js html htm txt ico png jpg jpeg gif pdf svg zip gz eps psd ai woff woff2 ttf eot otf swf)
7
11
 
8
12
  PRECOMPILED_ASSETS_SUBDIR_REGEX = /\A\/assets(?:\/|\z)/
9
13
 
10
14
  class AssetServer
11
15
 
12
- # Font extensions: woff, woff2, ttf, eot, otf
13
- STATIC_EXTENSION_REGEX = /\.(?:css|js|html|htm|txt|ico|png|jpg|jpeg|gif|pdf|svg|zip|gz|eps|psd|ai|woff|woff2|ttf|eot|otf|swf)\z/i
14
-
15
16
  HTTP_STATUS_CODE_OK = 200
16
17
 
17
18
  def initialize(app, asset_root=nil, options={})
@@ -46,6 +47,7 @@ module Rack
46
47
 
47
48
  serveable_file = ServeableFile.find_first(serveable_file_options)
48
49
 
50
+
49
51
  if serveable_file
50
52
  return [HTTP_STATUS_CODE_OK, serveable_file.headers, serveable_file.response_body]
51
53
  end
@@ -0,0 +1,37 @@
1
+ module Rack
2
+ module Zippy
3
+ module Configuration
4
+ def configure
5
+ yield self
6
+ end
7
+
8
+ def define_setting(name, default = nil)
9
+ default_copy = begin
10
+ default.dup
11
+ rescue TypeError
12
+ default
13
+ end
14
+ class_variable_set("@@#{name}", default_copy)
15
+
16
+ define_class_method "#{name}=" do |value|
17
+ class_variable_set("@@#{name}", value)
18
+ end
19
+ define_class_method name do
20
+ class_variable_get("@@#{name}")
21
+ end
22
+ define_class_method "reset_#{name}" do
23
+ class_variable_set("@@#{name}", default)
24
+ end
25
+ end
26
+
27
+ private
28
+
29
+ def define_class_method(name, &block)
30
+ (class << self; self; end).instance_eval do
31
+ define_method name, &block
32
+ end
33
+ end
34
+
35
+ end
36
+ end
37
+ end
@@ -94,7 +94,7 @@ module Rack
94
94
  end
95
95
 
96
96
  def self.has_static_extension?(path)
97
- path =~ AssetServer::STATIC_EXTENSION_REGEX
97
+ Rack::Zippy.static_extensions.include? ::File.extname(path).slice(1..-1).to_s.downcase
98
98
  end
99
99
 
100
100
  def encoding_variants?
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  module Zippy
3
- VERSION = '2.0.2'
3
+ VERSION = '3.0.0'
4
4
  end
5
5
  end
@@ -39,10 +39,6 @@ module Rack
39
39
  assert_responds_with_html_file '', 'public/index.html'
40
40
  end
41
41
 
42
- def test_static_extension_regexp_available_in_established_constant_for_monkey_patching
43
- assert AssetServer.const_defined?(:STATIC_EXTENSION_REGEX)
44
- end
45
-
46
42
  def test_rails_asset_compiler_set_when_rails_environment_detected
47
43
  assert_equal RailsAssetCompiler, app.send(:asset_compiler).class
48
44
  end
@@ -346,4 +342,4 @@ module Rack
346
342
 
347
343
  end
348
344
  end
349
- end
345
+ end
@@ -0,0 +1,62 @@
1
+ require_relative 'test_helper'
2
+
3
+ module Rack
4
+ module Zippy
5
+ class ConfigurationTest < TestCase
6
+
7
+ def setup
8
+ Rack::Zippy.const_set(:ConfiguredClass, Class.new)
9
+ ConfiguredClass.extend Configuration
10
+ end
11
+
12
+ def teardown
13
+ Rack::Zippy.send(:remove_const, :ConfiguredClass)
14
+ end
15
+
16
+
17
+ def setting_name
18
+ 'test_setting'
19
+ end
20
+
21
+ def test_define_setting_create_setter_method
22
+ ConfiguredClass.define_setting setting_name
23
+ assert ConfiguredClass.respond_to? "#{setting_name}="
24
+ end
25
+
26
+ def test_define_setting_create_getter_method
27
+ ConfiguredClass.define_setting setting_name
28
+ assert ConfiguredClass.respond_to? setting_name
29
+ end
30
+
31
+ def test_define_setting_create_reset_method
32
+ ConfiguredClass.define_setting setting_name
33
+ assert ConfiguredClass.respond_to? "reset_#{setting_name}"
34
+ end
35
+
36
+ def test_define_setting_can_handle_not_clonable_default_values
37
+ ConfiguredClass.define_setting setting_name, :singleton_type_instance
38
+ assert_equal ConfiguredClass.test_setting, :singleton_type_instance
39
+ end
40
+
41
+ def test_reset_setting_to_default_value
42
+ ConfiguredClass.define_setting 'test_setting', 'default_value'
43
+ ConfiguredClass.test_setting = 'new_value'
44
+ ConfiguredClass.reset_test_setting
45
+ assert_equal ConfiguredClass.test_setting, 'default_value'
46
+ end
47
+
48
+ def test_setter_store_config_value
49
+ ConfiguredClass.define_setting 'test_setting', 'default_value'
50
+ ConfiguredClass.test_setting = 'new_value'
51
+ assert_equal ConfiguredClass.test_setting, 'new_value'
52
+ end
53
+
54
+ def test_reset_setting_if_default_value_passed_by_reference
55
+ ConfiguredClass.define_setting 'test_setting', [1]
56
+ ConfiguredClass.test_setting << 2
57
+ ConfiguredClass.reset_test_setting
58
+ assert_equal ConfiguredClass.test_setting, [1]
59
+ end
60
+ end
61
+ end
62
+ end
@@ -14,6 +14,7 @@ module Rack
14
14
 
15
15
  def teardown
16
16
  revert_to_original_working_directory
17
+ Rack::Zippy.reset_static_extensions
17
18
  end
18
19
 
19
20
  def test_day_long_cache_headers_for_root_html_requests
@@ -467,6 +468,12 @@ module Rack
467
468
  "Should handle flash .swf files"
468
469
  end
469
470
 
471
+ def test_has_static_extension_returns_true_for_configured_extension
472
+ Rack::Zippy.static_extensions << 'csv'
473
+ assert ServeableFile.has_static_extension?('/static-file.csv'),
474
+ "Should handle files with user configured extensions"
475
+ end
476
+
470
477
  private
471
478
 
472
479
  def assert_last_modified(headers, expected)
@@ -484,4 +491,4 @@ module Rack
484
491
 
485
492
  end
486
493
  end
487
- end
494
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-zippy
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 3.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-12-15 00:00:00.000000000 Z
12
+ date: 2015-04-18 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Rack middleware for serving static gzipped assets generated by the Rails
15
15
  asset pipeline
@@ -28,10 +28,12 @@ files:
28
28
  - Rakefile
29
29
  - lib/rack-zippy.rb
30
30
  - lib/rack-zippy/asset_compiler.rb
31
+ - lib/rack-zippy/configuration.rb
31
32
  - lib/rack-zippy/serveable_file.rb
32
33
  - lib/rack-zippy/version.rb
33
34
  - rack-zippy.gemspec
34
35
  - test/asset_server_test.rb
36
+ - test/configuration_test.rb
35
37
  - test/null_asset_compiler_test.rb
36
38
  - test/public/assets/application.css
37
39
  - test/public/assets/application.css.gz
@@ -65,7 +67,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
65
67
  version: '0'
66
68
  segments:
67
69
  - 0
68
- hash: 2483500908093930156
70
+ hash: -1760946869363206133
69
71
  required_rubygems_version: !ruby/object:Gem::Requirement
70
72
  none: false
71
73
  requirements:
@@ -74,7 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
74
76
  version: '0'
75
77
  segments:
76
78
  - 0
77
- hash: 2483500908093930156
79
+ hash: -1760946869363206133
78
80
  requirements: []
79
81
  rubyforge_project:
80
82
  rubygems_version: 1.8.23.2
@@ -84,6 +86,7 @@ summary: Rack middleware for serving static gzipped assets generated by the Rail
84
86
  asset pipeline
85
87
  test_files:
86
88
  - test/asset_server_test.rb
89
+ - test/configuration_test.rb
87
90
  - test/null_asset_compiler_test.rb
88
91
  - test/public/assets/application.css
89
92
  - test/public/assets/application.css.gz