rack-slashenforce 0.0.1

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.
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ .DS_Store
2
+ *.gem
3
+ Gemfile.lock
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Tyler Kellen
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,32 @@
1
+ # Rack::SlashEnforce
2
+
3
+ A rack middleware to enforce appending or removing trailing slashes from URLs.
4
+
5
+ ## Setup
6
+
7
+ ```console
8
+ $ gem install rack-slashenforce
9
+ ```
10
+
11
+ #### Bundler users
12
+ If you use Bundler, you will need to add it to your *Gemfile*.
13
+
14
+ ```ruby
15
+ gem 'rack-slashenforce', :require => 'rack'
16
+ ```
17
+
18
+ Add one of the following to config.ru:
19
+
20
+ To enforce a trailing slash on all urls without a period in them:
21
+ ```ruby
22
+ use Rack::AppendSlash
23
+ ```
24
+
25
+ To enforce no trailing slashes on any urls:
26
+ ```ruby
27
+ use Rack::RemoveSlash
28
+ ```
29
+
30
+ For a more robust solution, see ([rack-rewrite](https://github.com/jtrupiano/rack-rewrite)).
31
+
32
+ Copyright (c) 2012 Tyler Kellen. See LICENSE for further details.
@@ -0,0 +1,45 @@
1
+ module Rack
2
+
3
+ module SlashEnforce
4
+ def self.version
5
+ '0.0.1'
6
+ end
7
+ end
8
+
9
+ class RemoveSlash
10
+ # regexp to match strings that start and end with a slash
11
+ MATCH = %r{^/(.*)/$}
12
+
13
+ def initialize(app)
14
+ @app = app
15
+ end
16
+
17
+ def call(env)
18
+ if env['PATH_INFO'] != '/' && env['PATH_INFO'] =~ MATCH
19
+ env['PATH_INFO'].sub!(/(\/)+$/,'')
20
+ [301, {"Location" => Rack::Request.new(env).url, "Content-Type" => ""}, []]
21
+ else
22
+ @app.call(env)
23
+ end
24
+ end
25
+ end
26
+
27
+ class AppendSlash
28
+ # regexp to match strings without periods that start and end with a slash
29
+ MATCH = %r{^/([^.]*)[^/]$}
30
+
31
+ def initialize(app)
32
+ @app = app
33
+ end
34
+
35
+ def call(env)
36
+ if env['PATH_INFO'] != '/' && env['PATH_INFO'] =~ MATCH
37
+ env['PATH_INFO'] += '/'
38
+ [301, {"Location" => Rack::Request.new(env).url, "Content-Type" => ""}, []]
39
+ else
40
+ @app.call(env)
41
+ end
42
+ end
43
+ end
44
+
45
+ end
@@ -0,0 +1,15 @@
1
+ require File.dirname(__FILE__)+'/lib/rack-slashenforce'
2
+
3
+ Gem::Specification.new do |gem|
4
+ gem.name = 'rack-slashenforce'
5
+ gem.version = Rack::SlashEnforce.version
6
+ gem.summary = 'A rack middleware to enforce appending or removing trailing slashes.'
7
+ gem.description = gem.description
8
+ gem.author = 'Tyler Kellen'
9
+ gem.email = 'tyler@sleekcode.net'
10
+ gem.homepage = 'https://github.com/tkellen/rack-slashenforce/'
11
+ gem.files = `git ls-files`.split("\n")
12
+ gem.require_paths = ['lib']
13
+
14
+ gem.add_runtime_dependency 'rack'
15
+ end
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack-slashenforce
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Tyler Kellen
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rack
16
+ requirement: &70154486898060 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70154486898060
25
+ description: ''
26
+ email: tyler@sleekcode.net
27
+ executables: []
28
+ extensions: []
29
+ extra_rdoc_files: []
30
+ files:
31
+ - .gitignore
32
+ - LICENSE
33
+ - README.md
34
+ - lib/rack-slashenforce.rb
35
+ - rack-slashenforce.gemspec
36
+ homepage: https://github.com/tkellen/rack-slashenforce/
37
+ licenses: []
38
+ post_install_message:
39
+ rdoc_options: []
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ requirements: []
55
+ rubyforge_project:
56
+ rubygems_version: 1.8.10
57
+ signing_key:
58
+ specification_version: 3
59
+ summary: A rack middleware to enforce appending or removing trailing slashes.
60
+ test_files: []
61
+ has_rdoc: