otto 0.3.2 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES.txt +5 -0
- data/README.md +12 -12
- data/VERSION.yml +2 -2
- data/lib/otto.rb +18 -1
- data/otto.gemspec +3 -3
- metadata +17 -7
data/CHANGES.txt
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Otto - 0.
|
1
|
+
# Otto - 0.4
|
2
2
|
|
3
3
|
**Auto-define your rack-apps in plain-text.**
|
4
4
|
|
@@ -31,8 +31,8 @@ Here is an example:
|
|
31
31
|
GET /robots.txt App#robots_text
|
32
32
|
GET /product/:prodid App#display_product
|
33
33
|
|
34
|
-
# You can also define these handlers when no
|
35
|
-
# route can be found or there's a server error. (optional)
|
34
|
+
# You can also define these handlers when no
|
35
|
+
# route can be found or there's a server error. (optional)
|
36
36
|
GET /404 App#not_found
|
37
37
|
GET /500 App#server_error
|
38
38
|
|
@@ -73,13 +73,13 @@ There is nothing special about the Ruby class. The only requirement is that the
|
|
73
73
|
rules = 'User-agent: *', 'Disallow: /private'
|
74
74
|
res.body = rules.join($/)
|
75
75
|
end
|
76
|
-
|
76
|
+
|
77
77
|
def display_product
|
78
78
|
res.header['Content-Type'] = "application/json; charset=utf-8"
|
79
79
|
prodid = req.params[:prodid]
|
80
80
|
res.body = '{"product":%s,"msg":"Hint: try another value"}' % [prodid]
|
81
81
|
end
|
82
|
-
|
82
|
+
|
83
83
|
def not_found
|
84
84
|
res.status = 404
|
85
85
|
res.body = "Item not found!"
|
@@ -93,29 +93,29 @@ There is nothing special about the Ruby class. The only requirement is that the
|
|
93
93
|
|
94
94
|
### Rackup ###
|
95
95
|
|
96
|
-
There is also nothing special about the rackup file. It just builds a Rack app using your routes file.
|
96
|
+
There is also nothing special about the rackup file. It just builds a Rack app using your routes file.
|
97
97
|
|
98
98
|
require 'otto'
|
99
99
|
require 'app'
|
100
|
-
|
100
|
+
|
101
101
|
app = Otto.new("./routes")
|
102
|
-
|
103
|
-
map('/') {
|
102
|
+
|
103
|
+
map('/') {
|
104
104
|
run app
|
105
105
|
}
|
106
106
|
|
107
107
|
See the examples/ directory for a working app.
|
108
108
|
|
109
|
-
|
109
|
+
|
110
110
|
## Installation
|
111
111
|
|
112
112
|
Get it in one of the following ways:
|
113
|
-
|
113
|
+
|
114
114
|
$ gem install otto
|
115
115
|
$ sudo gem install otto
|
116
116
|
$ git clone git://github.com/delano/otto.git
|
117
117
|
|
118
|
-
You can also download via [tarball](http://github.com/delano/otto/tarball/latest) or [zip](http://github.com/delano/otto/zipball/latest).
|
118
|
+
You can also download via [tarball](http://github.com/delano/otto/tarball/latest) or [zip](http://github.com/delano/otto/zipball/latest).
|
119
119
|
|
120
120
|
|
121
121
|
## More Information
|
data/VERSION.yml
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
:MAJOR: 0
|
2
|
-
:MINOR:
|
3
|
-
:PATCH:
|
2
|
+
:MINOR: 4
|
3
|
+
:PATCH: 0
|
data/lib/otto.rb
CHANGED
@@ -33,7 +33,8 @@ class Otto
|
|
33
33
|
@routes_literal = { :GET => {} }
|
34
34
|
@route_definitions = {}
|
35
35
|
@option = opts.merge({
|
36
|
-
:public => nil
|
36
|
+
:public => nil,
|
37
|
+
:locale => 'en'
|
37
38
|
})
|
38
39
|
load(path) unless path.nil?
|
39
40
|
super()
|
@@ -84,6 +85,8 @@ class Otto
|
|
84
85
|
end
|
85
86
|
|
86
87
|
def call env
|
88
|
+
locale = determine_locale env
|
89
|
+
env['rack.locale'] = locale || self.option[:locale]
|
87
90
|
if option[:public] && safe_dir?(option[:public])
|
88
91
|
@static_route ||= Rack::File.new(option[:public])
|
89
92
|
end
|
@@ -182,6 +185,20 @@ class Otto
|
|
182
185
|
end
|
183
186
|
end
|
184
187
|
|
188
|
+
def determine_locale env
|
189
|
+
accept_langs = env['HTTP_ACCEPT_LANGUAGE']
|
190
|
+
locales = accept_langs.split(',').map { |l|
|
191
|
+
l += ';q=1.0' unless l =~ /;q=\d+(?:\.\d+)?$/
|
192
|
+
l.split(';q=')
|
193
|
+
}.sort_by { |locale, qvalue|
|
194
|
+
qvalue.to_f
|
195
|
+
}.collect { |locale, qvalue|
|
196
|
+
locale
|
197
|
+
}.reverse
|
198
|
+
STDERR.puts "locale: #{locales} (#{accept_langs})" if Otto.debug
|
199
|
+
locales.empty? ? nil : locales
|
200
|
+
end
|
201
|
+
|
185
202
|
module Static
|
186
203
|
extend self
|
187
204
|
def server_error
|
data/otto.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "otto"
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.4.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Delano Mandelbaum"]
|
12
|
-
s.date = "
|
12
|
+
s.date = "2015-04-06"
|
13
13
|
s.description = "Auto-define your rack-apps in plaintext."
|
14
14
|
s.email = "delano@solutious.com"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -33,7 +33,7 @@ Gem::Specification.new do |s|
|
|
33
33
|
s.homepage = "http://github.com/delano/otto"
|
34
34
|
s.require_paths = ["lib"]
|
35
35
|
s.rubyforge_project = "otto"
|
36
|
-
s.rubygems_version = "1.8.
|
36
|
+
s.rubygems_version = "1.8.23"
|
37
37
|
s.summary = "Auto-define your rack-apps in plaintext."
|
38
38
|
|
39
39
|
if s.respond_to? :specification_version then
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: otto
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2015-04-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rack
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,15 @@ dependencies:
|
|
21
21
|
version: 1.2.1
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.2.1
|
25
30
|
- !ruby/object:Gem::Dependency
|
26
31
|
name: addressable
|
27
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
28
33
|
none: false
|
29
34
|
requirements:
|
30
35
|
- - ! '>='
|
@@ -32,7 +37,12 @@ dependencies:
|
|
32
37
|
version: 2.2.6
|
33
38
|
type: :runtime
|
34
39
|
prerelease: false
|
35
|
-
version_requirements:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 2.2.6
|
36
46
|
description: Auto-define your rack-apps in plaintext.
|
37
47
|
email: delano@solutious.com
|
38
48
|
executables: []
|
@@ -73,7 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
73
83
|
version: '0'
|
74
84
|
requirements: []
|
75
85
|
rubyforge_project: otto
|
76
|
-
rubygems_version: 1.8.
|
86
|
+
rubygems_version: 1.8.23
|
77
87
|
signing_key:
|
78
88
|
specification_version: 3
|
79
89
|
summary: Auto-define your rack-apps in plaintext.
|