ramaze 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (174) hide show
  1. data/Rakefile +360 -0
  2. data/bin/ramaze +152 -0
  3. data/doc/CHANGELOG +2021 -0
  4. data/doc/COPYING +56 -0
  5. data/doc/COPYING.ja +51 -0
  6. data/doc/README +275 -0
  7. data/doc/TODO +33 -0
  8. data/doc/allison/LICENSE +184 -0
  9. data/doc/allison/README +37 -0
  10. data/doc/allison/allison.css +300 -0
  11. data/doc/allison/allison.gif +0 -0
  12. data/doc/allison/allison.js +307 -0
  13. data/doc/allison/allison.rb +287 -0
  14. data/doc/allison/cache/BODY +588 -0
  15. data/doc/allison/cache/CLASS_INDEX +4 -0
  16. data/doc/allison/cache/CLASS_PAGE +1 -0
  17. data/doc/allison/cache/FILE_INDEX +4 -0
  18. data/doc/allison/cache/FILE_PAGE +1 -0
  19. data/doc/allison/cache/FONTS +1 -0
  20. data/doc/allison/cache/FR_INDEX_BODY +1 -0
  21. data/doc/allison/cache/IMGPATH +1 -0
  22. data/doc/allison/cache/INDEX +1 -0
  23. data/doc/allison/cache/JAVASCRIPT +307 -0
  24. data/doc/allison/cache/METHOD_INDEX +4 -0
  25. data/doc/allison/cache/METHOD_LIST +1 -0
  26. data/doc/allison/cache/SRC_PAGE +1 -0
  27. data/doc/allison/cache/STYLE +322 -0
  28. data/doc/allison/cache/URL +1 -0
  29. data/examples/blog/main.rb +16 -0
  30. data/examples/blog/public/screen.css +106 -0
  31. data/examples/blog/src/controller.rb +50 -0
  32. data/examples/blog/src/element.rb +53 -0
  33. data/examples/blog/src/model.rb +29 -0
  34. data/examples/blog/template/edit.xhtml +6 -0
  35. data/examples/blog/template/index.xhtml +24 -0
  36. data/examples/blog/template/new.xhtml +5 -0
  37. data/examples/blog/template/view.xhtml +15 -0
  38. data/examples/blog/test/tc_entry.rb +18 -0
  39. data/examples/caching.rb +23 -0
  40. data/examples/element.rb +40 -0
  41. data/examples/hello.rb +23 -0
  42. data/examples/simple.rb +60 -0
  43. data/examples/templates/template/external.haml +21 -0
  44. data/examples/templates/template/external.liquid +28 -0
  45. data/examples/templates/template/external.mab +27 -0
  46. data/examples/templates/template/external.rhtml +29 -0
  47. data/examples/templates/template/external.rmze +24 -0
  48. data/examples/templates/template_erubis.rb +50 -0
  49. data/examples/templates/template_haml.rb +48 -0
  50. data/examples/templates/template_liquid.rb +64 -0
  51. data/examples/templates/template_markaby.rb +52 -0
  52. data/examples/templates/template_ramaze.rb +49 -0
  53. data/examples/whywiki/main.rb +56 -0
  54. data/examples/whywiki/template/edit.xhtml +14 -0
  55. data/examples/whywiki/template/show.xhtml +17 -0
  56. data/lib/proto/conf/benchmark.yaml +35 -0
  57. data/lib/proto/conf/debug.yaml +34 -0
  58. data/lib/proto/conf/live.yaml +33 -0
  59. data/lib/proto/conf/silent.yaml +31 -0
  60. data/lib/proto/conf/stage.yaml +33 -0
  61. data/lib/proto/main.rb +18 -0
  62. data/lib/proto/public/404.jpg +0 -0
  63. data/lib/proto/public/css/coderay.css +105 -0
  64. data/lib/proto/public/css/ramaze_error.css +42 -0
  65. data/lib/proto/public/error.xhtml +74 -0
  66. data/lib/proto/public/favicon.ico +0 -0
  67. data/lib/proto/public/js/jquery.js +1923 -0
  68. data/lib/proto/public/ramaze.png +0 -0
  69. data/lib/proto/src/controller/main.rb +7 -0
  70. data/lib/proto/src/element/page.rb +16 -0
  71. data/lib/proto/src/model.rb +5 -0
  72. data/lib/proto/template/index.xhtml +6 -0
  73. data/lib/ramaze.rb +317 -0
  74. data/lib/ramaze/adapter/mongrel.rb +111 -0
  75. data/lib/ramaze/adapter/webrick.rb +161 -0
  76. data/lib/ramaze/cache.rb +11 -0
  77. data/lib/ramaze/cache/memcached.rb +52 -0
  78. data/lib/ramaze/cache/memory.rb +6 -0
  79. data/lib/ramaze/cache/yaml_store.rb +37 -0
  80. data/lib/ramaze/controller.rb +10 -0
  81. data/lib/ramaze/dispatcher.rb +315 -0
  82. data/lib/ramaze/error.rb +11 -0
  83. data/lib/ramaze/gestalt.rb +108 -0
  84. data/lib/ramaze/global.rb +120 -0
  85. data/lib/ramaze/helper.rb +32 -0
  86. data/lib/ramaze/helper/aspect.rb +189 -0
  87. data/lib/ramaze/helper/auth.rb +120 -0
  88. data/lib/ramaze/helper/cache.rb +52 -0
  89. data/lib/ramaze/helper/feed.rb +135 -0
  90. data/lib/ramaze/helper/form.rb +204 -0
  91. data/lib/ramaze/helper/link.rb +80 -0
  92. data/lib/ramaze/helper/redirect.rb +48 -0
  93. data/lib/ramaze/helper/stack.rb +67 -0
  94. data/lib/ramaze/http_status.rb +66 -0
  95. data/lib/ramaze/inform.rb +166 -0
  96. data/lib/ramaze/snippets.rb +5 -0
  97. data/lib/ramaze/snippets/hash/keys_to_sym.rb +19 -0
  98. data/lib/ramaze/snippets/kernel/aquire.rb +22 -0
  99. data/lib/ramaze/snippets/kernel/autoreload.rb +79 -0
  100. data/lib/ramaze/snippets/kernel/caller_lines.rb +58 -0
  101. data/lib/ramaze/snippets/kernel/constant.rb +24 -0
  102. data/lib/ramaze/snippets/kernel/rescue_require.rb +12 -0
  103. data/lib/ramaze/snippets/kernel/self_method.rb +41 -0
  104. data/lib/ramaze/snippets/kernel/silently.rb +13 -0
  105. data/lib/ramaze/snippets/object/traits.rb +60 -0
  106. data/lib/ramaze/snippets/openstruct/temp.rb +10 -0
  107. data/lib/ramaze/snippets/string/DIVIDE.rb +16 -0
  108. data/lib/ramaze/snippets/string/camel_case.rb +14 -0
  109. data/lib/ramaze/snippets/string/snake_case.rb +12 -0
  110. data/lib/ramaze/snippets/symbol/to_proc.rb +14 -0
  111. data/lib/ramaze/snippets/thread/deadQUESTIONMARK.rb +11 -0
  112. data/lib/ramaze/store/default.rb +48 -0
  113. data/lib/ramaze/template.rb +102 -0
  114. data/lib/ramaze/template/amrita2.rb +40 -0
  115. data/lib/ramaze/template/erubis.rb +58 -0
  116. data/lib/ramaze/template/haml.rb +65 -0
  117. data/lib/ramaze/template/haml/actionview_stub.rb +20 -0
  118. data/lib/ramaze/template/liquid.rb +74 -0
  119. data/lib/ramaze/template/markaby.rb +68 -0
  120. data/lib/ramaze/template/ramaze.rb +177 -0
  121. data/lib/ramaze/template/ramaze/element.rb +166 -0
  122. data/lib/ramaze/template/ramaze/morpher.rb +156 -0
  123. data/lib/ramaze/tool/create.rb +70 -0
  124. data/lib/ramaze/tool/tidy.rb +71 -0
  125. data/lib/ramaze/trinity.rb +38 -0
  126. data/lib/ramaze/trinity/request.rb +244 -0
  127. data/lib/ramaze/trinity/response.rb +41 -0
  128. data/lib/ramaze/trinity/session.rb +129 -0
  129. data/lib/ramaze/version.rb +14 -0
  130. data/spec/spec_all.rb +73 -0
  131. data/spec/spec_helper.rb +215 -0
  132. data/spec/tc_adapter_mongrel.rb +24 -0
  133. data/spec/tc_adapter_webrick.rb +22 -0
  134. data/spec/tc_cache.rb +79 -0
  135. data/spec/tc_controller.rb +39 -0
  136. data/spec/tc_element.rb +100 -0
  137. data/spec/tc_error.rb +23 -0
  138. data/spec/tc_gestalt.rb +90 -0
  139. data/spec/tc_global.rb +46 -0
  140. data/spec/tc_helper_aspect.rb +65 -0
  141. data/spec/tc_helper_auth.rb +61 -0
  142. data/spec/tc_helper_cache.rb +81 -0
  143. data/spec/tc_helper_feed.rb +129 -0
  144. data/spec/tc_helper_form.rb +146 -0
  145. data/spec/tc_helper_link.rb +58 -0
  146. data/spec/tc_helper_redirect.rb +51 -0
  147. data/spec/tc_helper_stack.rb +55 -0
  148. data/spec/tc_morpher.rb +90 -0
  149. data/spec/tc_params.rb +84 -0
  150. data/spec/tc_request.rb +111 -0
  151. data/spec/tc_session.rb +56 -0
  152. data/spec/tc_store.rb +25 -0
  153. data/spec/tc_template_amrita2.rb +34 -0
  154. data/spec/tc_template_erubis.rb +41 -0
  155. data/spec/tc_template_haml.rb +44 -0
  156. data/spec/tc_template_liquid.rb +98 -0
  157. data/spec/tc_template_markaby.rb +74 -0
  158. data/spec/tc_template_ramaze.rb +54 -0
  159. data/spec/tc_tidy.rb +14 -0
  160. data/spec/template/amrita2/data.html +6 -0
  161. data/spec/template/amrita2/index.html +1 -0
  162. data/spec/template/amrita2/sum.html +1 -0
  163. data/spec/template/erubis/sum.rhtml +1 -0
  164. data/spec/template/haml/index.haml +5 -0
  165. data/spec/template/haml/with_vars.haml +4 -0
  166. data/spec/template/liquid/index.liquid +1 -0
  167. data/spec/template/liquid/products.liquid +45 -0
  168. data/spec/template/markaby/external.mab +8 -0
  169. data/spec/template/markaby/sum.mab +1 -0
  170. data/spec/template/ramaze/file_only.rmze +1 -0
  171. data/spec/template/ramaze/index.rmze +1 -0
  172. data/spec/template/ramaze/nested.rmze +1 -0
  173. data/spec/template/ramaze/sum.rmze +1 -0
  174. metadata +317 -0
