route_downcaser 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -1,6 +1,6 @@
1
1
  = RouteDowncaser
2
2
 
3
- Makes routing in Rails case-insensitive
3
+ Makes routing in Rails case-insensitive (and other Rack-servers like Sinatra)
4
4
 
5
5
  This gem hooks into the Rack middleware of Rails. This way all paths are downcased before dispatching to Rails' routing mechanism. Querystring parameters are not changed in any way.
6
6
 
@@ -8,10 +8,14 @@ This gem hooks into the Rack middleware of Rails. This way all paths are downcas
8
8
 
9
9
  == Requirements
10
10
 
11
- This gem is only made to be used from Rails 3.0 and up. If you want this functionality in a Rails 2.x application, please refer to {this blog post}[http://gehling.dk/2010/02/how-to-make-rails-routing-case-insensitive].
11
+ This gem has been tested with Rails 3.+ and Sinatra
12
+
13
+ If you want this functionality in a Rails 2.x application, please refer to {this blog post}[http://gehling.dk/2010/02/how-to-make-rails-routing-case-insensitive].
12
14
 
13
15
  == Installing
14
16
 
17
+ === Rails
18
+
15
19
  Just add the gem to your gemfile and run bundle
16
20
 
17
21
  gem 'route_downcaser'
@@ -29,6 +33,29 @@ If you have a controller named app/controllers/foo_controller.rb and the action
29
33
 
30
34
  All the above are valid.
31
35
 
36
+ === Sinatra
37
+
38
+ In your Gemfile you add the gem:
39
+
40
+ gem 'route_downcaser'
41
+
42
+ In your application.rb you add the following (after loading Sinatra)
43
+
44
+ require 'route_downcaser'
45
+ use RouteDowncaser::DowncaseRouteMiddleware
46
+
47
+ Now this statement
48
+
49
+ get '/foo' do
50
+ "Hello"
51
+ end
52
+
53
+ will respond to all these requests:
54
+
55
+ http://localhost:4567/foo
56
+ http://localhost:4567/Foo
57
+ http://localhost:4567/FOO
58
+
32
59
  == Background information
33
60
 
34
61
  Sometimes you may wish to market a url which contains a controller name - like www.myshop.com/specialoffer. If this is done on offline media it will cause potential customers trouble, if they don't use the correct casing. If, for some reason, the user types www.myshop.com/Specialoffer (with capital S), your Rails app will return a 404 not found.
@@ -11,7 +11,10 @@ module RouteDowncaser
11
11
  env['REQUEST_URI'] = uri_items.join('?')
12
12
  end
13
13
 
14
- if env['PATH_INFO']
14
+ if env['PATH_INFO'] =~ /assets\//i
15
+ pieces = env['PATH_INFO'].split('/')
16
+ env['PATH_INFO'] = pieces.slice(0..-2).join('/').downcase + '/' + pieces.last
17
+ elsif env['PATH_INFO']
15
18
  env['PATH_INFO'] = env['PATH_INFO'].downcase
16
19
  end
17
20
 
@@ -1,3 +1,3 @@
1
1
  module RouteDowncaser
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -173,3 +173,7 @@ Started GET "/HELLO/WORLD" for 127.0.0.1 at 2013-01-17 12:58:26 +0100
173
173
  Processing by HelloController#world as HTML
174
174
  Rendered text template (0.0ms)
175
175
  Completed 200 OK in 52ms (Views: 51.5ms)
176
+ Started GET "/HELLO/WORLD" for 127.0.0.1 at 2013-02-16 14:33:16 +0100
177
+ Processing by HelloController#world as HTML
178
+ Rendered text template (0.0ms)
179
+ Completed 200 OK in 15ms (Views: 14.6ms)
@@ -32,4 +32,12 @@ class RouteDowncaserTest < ActiveSupport::TestCase
32
32
 
33
33
  assert_equal("hello/world", app.env['PATH_INFO'])
34
34
  end
35
+
36
+ test "asset filenames are not touched" do
37
+ app = MockApp.new
38
+ env = { 'PATH_INFO' => "ASSETS/IMAges/SpaceCat.jpeg" }
39
+ RouteDowncaser::DowncaseRouteMiddleware.new(app).call(env)
40
+
41
+ assert_equal("assets/images/SpaceCat.jpeg", app.env['PATH_INFO'])
42
+ end
35
43
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: route_downcaser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
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: 2013-01-18 00:00:00.000000000 Z
12
+ date: 2013-02-16 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: This gem hooks into the Rack middleware of Rails. This way all paths
15
15
  are downcased before dispatching to Rails' routing mechanism. Querystring parameters
@@ -20,46 +20,47 @@ executables: []
20
20
  extensions: []
21
21
  extra_rdoc_files: []
22
22
  files:
23
- - lib/route_downcaser/railtie.rb
24
23
  - lib/route_downcaser/downcase_route_middleware.rb
25
24
  - lib/route_downcaser/version.rb
25
+ - lib/route_downcaser/railtie.rb
26
26
  - lib/route_downcaser.rb
27
27
  - lib/tasks/route_downcaser_tasks.rake
28
28
  - MIT-LICENSE
29
29
  - Rakefile
30
30
  - README.rdoc
31
- - test/dummy/Rakefile
32
31
  - test/dummy/log/test.log
33
- - test/dummy/public/404.html
32
+ - test/dummy/public/500.html
34
33
  - test/dummy/public/favicon.ico
35
34
  - test/dummy/public/422.html
36
- - test/dummy/public/500.html
35
+ - test/dummy/public/404.html
36
+ - test/dummy/config/locales/en.yml
37
37
  - test/dummy/config/database.yml
38
- - test/dummy/config/environments/development.rb
38
+ - test/dummy/config/environment.rb
39
39
  - test/dummy/config/environments/production.rb
40
40
  - test/dummy/config/environments/test.rb
41
- - test/dummy/config/boot.rb
42
- - test/dummy/config/environment.rb
41
+ - test/dummy/config/environments/development.rb
43
42
  - test/dummy/config/routes.rb
44
- - test/dummy/config/locales/en.yml
45
- - test/dummy/config/initializers/wrap_parameters.rb
46
43
  - test/dummy/config/initializers/backtrace_silencers.rb
47
- - test/dummy/config/initializers/session_store.rb
48
44
  - test/dummy/config/initializers/inflections.rb
49
- - test/dummy/config/initializers/secret_token.rb
45
+ - test/dummy/config/initializers/session_store.rb
50
46
  - test/dummy/config/initializers/mime_types.rb
47
+ - test/dummy/config/initializers/wrap_parameters.rb
48
+ - test/dummy/config/initializers/secret_token.rb
49
+ - test/dummy/config/boot.rb
51
50
  - test/dummy/config/application.rb
52
- - test/dummy/app/assets/javascripts/application.js
53
- - test/dummy/app/assets/stylesheets/application.css
51
+ - test/dummy/Rakefile
54
52
  - test/dummy/app/helpers/application_helper.rb
55
53
  - test/dummy/app/views/layouts/application.html.erb
56
- - test/dummy/app/controllers/application_controller.rb
57
54
  - test/dummy/app/controllers/hello_controller.rb
58
- - test/dummy/script/rails
55
+ - test/dummy/app/controllers/application_controller.rb
56
+ - test/dummy/app/assets/images/SpaceCat.jpeg
57
+ - test/dummy/app/assets/javascripts/application.js
58
+ - test/dummy/app/assets/stylesheets/application.css
59
59
  - test/dummy/config.ru
60
- - test/test_helper.rb
60
+ - test/dummy/script/rails
61
61
  - test/integration/route_middleware_test.rb
62
62
  - test/route_downcaser_test.rb
63
+ - test/test_helper.rb
63
64
  homepage: https://github.com/carstengehling/route_downcaser
64
65
  licenses: []
65
66
  post_install_message:
@@ -74,7 +75,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
74
75
  version: '0'
75
76
  segments:
76
77
  - 0
77
- hash: 3944866067154632745
78
+ hash: -390555247668935241
78
79
  required_rubygems_version: !ruby/object:Gem::Requirement
79
80
  none: false
80
81
  requirements:
@@ -83,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
84
  version: '0'
84
85
  segments:
85
86
  - 0
86
- hash: 3944866067154632745
87
+ hash: -390555247668935241
87
88
  requirements: []
88
89
  rubyforge_project:
89
90
  rubygems_version: 1.8.24
@@ -91,35 +92,36 @@ signing_key:
91
92
  specification_version: 3
92
93
  summary: Makes routing in Rails case-insensitive
93
94
  test_files:
94
- - test/dummy/Rakefile
95
95
  - test/dummy/log/test.log
96
- - test/dummy/public/404.html
96
+ - test/dummy/public/500.html
97
97
  - test/dummy/public/favicon.ico
98
98
  - test/dummy/public/422.html
99
- - test/dummy/public/500.html
99
+ - test/dummy/public/404.html
100
+ - test/dummy/config/locales/en.yml
100
101
  - test/dummy/config/database.yml
101
- - test/dummy/config/environments/development.rb
102
+ - test/dummy/config/environment.rb
102
103
  - test/dummy/config/environments/production.rb
103
104
  - test/dummy/config/environments/test.rb
104
- - test/dummy/config/boot.rb
105
- - test/dummy/config/environment.rb
105
+ - test/dummy/config/environments/development.rb
106
106
  - test/dummy/config/routes.rb
107
- - test/dummy/config/locales/en.yml
108
- - test/dummy/config/initializers/wrap_parameters.rb
109
107
  - test/dummy/config/initializers/backtrace_silencers.rb
110
- - test/dummy/config/initializers/session_store.rb
111
108
  - test/dummy/config/initializers/inflections.rb
112
- - test/dummy/config/initializers/secret_token.rb
109
+ - test/dummy/config/initializers/session_store.rb
113
110
  - test/dummy/config/initializers/mime_types.rb
111
+ - test/dummy/config/initializers/wrap_parameters.rb
112
+ - test/dummy/config/initializers/secret_token.rb
113
+ - test/dummy/config/boot.rb
114
114
  - test/dummy/config/application.rb
115
- - test/dummy/app/assets/javascripts/application.js
116
- - test/dummy/app/assets/stylesheets/application.css
115
+ - test/dummy/Rakefile
117
116
  - test/dummy/app/helpers/application_helper.rb
118
117
  - test/dummy/app/views/layouts/application.html.erb
119
- - test/dummy/app/controllers/application_controller.rb
120
118
  - test/dummy/app/controllers/hello_controller.rb
121
- - test/dummy/script/rails
119
+ - test/dummy/app/controllers/application_controller.rb
120
+ - test/dummy/app/assets/images/SpaceCat.jpeg
121
+ - test/dummy/app/assets/javascripts/application.js
122
+ - test/dummy/app/assets/stylesheets/application.css
122
123
  - test/dummy/config.ru
123
- - test/test_helper.rb
124
+ - test/dummy/script/rails
124
125
  - test/integration/route_middleware_test.rb
125
126
  - test/route_downcaser_test.rb
127
+ - test/test_helper.rb