mojito 0.2.4 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +6 -8
- data/VERSION +1 -1
- data/lib/mojito.rb +3 -1
- data/lib/mojito/base.rb +2 -1
- data/lib/mojito/controllers.rb +1 -1
- data/lib/mojito/controllers/entities.rb +42 -0
- data/lib/mojito/rendering.rb +2 -0
- data/lib/mojito/rendering/markup.rb +14 -0
- data/lib/mojito/rendering/status_codes.rb +7 -18
- data/spec/mojito/rendering/status_codes_spec.rb +2 -4
- metadata +20 -2
data/README.textile
CHANGED
@@ -2,7 +2,7 @@ h1. mojito - Next level Ruby webframework
|
|
2
2
|
|
3
3
|
p. Mojito is a lean and simple webframework.
|
4
4
|
|
5
|
-
p. As the name implies mojito derives from cuba (https://github.com/soveran/cuba). Many thanks to Michel and his cuba project for giving me some major insights on web-application-simplicity!
|
5
|
+
p. As the name implies mojito derives from cuba (https://github.com/soveran/cuba). Many thanks to Michel and his cuba project for giving me some major insights on web-application-simplicity! See also https://github.com/mtrense/mojito-examples for more examples.
|
6
6
|
|
7
7
|
h2. Installing
|
8
8
|
|
@@ -38,19 +38,17 @@ p. This starts a http-server on port 9292. Now try to call your handler with cur
|
|
38
38
|
bc. $ curl http://localhost:9292/hello/Fred
|
39
39
|
Hello Fred! How are you?
|
40
40
|
|
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...
|
42
|
-
|
43
41
|
h2. Controllers
|
44
42
|
|
45
|
-
|
43
|
+
Controllers are the common building blocks of Mojito Applications. For each successful request at least one controller is instantiated. The call to @controller :runtime@ actually defines the calling class as runtime controller and includes the corresponding module - Mojito::Controllers::Runtime in this case. For a specific class one can choose from many controller types, each of which is specialized to a specific use-case.
|
44
|
+
|
45
|
+
Controller classes are actually Rack-Applications, so they must provide a (class-)method @call(env)@. The common sequence of processing a request includes:
|
46
46
|
|
47
47
|
* @call(env)@ is called from the surrounding application/the framework
|
48
|
-
* a new instance of the controller-class is instantiated and
|
48
|
+
* a new instance of the controller-class is instantiated and configured with the given environment
|
49
49
|
* a kind of dispatch method (@__dispatch@ for build-in controllers) is called to do the actual work
|
50
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
|
-
|
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.
|
54
52
|
|
55
53
|
h2. Structure of a real-world application
|
56
54
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.5
|
data/lib/mojito.rb
CHANGED
@@ -42,6 +42,8 @@ module Mojito
|
|
42
42
|
|
43
43
|
def controller(name, options = {})
|
44
44
|
mod = Mojito::Controllers.const_get name.to_s.camel_case.to_sym
|
45
|
+
[*options[:rendering]].each {|r| rendering r }
|
46
|
+
[*options[:helpers]].each {|h| helper h }
|
45
47
|
include mod
|
46
48
|
end
|
47
49
|
|
@@ -55,7 +57,7 @@ module Mojito
|
|
55
57
|
when :all
|
56
58
|
Mojito::Rendering
|
57
59
|
else
|
58
|
-
Mojito::
|
60
|
+
Mojito::Rendering.const_get name.to_s.camel_case.to_sym
|
59
61
|
end
|
60
62
|
include mod
|
61
63
|
end
|
data/lib/mojito/base.rb
CHANGED
@@ -10,13 +10,14 @@ module Mojito
|
|
10
10
|
type.extend ClassMethods
|
11
11
|
end
|
12
12
|
|
13
|
-
def initialize(request)
|
13
|
+
def initialize(request, options = {})
|
14
14
|
@__request = case request
|
15
15
|
when Rack::Request
|
16
16
|
request.dup
|
17
17
|
when Hash, Mash
|
18
18
|
Rack::Request.new(request.dup)
|
19
19
|
end
|
20
|
+
@options = options
|
20
21
|
self.env['MOJITO/CONTEXT_PATH'] = self.env['SCRIPT_NAME']
|
21
22
|
end
|
22
23
|
|
data/lib/mojito/controllers.rb
CHANGED
@@ -0,0 +1,42 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
module Mojito::Controllers
|
4
|
+
|
5
|
+
module Entities
|
6
|
+
|
7
|
+
def self.included(type)
|
8
|
+
type.extend ClassMethods
|
9
|
+
end
|
10
|
+
|
11
|
+
def __dispatch
|
12
|
+
|
13
|
+
[404, { 'Content-Type' => 'application/octet-stream' }, []]
|
14
|
+
end
|
15
|
+
|
16
|
+
module ClassMethods
|
17
|
+
|
18
|
+
def types
|
19
|
+
@types ||= {}
|
20
|
+
end
|
21
|
+
|
22
|
+
def type(t, &block)
|
23
|
+
tc = TypeConfiguration.new t
|
24
|
+
tc.instance_exec &block if block
|
25
|
+
types[t] = tc
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
class TypeConfiguration
|
31
|
+
|
32
|
+
def initialize(type)
|
33
|
+
@type = type
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
data/lib/mojito/rendering.rb
CHANGED
@@ -6,6 +6,7 @@ module Mojito::Rendering
|
|
6
6
|
require 'mojito/rendering/content_types'
|
7
7
|
require 'mojito/rendering/delegation'
|
8
8
|
require 'mojito/rendering/file'
|
9
|
+
require 'mojito/rendering/markup'
|
9
10
|
require 'mojito/rendering/status_codes'
|
10
11
|
require 'mojito/rendering/templates'
|
11
12
|
|
@@ -15,6 +16,7 @@ module Mojito::Rendering
|
|
15
16
|
include ContentTypes
|
16
17
|
include Delegation
|
17
18
|
include File
|
19
|
+
include Markup
|
18
20
|
include StatusCodes
|
19
21
|
include Templates
|
20
22
|
end
|
@@ -4,24 +4,13 @@ module Mojito::Rendering
|
|
4
4
|
|
5
5
|
module StatusCodes
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
halt!
|
15
|
-
end
|
16
|
-
|
17
|
-
def internal_server_error!
|
18
|
-
response.status = 500
|
19
|
-
halt!
|
20
|
-
end
|
21
|
-
|
22
|
-
def unavailable!
|
23
|
-
response.status = 503
|
24
|
-
halt!
|
7
|
+
%W[ok not_found unauthorized internal_server_error service_unavailable].each do |status|
|
8
|
+
eval <<-EVAL
|
9
|
+
def #{status}!
|
10
|
+
response.status = #{Mojito::STATUS[status.to_sym].code}
|
11
|
+
halt!
|
12
|
+
end
|
13
|
+
EVAL
|
25
14
|
end
|
26
15
|
|
27
16
|
def redirect(target, status = 302)
|
@@ -13,7 +13,7 @@ describe Mojito::Rendering::StatusCodes do
|
|
13
13
|
on 'ok' do ok! end
|
14
14
|
on 'not_found' do not_found! end
|
15
15
|
on 'internal_server_error' do internal_server_error! end
|
16
|
-
on '
|
16
|
+
on 'service_unavailable' do service_unavailable! end
|
17
17
|
on 'redirect' do redirect! '/test' end
|
18
18
|
end.mock_request
|
19
19
|
end
|
@@ -21,9 +21,7 @@ describe Mojito::Rendering::StatusCodes do
|
|
21
21
|
it { subject.get('/ok').status.should == 200 }
|
22
22
|
it { subject.get('/not_found').status.should == 404 }
|
23
23
|
it { subject.get('/internal_server_error').status.should == 500 }
|
24
|
-
it { subject.get('/
|
24
|
+
it { subject.get('/service_unavailable').status.should == 503 }
|
25
25
|
it { subject.get('/redirect').should respond_with(302, 'Location' => '/test') }
|
26
|
-
# it { subject.get('/redirect').status.should == 302 }
|
27
|
-
# it { subject.get('/redirect').headers['Location'].should == '/test' }
|
28
26
|
|
29
27
|
end
|
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.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-09-
|
12
|
+
date: 2012-09-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rack
|
@@ -75,6 +75,22 @@ dependencies:
|
|
75
75
|
- - ~>
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: 0.9.15
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: json_builder
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ~>
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 3.1.7
|
86
|
+
type: :runtime
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 3.1.7
|
78
94
|
- !ruby/object:Gem::Dependency
|
79
95
|
name: where-am-i
|
80
96
|
requirement: !ruby/object:Gem::Requirement
|
@@ -184,6 +200,7 @@ files:
|
|
184
200
|
- lib/mojito.rb
|
185
201
|
- lib/mojito/base.rb
|
186
202
|
- lib/mojito/controllers.rb
|
203
|
+
- lib/mojito/controllers/entities.rb
|
187
204
|
- lib/mojito/controllers/method.rb
|
188
205
|
- lib/mojito/controllers/runtime.rb
|
189
206
|
- lib/mojito/controllers/runtime/environment.rb
|
@@ -201,6 +218,7 @@ files:
|
|
201
218
|
- lib/mojito/rendering/content_types.rb
|
202
219
|
- lib/mojito/rendering/delegation.rb
|
203
220
|
- lib/mojito/rendering/file.rb
|
221
|
+
- lib/mojito/rendering/markup.rb
|
204
222
|
- lib/mojito/rendering/status_codes.rb
|
205
223
|
- lib/mojito/rendering/templates.rb
|
206
224
|
- lib/mojito/request_extensions.rb
|