route_downcaser 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +15 -0
- data/README.rdoc +19 -1
- data/lib/configuration.rb +26 -0
- data/lib/route_downcaser/downcase_route_middleware.rb +31 -3
- data/lib/route_downcaser/version.rb +1 -1
- data/lib/route_downcaser.rb +4 -0
- data/test/dummy/log/test.log +8 -0
- data/test/integration/route_middleware_test.rb +5 -1
- data/test/route_downcaser_test.rb +13 -0
- metadata +32 -39
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ZmNmOWFjODRlN2U1ZDZjNzkwMzBmMGZiMDc5NTZhMWVmZjM2YTE4Zg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MmU0OTljZTQwZDE4ZjgxZjNkYmE5ZjI5ZWU3ZWM1YmYyZjc2NzY2MA==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
NjlhYWRiMWM5MzI2ZWJmYjdlZmYyZDZkMTgxMTc1NGNhMmRjNDI4ODA1MTJm
|
10
|
+
YWU0MDJmZWRiNDY5MjZkN2MzM2Q1NDI3ODA2NWYyZDljYjJmM2E1MmRiMWZk
|
11
|
+
M2ZkMDhkMGNmNTkyMzMxY2VhYmQ2ZWNlZjIwMDk0NzA0MTI5YWQ=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MDk0YTJmNTUwZGU4N2ZlZjc5NjVkMzZmMzNkODdlMGQyZmY1NjBhYzJiYTU2
|
14
|
+
ZDRhMDIyMzkxYzNmOWFmNDE4MGI1OTI3ZWY0NWI4MDE1YmJhNWIwMzQzOTk2
|
15
|
+
ODhmZTU3MDU3YjRiYjQxYzRjZWY4Nzk3YzA1OGZhNTU0OTQ1YWU=
|
data/README.rdoc
CHANGED
@@ -16,7 +16,7 @@ If you want this functionality in a Rails 2.x application, please refer to {this
|
|
16
16
|
|
17
17
|
=== Rails
|
18
18
|
|
19
|
-
Just add the gem to your gemfile and run bundle
|
19
|
+
Just add the gem to your gemfile and run bundle
|
20
20
|
|
21
21
|
gem 'route_downcaser'
|
22
22
|
|
@@ -74,8 +74,26 @@ At first I just made this code as a snippet and published it {on my blog}[http:/
|
|
74
74
|
|
75
75
|
All it really does is to take the path and downcase it before dispatching. Querystring parameters are NOT touched, they keep their casing, since it may have some contextual meaning.
|
76
76
|
|
77
|
+
== Configuration Options
|
78
|
+
|
79
|
+
Configuration options can be set using an initializer in your application like so:
|
80
|
+
|
81
|
+
# config/initializers/route_downcaser.rb
|
82
|
+
|
83
|
+
RouteDowncaser.configuration do |config|
|
84
|
+
config.redirect = true
|
85
|
+
end
|
86
|
+
|
87
|
+
=== Redirect
|
88
|
+
|
89
|
+
With this configuration option set to `true`, the middleware will 301 redirect all routes to their downcased version. Example: `http://localhost:3000/Foo` will redirect to `http://localhost:3000/foo`.
|
90
|
+
|
77
91
|
== Changelog
|
78
92
|
|
93
|
+
=== 0.2.2
|
94
|
+
|
95
|
+
Redirection is now possible as a configurable option. Thanks goes to {Mike Ackerman}[https://github.com/mackermedia]
|
96
|
+
|
79
97
|
=== 0.2.1
|
80
98
|
|
81
99
|
The gem has now been tested to work with Rails 4.0 (it mostly involved changes in the test dummy-app because of deprecations between Rails 3.2 and 4.0)
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Configuration
|
2
|
+
|
3
|
+
def configuration
|
4
|
+
yield self
|
5
|
+
end
|
6
|
+
|
7
|
+
def define_setting(name, default = nil)
|
8
|
+
class_variable_set("@@#{name}", default)
|
9
|
+
|
10
|
+
define_class_method "#{name}=" do |value|
|
11
|
+
class_variable_set("@@#{name}", value)
|
12
|
+
end
|
13
|
+
|
14
|
+
define_class_method name do
|
15
|
+
class_variable_get("@@#{name}")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def define_class_method(name, &block)
|
22
|
+
(class << self; self; end).instance_eval do
|
23
|
+
define_method name, &block
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -5,10 +5,16 @@ module RouteDowncaser
|
|
5
5
|
end
|
6
6
|
|
7
7
|
def call(env)
|
8
|
+
@env = env
|
9
|
+
|
8
10
|
if env['REQUEST_URI']
|
9
|
-
|
10
|
-
|
11
|
-
|
11
|
+
if RouteDowncaser.redirect == true
|
12
|
+
if path != path.downcase
|
13
|
+
return [301, {'Location' => downcased_uri, 'Content-Type' => 'text/html'}, []]
|
14
|
+
end
|
15
|
+
else
|
16
|
+
env['REQUEST_URI'] = downcased_uri
|
17
|
+
end
|
12
18
|
end
|
13
19
|
|
14
20
|
if env['PATH_INFO'] =~ /assets\//i
|
@@ -20,5 +26,27 @@ module RouteDowncaser
|
|
20
26
|
|
21
27
|
@app.call(env)
|
22
28
|
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def uri_items
|
33
|
+
@env['REQUEST_URI'].split('?')
|
34
|
+
end
|
35
|
+
|
36
|
+
def path
|
37
|
+
uri_items[0]
|
38
|
+
end
|
39
|
+
|
40
|
+
def query?
|
41
|
+
uri_items.length > 1
|
42
|
+
end
|
43
|
+
|
44
|
+
def downcased_uri
|
45
|
+
if query?
|
46
|
+
"#{path.downcase!}?#{uri_items[1]}"
|
47
|
+
else
|
48
|
+
path.downcase!
|
49
|
+
end
|
50
|
+
end
|
23
51
|
end
|
24
52
|
end
|
data/lib/route_downcaser.rb
CHANGED
data/test/dummy/log/test.log
CHANGED
@@ -237,3 +237,11 @@ Started GET "/HELLO/WORLD" for 127.0.0.1 at 2013-09-02 10:00:29 +0200
|
|
237
237
|
Processing by HelloController#world as HTML
|
238
238
|
Rendered text template (0.0ms)
|
239
239
|
Completed 200 OK in 47ms (Views: 45.9ms)
|
240
|
+
Started GET "/HELLO/WORLD" for 127.0.0.1 at 2014-12-19 18:53:00 +0100
|
241
|
+
Processing by HelloController#world as HTML
|
242
|
+
Rendered text template (0.0ms)
|
243
|
+
Completed 200 OK in 22.0ms (Views: 21.8ms)
|
244
|
+
Started GET "/HELLO/WORLD" for 127.0.0.1 at 2014-12-19 18:56:30 +0100
|
245
|
+
Processing by HelloController#world as HTML
|
246
|
+
Rendered text template (0.0ms)
|
247
|
+
Completed 200 OK in 6.2ms (Views: 5.9ms)
|
@@ -1,7 +1,11 @@
|
|
1
1
|
require 'test_helper'
|
2
|
-
|
2
|
+
|
3
3
|
class RouteMiddlewareTest < ActionDispatch::IntegrationTest
|
4
4
|
test "Middleware is installed and working" do
|
5
|
+
RouteDowncaser.configuration do |config|
|
6
|
+
config.redirect = false
|
7
|
+
end
|
8
|
+
|
5
9
|
get "HELLO/WORLD"
|
6
10
|
assert_response :success
|
7
11
|
assert_equal("anybody out there?", @response.body)
|
@@ -40,4 +40,17 @@ class RouteDowncaserTest < ActiveSupport::TestCase
|
|
40
40
|
|
41
41
|
assert_equal("assets/images/SpaceCat.jpeg", app.env['PATH_INFO'])
|
42
42
|
end
|
43
|
+
|
44
|
+
test "when redirect is set to true it redirects" do
|
45
|
+
app = MockApp.new
|
46
|
+
env = { 'REQUEST_URI' => "HELLO/WORLD" }
|
47
|
+
RouteDowncaser.configuration do |config|
|
48
|
+
config.redirect = true
|
49
|
+
end
|
50
|
+
|
51
|
+
assert_equal(
|
52
|
+
RouteDowncaser::DowncaseRouteMiddleware.new(app).call(env),
|
53
|
+
[301, {'Location' => "hello/world", 'Content-Type' => 'text/html'}, []]
|
54
|
+
)
|
55
|
+
end
|
43
56
|
end
|
metadata
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: route_downcaser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
5
|
-
prerelease:
|
4
|
+
version: 0.2.2
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Carsten Gehling
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-12-19 00:00:00.000000000 Z
|
13
12
|
dependencies: []
|
14
13
|
description: This gem hooks into the Rack middleware of Rails. This way all paths
|
15
14
|
are downcased before dispatching to Rails' routing mechanism. Querystring parameters
|
@@ -20,76 +19,70 @@ executables: []
|
|
20
19
|
extensions: []
|
21
20
|
extra_rdoc_files: []
|
22
21
|
files:
|
22
|
+
- MIT-LICENSE
|
23
|
+
- README.rdoc
|
24
|
+
- Rakefile
|
25
|
+
- lib/configuration.rb
|
26
|
+
- lib/route_downcaser.rb
|
23
27
|
- lib/route_downcaser/downcase_route_middleware.rb
|
24
|
-
- lib/route_downcaser/version.rb
|
25
28
|
- lib/route_downcaser/railtie.rb
|
26
|
-
- lib/route_downcaser.rb
|
29
|
+
- lib/route_downcaser/version.rb
|
27
30
|
- lib/tasks/route_downcaser_tasks.rake
|
28
|
-
-
|
29
|
-
-
|
30
|
-
-
|
31
|
-
- test/dummy/
|
32
|
-
- test/dummy/
|
33
|
-
- test/dummy/
|
34
|
-
- test/dummy/
|
35
|
-
- test/dummy/
|
36
|
-
- test/dummy/config
|
31
|
+
- test/dummy/Rakefile
|
32
|
+
- test/dummy/app/assets/images/SpaceCat.jpeg
|
33
|
+
- test/dummy/app/assets/javascripts/application.js
|
34
|
+
- test/dummy/app/assets/stylesheets/application.css
|
35
|
+
- test/dummy/app/controllers/application_controller.rb
|
36
|
+
- test/dummy/app/controllers/hello_controller.rb
|
37
|
+
- test/dummy/app/helpers/application_helper.rb
|
38
|
+
- test/dummy/app/views/layouts/application.html.erb
|
39
|
+
- test/dummy/config.ru
|
40
|
+
- test/dummy/config/application.rb
|
41
|
+
- test/dummy/config/boot.rb
|
37
42
|
- test/dummy/config/database.yml
|
38
43
|
- test/dummy/config/environment.rb
|
44
|
+
- test/dummy/config/environments/development.rb
|
39
45
|
- test/dummy/config/environments/production.rb
|
40
46
|
- test/dummy/config/environments/test.rb
|
41
|
-
- test/dummy/config/environments/development.rb
|
42
|
-
- test/dummy/config/routes.rb
|
43
47
|
- test/dummy/config/initializers/backtrace_silencers.rb
|
44
48
|
- test/dummy/config/initializers/inflections.rb
|
45
|
-
- test/dummy/config/initializers/session_store.rb
|
46
49
|
- test/dummy/config/initializers/mime_types.rb
|
47
|
-
- test/dummy/config/initializers/wrap_parameters.rb
|
48
50
|
- test/dummy/config/initializers/secret_token.rb
|
49
|
-
- test/dummy/config/
|
50
|
-
- test/dummy/config/
|
51
|
-
- test/dummy/
|
52
|
-
- test/dummy/
|
53
|
-
- test/dummy/
|
54
|
-
- test/dummy/
|
55
|
-
- test/dummy/
|
56
|
-
- test/dummy/
|
57
|
-
- test/dummy/
|
58
|
-
- test/dummy/app/assets/stylesheets/application.css
|
59
|
-
- test/dummy/config.ru
|
51
|
+
- test/dummy/config/initializers/session_store.rb
|
52
|
+
- test/dummy/config/initializers/wrap_parameters.rb
|
53
|
+
- test/dummy/config/locales/en.yml
|
54
|
+
- test/dummy/config/routes.rb
|
55
|
+
- test/dummy/log/test.log
|
56
|
+
- test/dummy/public/404.html
|
57
|
+
- test/dummy/public/422.html
|
58
|
+
- test/dummy/public/500.html
|
59
|
+
- test/dummy/public/favicon.ico
|
60
60
|
- test/dummy/script/rails
|
61
61
|
- test/integration/route_middleware_test.rb
|
62
62
|
- test/route_downcaser_test.rb
|
63
63
|
- test/test_helper.rb
|
64
64
|
homepage: https://github.com/carstengehling/route_downcaser
|
65
65
|
licenses: []
|
66
|
+
metadata: {}
|
66
67
|
post_install_message:
|
67
68
|
rdoc_options: []
|
68
69
|
require_paths:
|
69
70
|
- lib
|
70
71
|
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
-
none: false
|
72
72
|
requirements:
|
73
73
|
- - ! '>='
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
|
-
segments:
|
77
|
-
- 0
|
78
|
-
hash: 4407952237472228384
|
79
76
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
-
none: false
|
81
77
|
requirements:
|
82
78
|
- - ! '>='
|
83
79
|
- !ruby/object:Gem::Version
|
84
80
|
version: '0'
|
85
|
-
segments:
|
86
|
-
- 0
|
87
|
-
hash: 4407952237472228384
|
88
81
|
requirements: []
|
89
82
|
rubyforge_project:
|
90
|
-
rubygems_version:
|
83
|
+
rubygems_version: 2.2.2
|
91
84
|
signing_key:
|
92
|
-
specification_version:
|
85
|
+
specification_version: 4
|
93
86
|
summary: Makes routing in Rails case-insensitive
|
94
87
|
test_files:
|
95
88
|
- test/dummy/log/test.log
|