mojito 0.2.3 → 0.2.4
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/README.textile +21 -3
- data/VERSION +1 -1
- data/lib/mojito.rb +20 -0
- data/lib/mojito/base.rb +11 -6
- data/lib/mojito/helpers/exception_handling.rb +0 -10
- metadata +73 -23
data/README.textile
CHANGED
|
@@ -15,7 +15,11 @@ p. The easiest way to start with mojito is to use a plain @config.ru@ script to
|
|
|
15
15
|
bc.. $ cat config.ru
|
|
16
16
|
require 'mojito'
|
|
17
17
|
|
|
18
|
-
FirstApp
|
|
18
|
+
class FirstApp
|
|
19
|
+
include Mojito
|
|
20
|
+
controller :runtime
|
|
21
|
+
rendering :all
|
|
22
|
+
|
|
19
23
|
on GET(), PATH('/hello/:name') do |name|
|
|
20
24
|
write "Hello #{name}! How are you?"
|
|
21
25
|
content_type :plain
|
|
@@ -23,21 +27,35 @@ FirstApp = Mojito.application do
|
|
|
23
27
|
end
|
|
24
28
|
end
|
|
25
29
|
|
|
26
|
-
run FirstApp
|
|
30
|
+
run FirstApp
|
|
27
31
|
|
|
28
32
|
p. This installs a handler for GET requests to a path of /hello/ followed by a name (actually this notation catches everything but a slash '/'). You can start this application by running @rackup@ from the same directory:
|
|
29
33
|
|
|
30
34
|
bc. $ rackup
|
|
31
35
|
|
|
32
|
-
p. This starts a http-server on port 9292. Now try to call your handler
|
|
36
|
+
p. This starts a http-server on port 9292. Now try to call your handler with curl:
|
|
33
37
|
|
|
34
38
|
bc. $ curl http://localhost:9292/hello/Fred
|
|
35
39
|
Hello Fred! How are you?
|
|
36
40
|
|
|
37
41
|
p. Please be aware that although this way is easy to start with it tends to get messy very quick if your project becomes more complex, so please read on...
|
|
38
42
|
|
|
43
|
+
h2. Controllers
|
|
44
|
+
|
|
45
|
+
The method call @Mojito::Controllers.runtime_controller@ actually created a new controller class. Every controller inherits from @Mojito::Base@ which contains a minimal set of methods that all controllers must have in common. Controller classes are actually Rack-Applications, so they must provide a (class-)method @call(env)@. The common sequence of processing a request includes:
|
|
46
|
+
|
|
47
|
+
* @call(env)@ is called from the surrounding application/the framework
|
|
48
|
+
* a new instance of the controller-class is instantiated and filled with the given environment
|
|
49
|
+
* a kind of dispatch method (@__dispatch@ for build-in controllers) is called to do the actual work
|
|
50
|
+
|
|
51
|
+
This ensures that the controller instance which handles a specific request is used solely for that request, so that any instance variables created during request-processing stay request-local. At the same time this keeps application stacking and nesting as simple as @call@-ing the next application
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
39
55
|
h2. Structure of a real-world application
|
|
40
56
|
|
|
57
|
+
p. *This is not up-to-date*
|
|
58
|
+
|
|
41
59
|
p. The above call to @Mojito.application@ actually created a class and included most of Mojitos foundation methods, so that you could start writing your application code without wondering what features you want to include in your application. As a tribute to simplicity (one of the most important I think), another helper method @Mojito.base_application@ can be used to create a blank application class, which only includes modules that are strictly necessary. Instead of using those methods you can also write out all of the generated classes code (here @Mojito@ is included, which in turn includes @Mojito::Base@, the basic module which is used by @Mojito.base_application@):
|
|
42
60
|
|
|
43
61
|
bc.. class FirstApp
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.2.
|
|
1
|
+
0.2.4
|
data/lib/mojito.rb
CHANGED
|
@@ -40,6 +40,26 @@ module Mojito
|
|
|
40
40
|
Rack::MockRequest.new self
|
|
41
41
|
end
|
|
42
42
|
|
|
43
|
+
def controller(name, options = {})
|
|
44
|
+
mod = Mojito::Controllers.const_get name.to_s.camel_case.to_sym
|
|
45
|
+
include mod
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def helper(name, options = {})
|
|
49
|
+
mod = Mojito::Helpers.const_get name.to_s.camel_case.to_sym
|
|
50
|
+
include mod
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def rendering(name, options = {})
|
|
54
|
+
mod = case name
|
|
55
|
+
when :all
|
|
56
|
+
Mojito::Rendering
|
|
57
|
+
else
|
|
58
|
+
Mojito::Controllers.const_get name.to_s.camel_case.to_sym
|
|
59
|
+
end
|
|
60
|
+
include mod
|
|
61
|
+
end
|
|
62
|
+
|
|
43
63
|
end
|
|
44
64
|
|
|
45
65
|
end
|
data/lib/mojito/base.rb
CHANGED
|
@@ -63,16 +63,21 @@ module Mojito
|
|
|
63
63
|
def call(env)
|
|
64
64
|
catch :halt do
|
|
65
65
|
request = Rack::Request.new env
|
|
66
|
-
|
|
66
|
+
dispatch request
|
|
67
67
|
end
|
|
68
68
|
end
|
|
69
69
|
|
|
70
|
-
def call_with_handlers(request)
|
|
71
|
-
dispatch request
|
|
72
|
-
end
|
|
73
|
-
|
|
74
70
|
def dispatch(request)
|
|
75
|
-
self.new
|
|
71
|
+
controller = self.new request
|
|
72
|
+
begin
|
|
73
|
+
controller.__dispatch
|
|
74
|
+
rescue Exception => e
|
|
75
|
+
if controller.respond_to? :__handle_error
|
|
76
|
+
controller.__handle_error(e)
|
|
77
|
+
else
|
|
78
|
+
raise e
|
|
79
|
+
end
|
|
80
|
+
end
|
|
76
81
|
end
|
|
77
82
|
|
|
78
83
|
end
|
|
@@ -22,16 +22,6 @@ module Mojito
|
|
|
22
22
|
module ExceptionHandling
|
|
23
23
|
|
|
24
24
|
def self.included(type)
|
|
25
|
-
type.instance_exec do
|
|
26
|
-
old_call_with_handlers = method(:call_with_handlers)
|
|
27
|
-
define_method :call_with_handlers do
|
|
28
|
-
begin
|
|
29
|
-
old_call_with_handlers.bind(self).call
|
|
30
|
-
rescue Exception => e
|
|
31
|
-
__handle_error e
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
25
|
type.extend ClassMethods
|
|
36
26
|
end
|
|
37
27
|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: mojito
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.4
|
|
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: 2012-
|
|
12
|
+
date: 2012-09-24 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.4.0
|
|
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.4.0
|
|
25
30
|
- !ruby/object:Gem::Dependency
|
|
26
31
|
name: mime-types
|
|
27
|
-
requirement:
|
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
|
28
33
|
none: false
|
|
29
34
|
requirements:
|
|
30
35
|
- - ~>
|
|
@@ -32,10 +37,15 @@ dependencies:
|
|
|
32
37
|
version: '1.18'
|
|
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: '1.18'
|
|
36
46
|
- !ruby/object:Gem::Dependency
|
|
37
47
|
name: tilt
|
|
38
|
-
requirement:
|
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
|
39
49
|
none: false
|
|
40
50
|
requirements:
|
|
41
51
|
- - ~>
|
|
@@ -43,10 +53,15 @@ dependencies:
|
|
|
43
53
|
version: 1.3.3
|
|
44
54
|
type: :runtime
|
|
45
55
|
prerelease: false
|
|
46
|
-
version_requirements:
|
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
57
|
+
none: false
|
|
58
|
+
requirements:
|
|
59
|
+
- - ~>
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: 1.3.3
|
|
47
62
|
- !ruby/object:Gem::Dependency
|
|
48
63
|
name: extlib
|
|
49
|
-
requirement:
|
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
|
50
65
|
none: false
|
|
51
66
|
requirements:
|
|
52
67
|
- - ~>
|
|
@@ -54,10 +69,15 @@ dependencies:
|
|
|
54
69
|
version: 0.9.15
|
|
55
70
|
type: :runtime
|
|
56
71
|
prerelease: false
|
|
57
|
-
version_requirements:
|
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
73
|
+
none: false
|
|
74
|
+
requirements:
|
|
75
|
+
- - ~>
|
|
76
|
+
- !ruby/object:Gem::Version
|
|
77
|
+
version: 0.9.15
|
|
58
78
|
- !ruby/object:Gem::Dependency
|
|
59
79
|
name: where-am-i
|
|
60
|
-
requirement:
|
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
|
61
81
|
none: false
|
|
62
82
|
requirements:
|
|
63
83
|
- - ~>
|
|
@@ -65,10 +85,15 @@ dependencies:
|
|
|
65
85
|
version: 1.0.0
|
|
66
86
|
type: :runtime
|
|
67
87
|
prerelease: false
|
|
68
|
-
version_requirements:
|
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
89
|
+
none: false
|
|
90
|
+
requirements:
|
|
91
|
+
- - ~>
|
|
92
|
+
- !ruby/object:Gem::Version
|
|
93
|
+
version: 1.0.0
|
|
69
94
|
- !ruby/object:Gem::Dependency
|
|
70
95
|
name: rspec
|
|
71
|
-
requirement:
|
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
97
|
none: false
|
|
73
98
|
requirements:
|
|
74
99
|
- - ~>
|
|
@@ -76,10 +101,15 @@ dependencies:
|
|
|
76
101
|
version: 2.8.0
|
|
77
102
|
type: :development
|
|
78
103
|
prerelease: false
|
|
79
|
-
version_requirements:
|
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
105
|
+
none: false
|
|
106
|
+
requirements:
|
|
107
|
+
- - ~>
|
|
108
|
+
- !ruby/object:Gem::Version
|
|
109
|
+
version: 2.8.0
|
|
80
110
|
- !ruby/object:Gem::Dependency
|
|
81
111
|
name: rdoc
|
|
82
|
-
requirement:
|
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
|
83
113
|
none: false
|
|
84
114
|
requirements:
|
|
85
115
|
- - ~>
|
|
@@ -87,10 +117,15 @@ dependencies:
|
|
|
87
117
|
version: '3.12'
|
|
88
118
|
type: :development
|
|
89
119
|
prerelease: false
|
|
90
|
-
version_requirements:
|
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
121
|
+
none: false
|
|
122
|
+
requirements:
|
|
123
|
+
- - ~>
|
|
124
|
+
- !ruby/object:Gem::Version
|
|
125
|
+
version: '3.12'
|
|
91
126
|
- !ruby/object:Gem::Dependency
|
|
92
127
|
name: bundler
|
|
93
|
-
requirement:
|
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
|
94
129
|
none: false
|
|
95
130
|
requirements:
|
|
96
131
|
- - ~>
|
|
@@ -98,10 +133,15 @@ dependencies:
|
|
|
98
133
|
version: 1.0.0
|
|
99
134
|
type: :development
|
|
100
135
|
prerelease: false
|
|
101
|
-
version_requirements:
|
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
137
|
+
none: false
|
|
138
|
+
requirements:
|
|
139
|
+
- - ~>
|
|
140
|
+
- !ruby/object:Gem::Version
|
|
141
|
+
version: 1.0.0
|
|
102
142
|
- !ruby/object:Gem::Dependency
|
|
103
143
|
name: jeweler
|
|
104
|
-
requirement:
|
|
144
|
+
requirement: !ruby/object:Gem::Requirement
|
|
105
145
|
none: false
|
|
106
146
|
requirements:
|
|
107
147
|
- - ~>
|
|
@@ -109,10 +149,15 @@ dependencies:
|
|
|
109
149
|
version: 1.8.3
|
|
110
150
|
type: :development
|
|
111
151
|
prerelease: false
|
|
112
|
-
version_requirements:
|
|
152
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
153
|
+
none: false
|
|
154
|
+
requirements:
|
|
155
|
+
- - ~>
|
|
156
|
+
- !ruby/object:Gem::Version
|
|
157
|
+
version: 1.8.3
|
|
113
158
|
- !ruby/object:Gem::Dependency
|
|
114
159
|
name: rcov
|
|
115
|
-
requirement:
|
|
160
|
+
requirement: !ruby/object:Gem::Requirement
|
|
116
161
|
none: false
|
|
117
162
|
requirements:
|
|
118
163
|
- - ! '>='
|
|
@@ -120,7 +165,12 @@ dependencies:
|
|
|
120
165
|
version: '0'
|
|
121
166
|
type: :development
|
|
122
167
|
prerelease: false
|
|
123
|
-
version_requirements:
|
|
168
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
169
|
+
none: false
|
|
170
|
+
requirements:
|
|
171
|
+
- - ! '>='
|
|
172
|
+
- !ruby/object:Gem::Version
|
|
173
|
+
version: '0'
|
|
124
174
|
description: A simple yet powerful webframework largely inspired by Rum and Cuba
|
|
125
175
|
email: dev@trense.info
|
|
126
176
|
executables: []
|
|
@@ -194,7 +244,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
194
244
|
version: '0'
|
|
195
245
|
requirements: []
|
|
196
246
|
rubyforge_project:
|
|
197
|
-
rubygems_version: 1.8.
|
|
247
|
+
rubygems_version: 1.8.24
|
|
198
248
|
signing_key:
|
|
199
249
|
specification_version: 3
|
|
200
250
|
summary: A simple yet powerful webframework largely inspired by Rum and Cuba
|