manveru-innate 2009.04.01 → 2009.04.08
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +104 -0
- data/MANIFEST +18 -18
- data/Rakefile +3 -3
- data/example/app/retro_games.rb +6 -6
- data/example/app/todo/layout/default.erb +1 -1
- data/example/app/todo/view/index.erb +11 -11
- data/example/app/whywiki_erb/start.rb +1 -0
- data/example/app/whywiki_erb/view/{edit.html.erb → edit.erb} +0 -0
- data/example/app/whywiki_erb/view/{index.html.erb → index.erb} +0 -0
- data/example/howto_spec.rb +1 -1
- data/example/session.rb +3 -3
- data/innate.gemspec +3 -12
- data/lib/innate/action.rb +2 -1
- data/lib/innate/helper.rb +18 -27
- data/lib/innate/helper/cgi.rb +30 -20
- data/lib/innate/helper/render.rb +80 -0
- data/lib/innate/mock.rb +2 -3
- data/lib/innate/node.rb +79 -50
- data/lib/innate/options.rb +1 -1
- data/lib/innate/request.rb +3 -23
- data/lib/innate/spec.rb +3 -6
- data/lib/innate/version.rb +1 -1
- data/lib/innate/view/erb.rb +1 -1
- data/lib/innate/view/etanni.rb +2 -2
- data/lib/innate/view/none.rb +1 -1
- data/spec/innate/action/layout.rb +1 -1
- data/spec/innate/action/layout/file_layout.xhtml +1 -0
- data/spec/innate/helper/aspect.rb +6 -6
- data/spec/innate/helper/flash.rb +6 -6
- data/spec/innate/helper/render.rb +157 -0
- data/spec/innate/helper/view/aspect_hello.xhtml +1 -0
- data/spec/innate/helper/view/locals.xhtml +1 -0
- data/spec/innate/helper/view/loop.xhtml +4 -0
- data/spec/innate/helper/view/num.xhtml +1 -0
- data/spec/innate/helper/view/partial.xhtml +1 -0
- data/spec/innate/helper/view/recursive.xhtml +7 -0
- data/spec/innate/node/node.rb +5 -13
- data/spec/innate/node/view/another_layout/{another_layout.erb → another_layout.xhtml} +1 -1
- data/spec/innate/node/view/{bar.erb → bar.xhtml} +0 -0
- data/spec/innate/node/view/foo.html.xhtml +1 -0
- data/spec/innate/node/view/{only_view.erb → only_view.xhtml} +0 -0
- data/spec/innate/node/view/with_layout.xhtml +1 -0
- data/spec/innate/provides.rb +2 -2
- data/spec/innate/provides/list.html.xhtml +1 -0
- data/spec/innate/provides/list.txt.xhtml +1 -0
- data/spec/innate/state/fiber.rb +8 -7
- data/tasks/bacon.rake +38 -21
- metadata +22 -51
- data/lib/innate/helper/partial.rb +0 -93
- data/spec/innate/action/layout/file_layout.erb +0 -1
- data/spec/innate/helper/partial.rb +0 -101
- data/spec/innate/helper/view/aspect_hello.erb +0 -1
- data/spec/innate/helper/view/locals.erb +0 -1
- data/spec/innate/helper/view/loop.erb +0 -4
- data/spec/innate/helper/view/num.erb +0 -1
- data/spec/innate/helper/view/partial.erb +0 -1
- data/spec/innate/helper/view/recursive.erb +0 -8
- data/spec/innate/node/view/foo.html.erb +0 -1
- data/spec/innate/node/view/with_layout.erb +0 -1
- data/spec/innate/provides/list.html.erb +0 -1
- data/spec/innate/provides/list.txt.erb +0 -1
data/lib/innate/spec.rb
CHANGED
@@ -57,11 +57,8 @@ shared :multipart do
|
|
57
57
|
data << "--#{boundary}--"
|
58
58
|
body = data.join("\r\n")
|
59
59
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
{ 'CONTENT_TYPE' => type,
|
64
|
-
'CONTENT_LENGTH' => length.to_s,
|
65
|
-
:input => StringIO.new(body) }
|
60
|
+
{ 'CONTENT_TYPE' => "multipart/form-data; boundary=#{boundary}",
|
61
|
+
'CONTENT_LENGTH' => Rack::Utils.bytesize(body).to_s,
|
62
|
+
:input => StringIO.new(body) }
|
66
63
|
end
|
67
64
|
end
|
data/lib/innate/version.rb
CHANGED
data/lib/innate/view/erb.rb
CHANGED
data/lib/innate/view/etanni.rb
CHANGED
@@ -2,7 +2,7 @@ module Innate
|
|
2
2
|
module View
|
3
3
|
module Etanni
|
4
4
|
def self.call(action, string)
|
5
|
-
template = Innate::Etanni.new(string.
|
5
|
+
template = Innate::Etanni.new(string.to_s)
|
6
6
|
html = template.result(action.binding, (action.view || action.method))
|
7
7
|
return html, 'text/html'
|
8
8
|
end
|
@@ -18,7 +18,7 @@ module Innate
|
|
18
18
|
def compile
|
19
19
|
temp = @template.dup
|
20
20
|
start_heredoc = "T" << Digest::SHA1.hexdigest(temp)
|
21
|
-
start_heredoc, end_heredoc = "\n<<#{start_heredoc}\n", "\n#{start_heredoc}\n"
|
21
|
+
start_heredoc, end_heredoc = "\n<<#{start_heredoc}.chomp\n", "\n#{start_heredoc}\n"
|
22
22
|
bufadd = "_out_ << "
|
23
23
|
|
24
24
|
temp.gsub!(/<\?r\s+(.*?)\s+\?>/m,
|
data/lib/innate/view/none.rb
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
<p>#{ @content }</p>
|
@@ -38,25 +38,25 @@ end
|
|
38
38
|
describe Innate::Helper::Aspect do
|
39
39
|
behaves_like :mock
|
40
40
|
|
41
|
-
|
41
|
+
it 'executes before aspect' do
|
42
42
|
$aspect_spec_before = 0
|
43
43
|
get('/with_before').body.should == '42'
|
44
44
|
$aspect_spec_before.should == 42
|
45
45
|
end
|
46
46
|
|
47
|
-
|
47
|
+
it 'executes after asepct' do
|
48
48
|
$aspect_spec_after = 0
|
49
49
|
get('/with_after').body.should == '2'
|
50
50
|
$aspect_spec_after.should == 42
|
51
51
|
end
|
52
52
|
|
53
|
-
|
53
|
+
it 'executes wrap aspects' do
|
54
54
|
$aspect_spec_wrap = 0
|
55
55
|
get('/with_wrap').body.should == '22'
|
56
56
|
$aspect_spec_wrap == 42
|
57
57
|
end
|
58
58
|
|
59
|
-
|
59
|
+
it 'calls before_all and after_all' do
|
60
60
|
$aspect_spec_before_all = $aspect_spec_after_all = 0
|
61
61
|
get('/all/before_first').body.should == '42'
|
62
62
|
$aspect_spec_before_all.should == 42
|
@@ -66,10 +66,10 @@ describe Innate::Helper::Aspect do
|
|
66
66
|
$aspect_spec_after_all.should == 80
|
67
67
|
end
|
68
68
|
|
69
|
-
|
69
|
+
it 'makes instance variables in blocks available to view/method' do
|
70
70
|
get('/with_instance_var').body.should == 'Hello World'
|
71
71
|
get('/all/with_instance_var_first').body.should == 'Hello World'
|
72
72
|
get('/all/with_instance_var_second').body.should == 'Hello to the World'
|
73
|
-
get('/without_method/aspect_hello').body.should == "Hello World
|
73
|
+
get('/without_method/aspect_hello').body.should == "Hello World!"
|
74
74
|
end
|
75
75
|
end
|
data/spec/innate/helper/flash.rb
CHANGED
@@ -63,11 +63,11 @@ describe Innate::Helper::Flash do
|
|
63
63
|
session do |mock|
|
64
64
|
mock.get('/welcome').body.should == 'Welcome manveru'
|
65
65
|
mock.get('/bye').body.should == 'Bye manveru'
|
66
|
-
mock.get('/bye').body.should == 'Bye
|
66
|
+
mock.get('/bye').body.should == 'Bye'
|
67
67
|
|
68
68
|
mock.get('/welcome').body.should == 'Welcome manveru'
|
69
69
|
mock.get('/bye').body.should == 'Bye manveru'
|
70
|
-
mock.get('/bye').body.should == 'Bye
|
70
|
+
mock.get('/bye').body.should == 'Bye'
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
@@ -75,11 +75,11 @@ describe Innate::Helper::Flash do
|
|
75
75
|
session do |mock|
|
76
76
|
mock.get('/welcome').body.should == 'Welcome manveru'
|
77
77
|
mock.get('/sub/bye').body.should == 'Bye manveru'
|
78
|
-
mock.get('/sub/bye').body.should == 'Bye
|
78
|
+
mock.get('/sub/bye').body.should == 'Bye'
|
79
79
|
|
80
80
|
mock.get('/sub/welcome').body.should == 'Welcome manveru'
|
81
81
|
mock.get('/bye').body.should == 'Bye manveru'
|
82
|
-
mock.get('/bye').body.should == 'Bye
|
82
|
+
mock.get('/bye').body.should == 'Bye'
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
@@ -100,14 +100,14 @@ describe Innate::Helper::Flash do
|
|
100
100
|
should 'set and delete key over two request' do
|
101
101
|
session do |mock|
|
102
102
|
mock.get('/welcome').body.should == 'Welcome manveru'
|
103
|
-
mock.get('/delete_key').body.should == 'Bye
|
103
|
+
mock.get('/delete_key').body.should == 'Bye'
|
104
104
|
end
|
105
105
|
end
|
106
106
|
|
107
107
|
should 'merge with hash' do
|
108
108
|
session do |mock|
|
109
109
|
mock.get('/merge').body.should == {:name => 'feagliir'}.inspect
|
110
|
-
mock.get('/bye').body.should == 'Bye
|
110
|
+
mock.get('/bye').body.should == 'Bye'
|
111
111
|
end
|
112
112
|
end
|
113
113
|
|
@@ -0,0 +1,157 @@
|
|
1
|
+
require 'spec/helper'
|
2
|
+
|
3
|
+
class SpecHelperRenderFull
|
4
|
+
Innate.node '/render_full'
|
5
|
+
|
6
|
+
def foo
|
7
|
+
"foo: %p" % [request.params.sort]
|
8
|
+
end
|
9
|
+
|
10
|
+
def standard
|
11
|
+
render_full(r(:foo))
|
12
|
+
end
|
13
|
+
|
14
|
+
def with_query
|
15
|
+
render_full(r(:foo), 'a' => 'b')
|
16
|
+
end
|
17
|
+
|
18
|
+
def with_session
|
19
|
+
render_full(r(:get_session, :user))
|
20
|
+
end
|
21
|
+
|
22
|
+
def get_session(key)
|
23
|
+
session[key].inspect
|
24
|
+
end
|
25
|
+
|
26
|
+
def set_session(key, value)
|
27
|
+
session[key] = value
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class SpecHelperRenderPartial
|
32
|
+
Innate.node '/render_partial'
|
33
|
+
|
34
|
+
layout :layout
|
35
|
+
|
36
|
+
def standard
|
37
|
+
'hello'
|
38
|
+
end
|
39
|
+
|
40
|
+
def layout
|
41
|
+
'{ #{@content} }'
|
42
|
+
end
|
43
|
+
|
44
|
+
def without_layout
|
45
|
+
render_partial(:standard)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
class SpecHelperRenderView
|
50
|
+
Innate.node '/render_view'
|
51
|
+
map_views '/'
|
52
|
+
|
53
|
+
layout :layout
|
54
|
+
|
55
|
+
def standard
|
56
|
+
'hello'
|
57
|
+
end
|
58
|
+
|
59
|
+
def layout
|
60
|
+
'{ #{@content} }'
|
61
|
+
end
|
62
|
+
|
63
|
+
def without_method_or_layout
|
64
|
+
render_view(:num, :n => 42)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
class SpecHelperRenderTemplate
|
69
|
+
Innate.node '/render_template'
|
70
|
+
|
71
|
+
def relative
|
72
|
+
render_template('spec/innate/helper/view/num.xhtml', :n => 42)
|
73
|
+
end
|
74
|
+
|
75
|
+
def absolute
|
76
|
+
path = File.join(File.dirname(__FILE__), 'view/num.xhtml')
|
77
|
+
render_template(path, :n => 42)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
class SpecHelperRenderMisc
|
82
|
+
Innate.node '/misc'
|
83
|
+
map_views '/'
|
84
|
+
|
85
|
+
def recursive
|
86
|
+
@n ||= 1
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe Innate::Helper::Render do
|
91
|
+
describe '#render_full' do
|
92
|
+
behaves_like :mock, :session
|
93
|
+
|
94
|
+
it 'renders a full action' do
|
95
|
+
get('/render_full/standard').body.should == 'foo: []'
|
96
|
+
end
|
97
|
+
|
98
|
+
it 'renders full action with query parameters' do
|
99
|
+
get('/render_full/with_query').body.should == 'foo: [["a", "b"]]'
|
100
|
+
end
|
101
|
+
|
102
|
+
# this is an edge-case, we don't have a full session running if this is the
|
103
|
+
# first request from the client as Innate creates sessions only on demand
|
104
|
+
# at the end of the request/response cycle.
|
105
|
+
#
|
106
|
+
# So we have to make some request first, in this case we simply set some
|
107
|
+
# value in the session that we can get afterwards.
|
108
|
+
|
109
|
+
it 'renders full action inside a session' do
|
110
|
+
session do |mock|
|
111
|
+
mock.get('/render_full/set_session/user/manveru')
|
112
|
+
mock.get('/render_full/with_session').body.should == '"manveru"'
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
describe '#render_partial' do
|
118
|
+
behaves_like :mock
|
119
|
+
|
120
|
+
it 'renders action with layout' do
|
121
|
+
get('/render_partial/standard').body.should == '{ hello }'
|
122
|
+
end
|
123
|
+
|
124
|
+
it 'renders partial action without layout' do
|
125
|
+
get('/render_partial/without_layout').body.should == '{ hello }'
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
describe '#render_view' do
|
130
|
+
behaves_like :mock
|
131
|
+
|
132
|
+
it 'renders action without calling the method or applying layout' do
|
133
|
+
get('/render_view/without_method_or_layout').body.should == '{ 42 }'
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
describe '#render_template' do
|
138
|
+
behaves_like :mock
|
139
|
+
|
140
|
+
it 'renders action with the given template file' do
|
141
|
+
get('/render_template/relative').body.should == '42'
|
142
|
+
get('/render_template/absolute').body.should == '42'
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
describe 'misc functionality' do
|
147
|
+
behaves_like :mock
|
148
|
+
|
149
|
+
it 'can render_partial in a loop' do
|
150
|
+
get('/misc/loop').body.scan(/\d+/).should == %w[1 2 3 4 5]
|
151
|
+
end
|
152
|
+
|
153
|
+
it 'can recursively render_partial' do
|
154
|
+
get('/misc/recursive').body.scan(/\S/).join.should == '{1{2{3{44}3}2}1}'
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
#{@foo} #{@bar}!
|
@@ -0,0 +1 @@
|
|
1
|
+
#{say}, #{to}!
|
@@ -0,0 +1 @@
|
|
1
|
+
#{@n}
|
@@ -0,0 +1 @@
|
|
1
|
+
From Partial #{@here}
|
data/spec/innate/node/node.rb
CHANGED
@@ -4,8 +4,6 @@ Innate.options.merge!(:views => 'view', :layouts => 'view')
|
|
4
4
|
|
5
5
|
class SpecNode
|
6
6
|
Innate.node('/')
|
7
|
-
provide(:html, :ERB)
|
8
|
-
provide(:erb, :None)
|
9
7
|
|
10
8
|
def foo; end
|
11
9
|
def bar; end
|
@@ -18,24 +16,18 @@ end
|
|
18
16
|
class SpecNodeProvide
|
19
17
|
Innate.node('/provide')
|
20
18
|
|
21
|
-
provide(:html, :ERB)
|
22
|
-
provide(:erb, :None)
|
23
|
-
|
24
19
|
def foo
|
25
|
-
'
|
20
|
+
'#{21 * 2}'
|
26
21
|
end
|
27
22
|
|
28
23
|
def bar
|
29
|
-
'
|
24
|
+
'#{84 / 2}'
|
30
25
|
end
|
31
26
|
end
|
32
27
|
|
33
28
|
class SpecNodeProvideTemplate
|
34
29
|
Innate.node('/provide_template')
|
35
30
|
|
36
|
-
provide :html, :ERB
|
37
|
-
provide :erb, :None
|
38
|
-
|
39
31
|
map_views '/'
|
40
32
|
end
|
41
33
|
|
@@ -64,7 +56,7 @@ class SpecNodeWithLayoutMethod < SpecNodeProvide
|
|
64
56
|
layout 'layout_method'
|
65
57
|
|
66
58
|
def layout_method
|
67
|
-
'<div class="content"
|
59
|
+
'<div class="content">#{@content}</div>'
|
68
60
|
end
|
69
61
|
end
|
70
62
|
|
@@ -96,14 +88,14 @@ describe 'Innate::Node' do
|
|
96
88
|
should 'wrap with layout' do
|
97
89
|
got = Innate::Mock.get('/layout/bar')
|
98
90
|
got.status.should == 200
|
99
|
-
got.body.should == %(<div class="content">42</div
|
91
|
+
got.body.should == %(<div class="content">42</div>)
|
100
92
|
got['Content-Type'].should == 'text/html'
|
101
93
|
end
|
102
94
|
|
103
95
|
should 'find layout with view_root' do
|
104
96
|
got = Innate::Mock.get('/another_layout/bar')
|
105
97
|
got.status.should == 200
|
106
|
-
got.body.should == %(<div class="content">\n 42\n</div
|
98
|
+
got.body.should == %(<div class="content">\n 42\n</div>)
|
107
99
|
got['Content-Type'].should == 'text/html'
|
108
100
|
end
|
109
101
|
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
<?r 10.times do |n| ?>#{n}<?r end ?>
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
<div class="content">#{@content}</div>
|
data/spec/innate/provides.rb
CHANGED
@@ -12,7 +12,7 @@ Innate.options.merge!(:views => 'provides', :layouts => 'provides')
|
|
12
12
|
class SpecNodeProvides
|
13
13
|
Innate.node '/'
|
14
14
|
|
15
|
-
provide(:html, :None)
|
15
|
+
provide(:html, :engine => :None)
|
16
16
|
provide(:yaml, :type => 'text/yaml'){|a,s| s.to_yaml }
|
17
17
|
provide(:json, :type => 'application/json'){|a,s| s.to_json }
|
18
18
|
|
@@ -31,7 +31,7 @@ class SpecNodeProvidesTemplates
|
|
31
31
|
|
32
32
|
provide(:yaml, :type => 'text/yaml'){|a,s| s.to_yaml }
|
33
33
|
provide(:json, :type => 'application/json'){|a,s| s.to_json }
|
34
|
-
provide(:txt, :engine => :
|
34
|
+
provide(:txt, :engine => :Etanni, :type => 'text/plain')
|
35
35
|
|
36
36
|
def list
|
37
37
|
@users = %w[starbucks apollo athena]
|
@@ -0,0 +1 @@
|
|
1
|
+
<ul><?r @users.each do |user| ?><li>#{user}</li><?r end ?></ul>
|
@@ -0,0 +1 @@
|
|
1
|
+
<?r @users.each do |user| ?>#{"#{user}\n"}<?r end ?>
|
data/spec/innate/state/fiber.rb
CHANGED
@@ -1,12 +1,13 @@
|
|
1
|
-
begin
|
2
|
-
require 'fiber'
|
3
|
-
rescue LoadError
|
4
|
-
exit
|
5
|
-
end
|
6
|
-
|
7
1
|
require 'spec/helper'
|
8
2
|
|
9
|
-
describe Innate::State::Fiber do
|
3
|
+
describe 'Innate::State::Fiber' do
|
4
|
+
begin
|
5
|
+
require 'fiber'
|
6
|
+
rescue LoadError
|
7
|
+
it('needs fiber'){ should.flunk('needed fiber') }
|
8
|
+
exit
|
9
|
+
end
|
10
|
+
|
10
11
|
F = Innate::State::Fiber
|
11
12
|
|
12
13
|
it 'sets value in current thread with #[]=' do
|