@@ -0,0 +1,129 @@
1
+ # Copyright (c) 2006 Michael Fellinger m.fellinger@gmail.com
2
+ # All files in this distribution are subject to the terms of the Ruby license.
3
+
4
+ require 'spec/spec_helper'
5
+
6
+ testcase_requires 'hpricot'
7
+
8
+ require 'ramaze/helper/feed'
9
+ require 'pp'
10
+
11
+ class String
12
+ def hpricot
13
+ Hpricot(self)
14
+ end
15
+ end
16
+
17
+ class With
18
+ class << self
19
+ def with(hash)
20
+ instance = self.new
21
+ hash.each do |key, value|
22
+ instance.send("#{key}=", value)
23
+ end
24
+ instance
25
+ end
26
+ end
27
+ end
28
+
29
+ include Ramaze
30
+
31
+ class Book < With
32
+ include ReFeed
33
+
34
+ attr_accessor :title, :content, :author, :isbn, :description
35
+
36
+ xml :title, :content, :type => :text
37
+ xml :isbn, :type => :attribute
38
+ xml :description, :type => :cdata
39
+ xml :author
40
+ end
41
+
42
+ class User < With
43
+ include ReFeed
44
+
45
+ xml_accessor :name, :email, :type => :text
46
+ xml_accessor :books
47
+ end
48
+
49
+ context "ReFeed" do
50
+ context "User" do
51
+ user = User.with :name => 'manveru', :email => 'foo@bar.com'
52
+
53
+ specify "to_xml" do
54
+ xml = ( user.to_xml.hpricot/:user )
55
+
56
+ xml.size.should == 1
57
+ xml.at('email').inner_html.should == user.email
58
+ xml.at('name').inner_html.should == user.name
59
+ end
60
+ end
61
+
62
+ context "Book" do
63
+ book = Book.with :title => 'foo', :content => 'bar',
64
+ :isbn => 123456789012, :description => 'The Best Foo in the world!'
65
+
66
+ specify "to_xml" do
67
+ xml = ( book.to_xml.hpricot/:book )
68
+
69
+ xml.size.should == 1
70
+
71
+ xml.first['isbn'].to_i.should == book.isbn
72
+
73
+ xml.at('description').to_plain_text.should == book.description
74
+ xml.at('title').inner_html.should == 'foo'
75
+ xml.at('content').inner_html.should == 'bar'
76
+ end
77
+ end
78
+
79
+ context "Book and User" do
80
+ user = User.with :name => 'manveru', :email => 'foo@bar.com'
81
+ book = Book.with :title => 'foo', :content => 'bar', :author => user
82
+
83
+ specify "to_xml" do
84
+ xml_book = ( book.to_xml.hpricot/:book )
85
+ xml_user = xml_book.at(:user)
86
+
87
+ xml_book.at('title').inner_html.should == book.title
88
+ xml_book.at('content').inner_html.should == book.content
89
+
90
+ xml_user.at('name').inner_html.should == user.name
91
+ xml_user.at('email').inner_html.should == user.email
92
+ end
93
+ end
94
+
95
+ context "User and books" do
96
+ book1 = Book.with :title => 'foo', :content => 'bar'
97
+ book2 = Book.with :title => 'foz', :content => 'baz'
98
+ user = User.with :name => 'manveru', :email => 'foo@bar.com',
99
+ :books => [book1, book2]
100
+
101
+ specify "to_xml" do
102
+ xml = ( user.to_xml.hpricot/:user )
103
+ books = ( xml/:book )
104
+ first = books.find{|a| a.at('title').inner_html == book1.title }
105
+ second = books.find{|a| a.at('title').inner_html == book2.title }
106
+
107
+ books.size.should == 2
108
+
109
+ xml.at('name').inner_html.should == user.name
110
+ xml.at('email').inner_html.should == user.email
111
+
112
+ first.at('title').inner_html.should == book1.title
113
+ first.at('content').inner_html.should == book1.content
114
+
115
+ second.at('title').inner_html.should == book2.title
116
+ second.at('content').inner_html.should == book2.content
117
+ end
118
+ end
119
+
120
+ context "User from XML" do
121
+ user = User.with :name => 'manveru', :email => 'foo@bar.com'
122
+
123
+ specify "from_xml" do
124
+ new_user = User.from_xml(user.to_xml)
125
+ new_user.name.should == user.name
126
+ new_user.email.should == user.email
127
+ end
128
+ end
129
+ end
@@ -0,0 +1,146 @@
1
+ # Copyright (c) 2006 Michael Fellinger m.fellinger@gmail.com
2
+ # All files in this distribution are subject to the terms of the Ruby license.
3
+
4
+ require 'spec/spec_helper'
5
+
6
+ testcase_requires 'og', 'glue/timestamped'
7
+
8
+ class Entry
9
+ attr_accessor :title, String
10
+ end
11
+
12
+ class EntryTimestamped
13
+ attr_accessor :title, String
14
+ is Timestamped
15
+ end
16
+
17
+ class EntryDated
18
+ attr_accessor :date, Date
19
+ end
20
+
21
+ # catches all the stuff Og sends to Logger,
22
+ # i wished on could mute it otherwise
23
+
24
+ gulp_class = Ramaze::GlobalInformer
25
+ Logger.send(:class_variable_set, "@@global_logger", gulp_class.new)
26
+
27
+ Og.start :destroy => true
28
+
29
+ include Ramaze
30
+
31
+ class TCFormHelperEntryController < Template::Ramaze
32
+ helper :form
33
+
34
+ def index
35
+ 'FormHelper Entry'
36
+ end
37
+
38
+ def form_with_submit
39
+ form Entry
40
+ end
41
+
42
+ def form_without_submit
43
+ form Entry, :submit => false
44
+ end
45
+
46
+ def form_with_title
47
+ form Entry, :title => 'Title'
48
+ end
49
+
50
+ def form_without_title
51
+ form Entry, :title => false
52
+ end
53
+
54
+ def form_with_oid
55
+ form Entry, :deny => nil
56
+ end
57
+ end
58
+
59
+ class TCFormHelperEntryTimestampedController < Template::Ramaze
60
+ helper :form
61
+
62
+ def index
63
+ "FormHelper EntryTimestamped"
64
+ end
65
+
66
+ def form_with_submit
67
+ form EntryTimestamped
68
+ end
69
+ end
70
+
71
+ class TCFormHelperEntryDated < Template::Ramaze
72
+ helper :form
73
+
74
+ def index
75
+ "FormHelper Dated"
76
+ end
77
+
78
+ def form_with_submit
79
+ form EntryDated
80
+ end
81
+ end
82
+
83
+ context "FormHelper" do
84
+ context "Entry" do
85
+ ramaze :mapping => {'/entry' => TCFormHelperEntryController}
86
+
87
+ specify "testrun" do
88
+ get('/entry/').should == 'FormHelper Entry'
89
+ end
90
+
91
+ specify "with submit" do
92
+ get('/entry/form_with_submit').should ==
93
+ %{title: <input type="text" name="title" value="" /><br />\n<input type="submit" />}
94
+ end
95
+
96
+ specify "without submit" do
97
+ get('/entry/form_without_submit').should ==
98
+ %{title: <input type="text" name="title" value="" />}
99
+ end
100
+
101
+ specify "with title" do
102
+ get('/entry/form_with_title').should ==
103
+ %{Title: <input type="text" name="title" value="" /><br />\n<input type="submit" />}
104
+ end
105
+
106
+ specify "without title" do
107
+ get('/entry/form_without_title').should ==
108
+ %{<input type="text" name="title" value="" /><br />\n<input type="submit" />}
109
+ end
110
+
111
+ specify "with oid" do
112
+ get('/entry/form_with_oid').should ==
113
+ %{title: <input type="text" name="title" value="" /><br />\noid: <input type="text" name="oid" value="0" /><br />\n<input type="submit" />}
114
+ end
115
+
116
+ context "EntryTimestamped" do
117
+ ramaze :fake_start => true, :mapping => {'/entry_timestamped' => TCFormHelperEntryTimestampedController}
118
+
119
+ specify "testrun" do
120
+ get('/entry_timestamped/').should == "FormHelper EntryTimestamped"
121
+ end
122
+
123
+ specify "with submit" do
124
+ get('/entry_timestamped/form_with_submit').should ==
125
+ "title: <input type=\"text\" name=\"title\" value=\"\" /><br />\n<input type=\"submit\" />"
126
+ end
127
+ end
128
+
129
+ context "EntryDated" do
130
+ ramaze :fake_start => true, :mapping => {'/entry_dated' => TCFormHelperEntryDated}
131
+
132
+ specify "testrun" do
133
+ get('/entry_dated').should ==
134
+ "FormHelper Dated"
135
+ end
136
+
137
+ specify "with submit" do
138
+ result = get('/entry_dated/form_with_submit')
139
+ result.should =~ /date\[day\]/
140
+ result.should =~ /date\[month\]/
141
+ result.should =~ /date\[year\]/
142
+ result.should =~ /<input type="submit" \/>/
143
+ end
144
+ end
145
+ end
146
+ end
@@ -0,0 +1,58 @@
1
+ # Copyright (c) 2006 Michael Fellinger m.fellinger@gmail.com
2
+ # All files in this distribution are subject to the terms of the Ruby license.
3
+
4
+ require 'spec/spec_helper'
5
+
6
+ include Ramaze
7
+
8
+ class TCLinkHelperController < Template::Ramaze
9
+ helper :link
10
+
11
+ def index
12
+ link self
13
+ end
14
+
15
+ def index_with_title
16
+ link self, :title => 'Foo'
17
+ end
18
+ end
19
+
20
+
21
+ context "LinkHelper" do
22
+ ramaze(:mapping => {'/' => TCLinkHelperController})
23
+
24
+ include Ramaze::LinkHelper
25
+
26
+ this = TCLinkHelperController
27
+
28
+ specify "testrun" do
29
+ get.should == %{<a href="/">index</a>}
30
+ get('/index_with_title').should == %{<a href="/">Foo</a>}
31
+ end
32
+
33
+ specify "link" do
34
+ link(:foo).should == %{<a href="foo">foo</a>}
35
+ link(:foo, :bar).should == %{<a href="foo/bar">bar</a>}
36
+ link(this, :bar).should == %{<a href="/bar">bar</a>}
37
+ link('/foo/bar').should == %{<a href="/foo/bar">bar</a>}
38
+ end
39
+
40
+ specify "link with title" do
41
+ link(:foo, :title => 'bar').should == %{<a href="foo">bar</a>}
42
+ end
43
+
44
+ specify "link with get-parameters" do
45
+ link(:foo, :first => :bar, :title => 'bar').should == %{<a href="foo?first=bar">bar</a>}
46
+ l = link(:foo, :first => :bar, :second => :foobar)
47
+ m = l.match(%r{<a href="foo\?(.*?)=(.*?);(.*?)=(.*?)">(.*?)</a>}).to_a
48
+ m.shift
49
+ m.pop.should == 'foo'
50
+ Hash[*m].should == {'first' => 'bar', 'second' => 'foobar'}
51
+ end
52
+
53
+ specify "R" do
54
+ R(this).should == '/'
55
+ R(this, :foo).should == '/foo'
56
+ R(this, :foo, :bar => :one).should == '/foo?bar=one'
57
+ end
58
+ end
@@ -0,0 +1,51 @@
1
+ # Copyright (c) 2006 Michael Fellinger m.fellinger@gmail.com
2
+ # All files in this distribution are subject to the terms of the Ruby license.
3
+
4
+ require 'spec/spec_helper'
5
+
6
+ include Ramaze
7
+
8
+ class TCRedirectHelperController < Template::Ramaze
9
+ helper :redirect
10
+
11
+ def index
12
+ self.class.name
13
+ end
14
+
15
+ def noop
16
+ 'noop'
17
+ end
18
+
19
+ def redirection
20
+ redirect :index
21
+ end
22
+
23
+ def double_redirection
24
+ redirect :redirection
25
+ end
26
+
27
+ def redirect_referer_action
28
+ redirect_referer
29
+ end
30
+ end
31
+
32
+ context "RedirectHelper" do
33
+ ramaze(:mapping => {'/' => TCRedirectHelperController})
34
+
35
+ ctx = Context.new
36
+
37
+ specify "testrun" do
38
+ ctx.get('/').should == "TCRedirectHelperController"
39
+ end
40
+
41
+ specify "calls" do
42
+ ctx.get('/redirection').should == "TCRedirectHelperController"
43
+ ctx.get('/double_redirection').should == "TCRedirectHelperController"
44
+ end
45
+
46
+ specify "redirect to referer" do
47
+ ctx.get('/redirect_referer_action').should == 'TCRedirectHelperController'
48
+ ctx.get('/noop').should == 'noop'
49
+ ctx.get('/redirect_referer_action').should == 'noop'
50
+ end
51
+ end
@@ -0,0 +1,55 @@
1
+ # Copyright (c) 2006 Michael Fellinger m.fellinger@gmail.com
2
+ # All files in this distribution are subject to the terms of the Ruby license.
3
+
4
+ require 'spec/spec_helper'
5
+
6
+ include Ramaze
7
+
8
+ class TCStackHelperController < Template::Ramaze
9
+ helper :stack
10
+
11
+ def index
12
+ session.inspect
13
+ end
14
+
15
+ def foo
16
+ call :login unless logged_in?
17
+ "logged in"
18
+ end
19
+
20
+ def bar
21
+ call :login unless logged_in?
22
+ request.params.inspect
23
+ end
24
+
25
+ def login
26
+ session[:logged_in] = true
27
+ answer
28
+ end
29
+
30
+ private
31
+
32
+ def logged_in?
33
+ session[:logged_in]
34
+ end
35
+ end
36
+
37
+ context "StackHelper" do
38
+ ramaze(:mapping => {'/' => TCStackHelperController})
39
+
40
+ ctx = Context.new
41
+
42
+ specify "indirect login" do
43
+ ctx.get('/foo').should == 'logged in'
44
+ ctx.eget('/').should == {:logged_in => true, :STACK => []}
45
+ end
46
+
47
+ specify "indirect login with params" do
48
+ ctx.eget('/bar?x=y').should == {'x' => 'y'}
49
+ ctx.eget('/').should == {:logged_in => true, :STACK => []}
50
+ end
51
+
52
+ specify "indirect posting fun" do
53
+ ctx.epost('/bar', :x => :y)['x'].should == 'y'
54
+ end
55
+ end
@@ -0,0 +1,90 @@
1
+ # Copyright (c) 2006 Michael Fellinger m.fellinger@gmail.com
2
+ # All files in this distribution are subject to the terms of the Ruby license.
3
+
4
+ require 'spec/spec_helper'
5
+
6
+ include Ramaze
7
+
8
+ begin
9
+ require 'hpricot'
10
+
11
+ class TCMorpherController < Template::Ramaze
12
+ def index
13
+ self.class.name
14
+ end
15
+
16
+ def simple_if(arg = nil)
17
+ @arg = arg
18
+ %q{
19
+ <p if="@arg.nil?">orig</p>
20
+ <p if="@arg">#{@arg}</p>
21
+ }.strip
22
+ end
23
+
24
+ def simple_unless(arg = nil)
25
+ @arg = arg
26
+ %q{
27
+ <p unless="@arg">orig</p>
28
+ <p unless="@arg.nil?">#{@arg}</p>
29
+ }.strip
30
+ end
31
+
32
+ def simple_for n = 1
33
+ @n = (0..n.to_i)
34
+ %q{
35
+ <div for="i in @n">#{i}</div>
36
+ }
37
+ end
38
+
39
+ def simple_times n = 1
40
+ @n = n.to_i
41
+ %q{
42
+ <div times="@n">#{_t}</div>
43
+ }
44
+ end
45
+
46
+ def simple_each *elem
47
+ @elem = elem
48
+ %q{
49
+ <div each="@elem">#{_e}</div>
50
+ }
51
+ end
52
+ end
53
+
54
+ context "Morpher" do
55
+ ramaze :mapping => {'/' => TCMorpherController}
56
+
57
+ specify "testrun" do
58
+ get('/').should == 'TCMorpherController'
59
+ end
60
+
61
+ specify "if" do
62
+ get('/simple_if').should == '<p>orig</p>'
63
+ get('/simple_if/bar').should == '<p>bar</p>'
64
+ end
65
+
66
+ specify "unless" do
67
+ get('/simple_unless').should == '<p>orig</p>'
68
+ get('/simple_unless/bar').should == '<p>bar</p>'
69
+ end
70
+
71
+ specify "for" do
72
+ get('/simple_for').should == "<div>0</div><div>1</div>"
73
+ get('/simple_for/3').should == "<div>0</div><div>1</div><div>2</div><div>3</div>"
74
+ end
75
+
76
+ specify "times" do
77
+ get('/simple_times').should == "<div>0</div>"
78
+ get('/simple_times/3').should == "<div>0</div><div>1</div><div>2</div>"
79
+ end
80
+
81
+ specify "each" do
82
+ get('/simple_each').should == ''
83
+ get('/simple_each/1/2/3').should == "<div>1</div><div>2</div><div>3</div>"
84
+ end
85
+ end
86
+
87
+ rescue LoadError => ex
88
+ puts ex
89
+ puts "Won't run #{__FILE__} unless you install hpricot"
90
+ end