rack-combobot 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,2 +1,3 @@
1
1
  .DS_Store
2
2
  *.gem
3
+ Gemfile.lock
data/README.md CHANGED
@@ -31,10 +31,14 @@ config.middleware.use 'Rack::Combobot', :root => "#{Rails.root}/public"
31
31
 
32
32
  ### Expires header
33
33
 
34
- Add expires header by like so
34
+ Add expires header
35
35
 
36
36
  ```ruby
37
37
  config.middleware.use 'Rack::Combobot', :root => "#{Rails.root}/public", :expires => Time.gm(2020)
38
38
  ```
39
39
 
40
40
  To bust the cache, simple add a unique string to your request like so `/combobot/BUSTINGSRING?script1.js&script2.js`.
41
+
42
+ ### Without query string
43
+
44
+ If you environment doesn't allow having the file names in the query string (Like on CloudFront). Combobot will accept the file names as part of the url, but they have to start with `&`.
@@ -24,16 +24,17 @@ module Rack
24
24
 
25
25
  # rack request handler
26
26
  def call(env)
27
- if Rack::Request.new(env).path =~ /^\/combobot/
28
- combine(env)
27
+ request = Rack::Request.new(env)
28
+
29
+ if request.path =~ /^\/combobot/
30
+ combine(request)
29
31
  else
30
32
  @app.call(env)
31
33
  end
32
34
  end
33
35
 
34
- def combine(env)
35
- params = env["QUERY_STRING"]
36
- file_names = params.split("&")
36
+ def combine(request)
37
+ file_names = extract_file_names_from_request(request)
37
38
 
38
39
  return not_found if file_names.empty?
39
40
 
@@ -48,6 +49,20 @@ module Rack
48
49
  end
49
50
  end
50
51
 
52
+ def extract_file_names_from_request(request)
53
+ path = request.path
54
+ file_names = request.query_string
55
+
56
+ if file_names == '' && path =~ /.js|.css/
57
+ file_names = path.split('&')
58
+ file_names.slice!(0)
59
+ else
60
+ file_names = file_names.split("&")
61
+ end
62
+
63
+ file_names
64
+ end
65
+
51
66
  def create_headers(extension)
52
67
  headers = {"Content-Type" => MIME_TYPES[extension]}
53
68
 
@@ -4,7 +4,7 @@ $:.push File.expand_path("../lib", __FILE__)
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "rack-combobot"
7
- s.version = "0.2.1"
7
+ s.version = "0.2.2"
8
8
  s.authors = ["Simon Højberg", "Christopher Meiklejohn"]
9
9
  s.email = ["r.hackr@gmail.com", "christopher.meiklejohn@gmail.com"]
10
10
  s.homepage = "https://github.com/hojberg/rack-combobot"
@@ -12,7 +12,9 @@ describe Rack::Combobot do
12
12
  end
13
13
 
14
14
  # request helpers
15
- let(:combobot_request) { { 'PATH_INFO' => '/combobot' } }
15
+ let(:combobot_request) { { 'PATH_INFO' => '/combobot' } }
16
+ let(:no_querystring_request) { { 'PATH_INFO' => '/combobot/&js1.js&js2.js' } }
17
+ let(:no_querystring_request_with_slash) { { 'PATH_INFO' => '/combobot/cachebuster/&subdir/js1.js&subdir/js2.js' } }
16
18
  let(:combobot_js_request) { combobot_request.merge({ "QUERY_STRING" => "js1.js&js2.js" }) }
17
19
  let(:combobot_css_request) { combobot_request.merge({ "QUERY_STRING" => "css1.css&css2.css" }) }
18
20
  let(:combobot_404_request) { combobot_request.merge({ "QUERY_STRING" => "js3.js&js4.js" }) }
@@ -40,6 +42,16 @@ describe Rack::Combobot do
40
42
  it "combines css" do
41
43
  @app.call(combobot_css_request).must_equal(combobot_css_response)
42
44
  end
45
+
46
+ describe 'without query string' do
47
+ it "combines javascript" do
48
+ @app.call(no_querystring_request).must_equal(combobot_js_response)
49
+ end
50
+
51
+ it 'combines without / in file names' do
52
+ @app.call(no_querystring_request_with_slash).must_equal(combobot_js_response)
53
+ end
54
+ end
43
55
  end
