naughty-step 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 +1 -0
- data/MIT_LICENCE +19 -0
- data/README.rdoc +22 -0
- data/naughty_step.gemspec +13 -0
- data/naughty_step.rb +23 -0
- data/spec.rb +1 -0
- metadata +72 -0
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
pkg/*
|
data/MIT_LICENCE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2010 Mickael Riga
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
"On ne menace pas son enfant d'une Ratatouille !!!" -- French Super Nanny
|
2
|
+
|
3
|
+
= Naughty Step
|
4
|
+
|
5
|
+
Well, Naughty Step is nothing ground-breaking. This is just a basic way of catching errors (Status 500) and pages not found (Status 404) and use related html pages you've written for that purpose. The middleware even has default values:
|
6
|
+
|
7
|
+
- public/404.html
|
8
|
+
- public/500.html
|
9
|
+
|
10
|
+
So a very simple example might be to require the Gem and then:
|
11
|
+
|
12
|
+
use ::Rack::NaughtyStep
|
13
|
+
|
14
|
+
Or if you want to declare your paths:
|
15
|
+
|
16
|
+
use ::Rack::NaughtyStep '/path/to/404/page.html', '/path/to/500/page.html'
|
17
|
+
|
18
|
+
Here you go. Truth is that I've been naughty as well. I did not write a proper full example, neither a spec. Just because I was in a rush, but I'll do it as soon as I can. Please don't spank me.
|
19
|
+
|
20
|
+
== Copyright
|
21
|
+
|
22
|
+
(c) 2010 Mickael Riga - see MIT_LICENCE for details
|
@@ -0,0 +1,13 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'naughty-step'
|
3
|
+
s.version = "0.0.1"
|
4
|
+
s.platform = Gem::Platform::RUBY
|
5
|
+
s.summary = "A Rack middleware for simple 404 and 500 status handling"
|
6
|
+
s.description = "Just create your 404 and 500 html pages, use the middleware, and that's it."
|
7
|
+
s.files = `git ls-files`.split("\n").sort
|
8
|
+
s.test_files = ['spec.rb']
|
9
|
+
s.require_path = '.'
|
10
|
+
s.author = "Mickael Riga"
|
11
|
+
s.email = "mig@mypeplum.com"
|
12
|
+
s.homepage = "http://github.com/mig-hub/naughty_step"
|
13
|
+
end
|
data/naughty_step.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
module Rack
|
2
|
+
class NaughtyStep
|
3
|
+
F = ::File
|
4
|
+
def initialize(app, loc_not_found='public/404.html', loc_error='public/500.html')
|
5
|
+
@app = app
|
6
|
+
@loc_not_found = loc_not_found
|
7
|
+
@loc_error = loc_error
|
8
|
+
end
|
9
|
+
def call(env)
|
10
|
+
status, headers, body = @app.call(env)
|
11
|
+
if status==404
|
12
|
+
body = F.read(@loc_not_found)
|
13
|
+
headers['Content-Type'] = 'text/html'
|
14
|
+
headers['Content-Length'] = body.size.to_s
|
15
|
+
end
|
16
|
+
[status,headers,body]
|
17
|
+
rescue StandardError, LoadError, SyntaxError => e
|
18
|
+
body = F.read(@loc_error)
|
19
|
+
headers = {'Content-Type' => 'text/html', 'Content-Length' => body.size.to_s}
|
20
|
+
[500, headers, body]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/spec.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# TODO
|
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: naughty-step
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Mickael Riga
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-09-21 00:00:00 +01:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: Just create your 404 and 500 html pages, use the middleware, and that's it.
|
23
|
+
email: mig@mypeplum.com
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files: []
|
29
|
+
|
30
|
+
files:
|
31
|
+
- .gitignore
|
32
|
+
- MIT_LICENCE
|
33
|
+
- README.rdoc
|
34
|
+
- naughty_step.gemspec
|
35
|
+
- naughty_step.rb
|
36
|
+
- spec.rb
|
37
|
+
has_rdoc: true
|
38
|
+
homepage: http://github.com/mig-hub/naughty_step
|
39
|
+
licenses: []
|
40
|
+
|
41
|
+
post_install_message:
|
42
|
+
rdoc_options: []
|
43
|
+
|
44
|
+
require_paths:
|
45
|
+
- .
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
none: false
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
hash: 3
|
52
|
+
segments:
|
53
|
+
- 0
|
54
|
+
version: "0"
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
hash: 3
|
61
|
+
segments:
|
62
|
+
- 0
|
63
|
+
version: "0"
|
64
|
+
requirements: []
|
65
|
+
|
66
|
+
rubyforge_project:
|
67
|
+
rubygems_version: 1.3.7
|
68
|
+
signing_key:
|
69
|
+
specification_version: 3
|
70
|
+
summary: A Rack middleware for simple 404 and 500 status handling
|
71
|
+
test_files:
|
72
|
+
- spec.rb
|