cuba 3.0.1.rc2 → 3.1.0.rc1
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/CHANGELOG +7 -0
- data/cuba.gemspec +1 -1
- data/lib/cuba.rb +11 -16
- data/lib/cuba/capybara.rb +13 -0
- data/lib/cuba/render.rb +16 -5
- data/lib/cuba/test.rb +5 -7
- data/test/rack.rb +22 -0
- data/test/render.rb +11 -9
- data/test/settings.rb +13 -0
- metadata +10 -8
data/CHANGELOG
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
3.1.0.rc1
|
|
2
|
+
|
|
3
|
+
* Do a deep clone of the settings object during inheritance.
|
|
4
|
+
* Start namespacing plugins (i.e. settings[:render]).
|
|
5
|
+
* Use rack/test when doing equire 'cuba/test'.
|
|
6
|
+
* Capybara available via equire 'cuba/capybara'.
|
|
7
|
+
|
|
1
8
|
3.0.0
|
|
2
9
|
|
|
3
10
|
* Remove Cuba.build. Use subclassing instead.
|
data/cuba.gemspec
CHANGED
data/lib/cuba.rb
CHANGED
|
@@ -84,10 +84,17 @@ class Cuba
|
|
|
84
84
|
@settings ||= {}
|
|
85
85
|
end
|
|
86
86
|
|
|
87
|
+
def self.deepclone(obj)
|
|
88
|
+
Marshal.load(Marshal.dump(obj))
|
|
89
|
+
end
|
|
90
|
+
|
|
87
91
|
def self.inherited(child)
|
|
88
|
-
child.settings.replace(settings)
|
|
92
|
+
child.settings.replace(deepclone(settings))
|
|
89
93
|
end
|
|
90
94
|
|
|
95
|
+
attr :env
|
|
96
|
+
attr :req
|
|
97
|
+
attr :res
|
|
91
98
|
attr :captures
|
|
92
99
|
|
|
93
100
|
def initialize(&blk)
|
|
@@ -103,22 +110,10 @@ class Cuba
|
|
|
103
110
|
dup.call!(env)
|
|
104
111
|
end
|
|
105
112
|
|
|
106
|
-
def req
|
|
107
|
-
Thread.current[:_cuba_req]
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
def res
|
|
111
|
-
Thread.current[:_cuba_res]
|
|
112
|
-
end
|
|
113
|
-
|
|
114
|
-
def env
|
|
115
|
-
Thread.current[:_cuba_env]
|
|
116
|
-
end
|
|
117
|
-
|
|
118
113
|
def call!(env)
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
114
|
+
@env = env
|
|
115
|
+
@req = Rack::Request.new(env)
|
|
116
|
+
@res = Cuba::Response.new
|
|
122
117
|
|
|
123
118
|
# This `catch` statement will either receive a
|
|
124
119
|
# rack response tuple via a `halt`, or will
|
data/lib/cuba/render.rb
CHANGED
|
@@ -3,17 +3,28 @@ require "tilt"
|
|
|
3
3
|
class Cuba
|
|
4
4
|
module Render
|
|
5
5
|
def self.setup(app)
|
|
6
|
-
app.settings[:
|
|
7
|
-
app.settings[:
|
|
6
|
+
app.settings[:render] ||= {}
|
|
7
|
+
app.settings[:render][:template_engine] ||= "erb"
|
|
8
|
+
app.settings[:render][:views] ||= File.expand_path("views", Dir.pwd)
|
|
9
|
+
app.settings[:render][:options] ||= {
|
|
10
|
+
default_encoding: Encoding.default_external
|
|
11
|
+
}
|
|
8
12
|
end
|
|
9
13
|
|
|
10
14
|
def view(template, locals = {}, layout = "layout")
|
|
11
15
|
partial(layout, { content: partial(template, locals) }.merge(locals))
|
|
12
16
|
end
|
|
13
17
|
|
|
18
|
+
def template_path(template)
|
|
19
|
+
"%s/%s.%s" % [
|
|
20
|
+
settings[:render][:views],
|
|
21
|
+
template,
|
|
22
|
+
settings[:render][:template_engine]
|
|
23
|
+
]
|
|
24
|
+
end
|
|
25
|
+
|
|
14
26
|
def partial(template, locals = {})
|
|
15
|
-
render(
|
|
16
|
-
locals, default_encoding: Encoding.default_external)
|
|
27
|
+
render(template_path(template), locals, settings[:render][:options])
|
|
17
28
|
end
|
|
18
29
|
|
|
19
30
|
# Render any type of template file supported by Tilt.
|
|
@@ -34,7 +45,7 @@ class Cuba
|
|
|
34
45
|
#
|
|
35
46
|
def render(template, locals = {}, options = {}, &block)
|
|
36
47
|
_cache.fetch(template) {
|
|
37
|
-
Tilt.new(template, 1, options.merge(outvar: '@_output')
|
|
48
|
+
Tilt.new(template, 1, options.merge(outvar: '@_output'))
|
|
38
49
|
}.render(self, locals, &block)
|
|
39
50
|
end
|
|
40
51
|
|
data/lib/cuba/test.rb
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
require "cuba"
|
|
2
2
|
require "cutest"
|
|
3
|
-
require "
|
|
3
|
+
require "rack/test"
|
|
4
4
|
|
|
5
5
|
class Cutest::Scope
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
include Rack::Test::Methods
|
|
7
|
+
|
|
8
|
+
def app
|
|
9
|
+
Cuba
|
|
10
10
|
end
|
|
11
11
|
end
|
|
12
|
-
|
|
13
|
-
Capybara.app = Cuba
|
data/test/rack.rb
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
require File.expand_path("helper", File.dirname(__FILE__))
|
|
2
|
+
require "cuba/test"
|
|
3
|
+
|
|
4
|
+
scope do
|
|
5
|
+
test do
|
|
6
|
+
Cuba.define do
|
|
7
|
+
on root do
|
|
8
|
+
res.write "home"
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
on "about" do
|
|
12
|
+
res.write "about"
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
get "/"
|
|
17
|
+
assert_equal "home", last_response.body
|
|
18
|
+
|
|
19
|
+
get "/about"
|
|
20
|
+
assert_equal "about", last_response.body
|
|
21
|
+
end
|
|
22
|
+
end
|
data/test/render.rb
CHANGED
|
@@ -3,20 +3,22 @@ require_relative "helper"
|
|
|
3
3
|
require "cuba/render"
|
|
4
4
|
|
|
5
5
|
test "doesn't override the settings if they already exist" do
|
|
6
|
-
Cuba.settings[:
|
|
7
|
-
|
|
6
|
+
Cuba.settings[:render] = {
|
|
7
|
+
:views => "./test/views",
|
|
8
|
+
:template_engine => "haml"
|
|
9
|
+
}
|
|
8
10
|
|
|
9
11
|
Cuba.plugin Cuba::Render
|
|
10
12
|
|
|
11
|
-
assert_equal "./test/views", Cuba.settings[:views]
|
|
12
|
-
assert_equal "haml", Cuba.settings[:template_engine]
|
|
13
|
+
assert_equal "./test/views", Cuba.settings[:render][:views]
|
|
14
|
+
assert_equal "haml", Cuba.settings[:render][:template_engine]
|
|
13
15
|
end
|
|
14
16
|
|
|
15
17
|
scope do
|
|
16
18
|
setup do
|
|
17
19
|
Cuba.plugin Cuba::Render
|
|
18
|
-
Cuba.settings[:views] = "./test/views"
|
|
19
|
-
Cuba.settings[:template_engine] = "erb"
|
|
20
|
+
Cuba.settings[:render][:views] = "./test/views"
|
|
21
|
+
Cuba.settings[:render][:template_engine] = "erb"
|
|
20
22
|
|
|
21
23
|
Cuba.define do
|
|
22
24
|
on "home" do
|
|
@@ -42,7 +44,7 @@ scope do
|
|
|
42
44
|
end
|
|
43
45
|
|
|
44
46
|
test "partial with str as engine" do
|
|
45
|
-
Cuba.settings[:template_engine] = "str"
|
|
47
|
+
Cuba.settings[:render][:template_engine] = "str"
|
|
46
48
|
|
|
47
49
|
_, _, body = Cuba.call({ "PATH_INFO" => "/about", "SCRIPT_NAME" => "/" })
|
|
48
50
|
|
|
@@ -50,7 +52,7 @@ scope do
|
|
|
50
52
|
end
|
|
51
53
|
|
|
52
54
|
test "view with str as engine" do
|
|
53
|
-
Cuba.settings[:template_engine] = "str"
|
|
55
|
+
Cuba.settings[:render][:template_engine] = "str"
|
|
54
56
|
|
|
55
57
|
_, _, body = Cuba.call({ "PATH_INFO" => "/home", "SCRIPT_NAME" => "/" })
|
|
56
58
|
|
|
@@ -62,7 +64,7 @@ test "caching behavior" do
|
|
|
62
64
|
Thread.current[:_cache] = nil
|
|
63
65
|
|
|
64
66
|
Cuba.plugin Cuba::Render
|
|
65
|
-
Cuba.settings[:views] = "./test/views"
|
|
67
|
+
Cuba.settings[:render][:views] = "./test/views"
|
|
66
68
|
|
|
67
69
|
Cuba.define do
|
|
68
70
|
on "foo/:i" do |i|
|
data/test/settings.rb
CHANGED
|
@@ -37,3 +37,16 @@ test do
|
|
|
37
37
|
|
|
38
38
|
assert_equal ["Hello World"], body
|
|
39
39
|
end
|
|
40
|
+
|
|
41
|
+
# The following tests the settings clone bug where
|
|
42
|
+
# we share the same reference. Deep cloning is the solution here.
|
|
43
|
+
Cuba.settings[:mote] ||= {}
|
|
44
|
+
Cuba.settings[:mote][:layout] ||= "layout"
|
|
45
|
+
|
|
46
|
+
class Login < Cuba
|
|
47
|
+
settings[:mote][:layout] = "layout/guest"
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
test do
|
|
51
|
+
assert Login.settings[:mote].object_id != Cuba.settings[:mote].object_id
|
|
52
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: cuba
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.0.
|
|
4
|
+
version: 3.1.0.rc1
|
|
5
5
|
prerelease: 6
|
|
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-07-03 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: rack
|
|
16
|
-
requirement: &
|
|
16
|
+
requirement: &2152007660 !ruby/object:Gem::Requirement
|
|
17
17
|
none: false
|
|
18
18
|
requirements:
|
|
19
19
|
- - ! '>='
|
|
@@ -21,10 +21,10 @@ dependencies:
|
|
|
21
21
|
version: '0'
|
|
22
22
|
type: :runtime
|
|
23
23
|
prerelease: false
|
|
24
|
-
version_requirements: *
|
|
24
|
+
version_requirements: *2152007660
|
|
25
25
|
- !ruby/object:Gem::Dependency
|
|
26
26
|
name: cutest
|
|
27
|
-
requirement: &
|
|
27
|
+
requirement: &2152007040 !ruby/object:Gem::Requirement
|
|
28
28
|
none: false
|
|
29
29
|
requirements:
|
|
30
30
|
- - ! '>='
|
|
@@ -32,10 +32,10 @@ dependencies:
|
|
|
32
32
|
version: '0'
|
|
33
33
|
type: :development
|
|
34
34
|
prerelease: false
|
|
35
|
-
version_requirements: *
|
|
35
|
+
version_requirements: *2152007040
|
|
36
36
|
- !ruby/object:Gem::Dependency
|
|
37
37
|
name: capybara
|
|
38
|
-
requirement: &
|
|
38
|
+
requirement: &2152006120 !ruby/object:Gem::Requirement
|
|
39
39
|
none: false
|
|
40
40
|
requirements:
|
|
41
41
|
- - ! '>='
|
|
@@ -43,7 +43,7 @@ dependencies:
|
|
|
43
43
|
version: '0'
|
|
44
44
|
type: :development
|
|
45
45
|
prerelease: false
|
|
46
|
-
version_requirements: *
|
|
46
|
+
version_requirements: *2152006120
|
|
47
47
|
description: Cuba is a microframework for web applications.
|
|
48
48
|
email:
|
|
49
49
|
- michel@soveran.com
|
|
@@ -55,6 +55,7 @@ files:
|
|
|
55
55
|
- CHANGELOG
|
|
56
56
|
- README.md
|
|
57
57
|
- Rakefile
|
|
58
|
+
- lib/cuba/capybara.rb
|
|
58
59
|
- lib/cuba/render.rb
|
|
59
60
|
- lib/cuba/test.rb
|
|
60
61
|
- lib/cuba.rb
|
|
@@ -74,6 +75,7 @@ files:
|
|
|
74
75
|
- test/param.rb
|
|
75
76
|
- test/path.rb
|
|
76
77
|
- test/plugin.rb
|
|
78
|
+
- test/rack.rb
|
|
77
79
|
- test/redirect.rb
|
|
78
80
|
- test/render.rb
|
|
79
81
|
- test/root.rb
|