44
56
 
45
57
  describe 'error handling' do
@@ -0,0 +1 @@
1
+ function lorem() { return "a"; }
@@ -0,0 +1 @@
1
+ function ipsum() { return "b"; }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-combobot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-03-22 00:00:00.000000000 Z
13
+ date: 2012-05-02 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake
17
- requirement: &2168961680 !ruby/object:Gem::Requirement
17
+ requirement: &2152864840 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: '0'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *2168961680
25
+ version_requirements: *2152864840
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: rack
28
- requirement: &2168961240 !ruby/object:Gem::Requirement
28
+ requirement: &2152864400 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *2168961240
36
+ version_requirements: *2152864400
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: minitest
39
- requirement: &2168960820 !ruby/object:Gem::Requirement
39
+ requirement: &2152863980 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ! '>='
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: '0'
45
45
  type: :development
46
46
  prerelease: false
47
- version_requirements: *2168960820
47
+ version_requirements: *2152863980
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: rack-test
50
- requirement: &2168960400 !ruby/object:Gem::Requirement
50
+ requirement: &2152863560 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ! '>='
@@ -55,10 +55,10 @@ dependencies:
55
55
  version: '0'
56
56
  type: :development
57
57
  prerelease: false
58
- version_requirements: *2168960400
58
+ version_requirements: *2152863560
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: guard
61
- requirement: &2168959980 !ruby/object:Gem::Requirement
61
+ requirement: &2152863140 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
64
  - - ! '>='
@@ -66,10 +66,10 @@ dependencies:
66
66
  version: '0'
67
67
  type: :development
68
68
  prerelease: false
69
- version_requirements: *2168959980
69
+ version_requirements: *2152863140
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: guard-minitest
72
- requirement: &2168959560 !ruby/object:Gem::Requirement
72
+ requirement: &2152862720 !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
75
  - - ! '>='
@@ -77,7 +77,7 @@ dependencies:
77
77
  version: '0'
78
78
  type: :development
79
79
  prerelease: false
80
- version_requirements: *2168959560
80
+ version_requirements: *2152862720
81
81
  description: combines assets to server 1 file
82
82
  email:
83
83
  - r.hackr@gmail.com
@@ -90,7 +90,6 @@ files:
90
90
  - .rbenv-version
91
91
  - .travis.yml
92
92
  - Gemfile
93
- - Gemfile.lock
94
93
  - Guardfile
95
94
  - README.md
96
95
  - Rakefile
@@ -106,6 +105,8 @@ files:
106
105
  - spec/public/css2.css
107
106
  - spec/public/js1.js
108
107
  - spec/public/js2.js
108
+ - spec/public/subdir/js1.js
109
+ - spec/public/subdir/js2.js
109
110
  - spec/spec_helper.rb
110
111
  homepage: https://github.com/hojberg/rack-combobot
111
112
  licenses: []
@@ -138,4 +139,6 @@ test_files:
138
139
  - spec/public/css2.css
139
140
  - spec/public/js1.js
140
141
  - spec/public/js2.js
142
+ - spec/public/subdir/js1.js
143
+ - spec/public/subdir/js2.js
141
144
  - spec/spec_helper.rb
@@ -1,32 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- rack-combobot (0.2.0)
5
- rack
6
- rake
7
-
8
- GEM
9
- remote: http://rubygems.org/
10
- specs:
11
- ffi (1.0.11)
12
- guard (0.10.0)
13
- ffi (>= 0.5.0)
14
- thor (~> 0.14.6)
15
- guard-minitest (0.5.0)
16
- guard (~> 0.4)
17
- minitest (2.10.0)
18
- rack (1.4.0)
19
- rack-test (0.6.1)
20
- rack (>= 1.0)
21
- rake (0.9.2.2)
22
- thor (0.14.6)
23
-
24
- PLATFORMS
25
- ruby
26
-
27
- DEPENDENCIES
28
- guard
29
- guard-minitest
30
- minitest
31
- rack-combobot!
32
- rack-test