amrita2 1.9.6 → 2.0.0

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.
Files changed (112) hide show
  1. data/README +112 -0
  2. data/init.rb +6 -0
  3. data/lib/amrita2/gettext.rb +116 -0
  4. data/lib/amrita2/macro.rb +153 -0
  5. data/lib/amrita2/rails_bridge.rb +172 -26
  6. data/lib/amrita2/template.rb +2634 -234
  7. data/lib/amrita2/testsupport.rb +171 -0
  8. data/lib/amrita2/version.rb +3 -3
  9. data/lib/amrita2.rb +1 -0
  10. data/sample/depot/app/controllers/admin_controller.rb +59 -0
  11. data/sample/depot/app/controllers/application.rb +20 -0
  12. data/sample/depot/app/controllers/info_controller.rb +19 -0
  13. data/sample/depot/app/controllers/login_controller.rb +85 -0
  14. data/sample/depot/app/controllers/store_controller.rb +68 -0
  15. data/sample/depot/app/helpers/admin_helper.rb +7 -0
  16. data/sample/depot/app/helpers/application_helper.rb +10 -0
  17. data/sample/depot/app/helpers/ar_form.rb +169 -0
  18. data/sample/depot/app/helpers/form_tag.rb +24 -0
  19. data/sample/depot/app/helpers/info_helper.rb +7 -0
  20. data/sample/depot/app/helpers/standard_form.rb +73 -0
  21. data/sample/depot/app/helpers/store_helper.rb +14 -0
  22. data/sample/depot/app/models/cart.rb +36 -0
  23. data/sample/depot/app/models/cart_item.rb +26 -0
  24. data/sample/depot/app/models/line_item.rb +34 -0
  25. data/sample/depot/app/models/order.rb +57 -0
  26. data/sample/depot/app/models/product.rb +41 -0
  27. data/sample/depot/app/models/user.rb +83 -0
  28. data/sample/depot/config/boot.rb +49 -0
  29. data/sample/depot/config/environment.rb +83 -0
  30. data/sample/depot/config/environments/development.rb +24 -0
  31. data/sample/depot/config/environments/production.rb +24 -0
  32. data/sample/depot/config/environments/test.rb +24 -0
  33. data/sample/depot/config/routes.rb +10 -0
  34. data/sample/depot/db/migrate/001_create_products.rb +18 -0
  35. data/sample/depot/db/migrate/002_add_price.rb +14 -0
  36. data/sample/depot/db/migrate/003_add_test_data.rb +68 -0
  37. data/sample/depot/db/migrate/004_add_sessions.rb +20 -0
  38. data/sample/depot/db/migrate/005_create_orders.rb +21 -0
  39. data/sample/depot/db/migrate/006_create_line_items.rb +27 -0
  40. data/sample/depot/db/migrate/007_create_users.rb +18 -0
  41. data/sample/depot/db/schema.rb +45 -0
  42. data/sample/depot/public/dispatch.rb +15 -0
  43. data/sample/depot/test/functional/admin_controller_test.rb +54 -0
  44. data/sample/depot/test/functional/info_controller_test.rb +23 -0
  45. data/sample/depot/test/functional/login_controller_test.rb +74 -0
  46. data/sample/depot/test/functional/store_controller_test.rb +57 -0
  47. data/sample/depot/test/integration/dsl_user_stories_test.rb +126 -0
  48. data/sample/depot/test/integration/user_stories_test.rb +70 -0
  49. data/sample/depot/test/performance/order_speed_test.rb +58 -0
  50. data/sample/depot/test/test_helper.rb +16 -0
  51. data/sample/depot/test/unit/cart_test.rb +39 -0
  52. data/sample/depot/test/unit/cart_test1.rb +31 -0
  53. data/sample/depot/test/unit/line_item_test.rb +15 -0
  54. data/sample/depot/test/unit/order_test.rb +15 -0
  55. data/sample/depot/test/unit/product_test.rb +98 -0
  56. data/sample/depot/vendor/plugins/amrita2/init.rb +6 -0
  57. data/sample/hello/hello.rb +22 -0
  58. data/sample/login_engine/app/controllers/application.rb +16 -0
  59. data/sample/login_engine/app/controllers/user_controller.rb +265 -0
  60. data/sample/login_engine/app/helpers/application_helper.rb +3 -0
  61. data/sample/login_engine/app/helpers/form_tag.rb +16 -0
  62. data/sample/login_engine/app/helpers/two_columns.rb +24 -0
  63. data/sample/login_engine/app/helpers/two_columns_form.rb +47 -0
  64. data/sample/login_engine/app/helpers/user_helper.rb +88 -0
  65. data/sample/login_engine/app/models/user.rb +7 -0
  66. data/sample/login_engine/app/models/user_notify.rb +75 -0
  67. data/sample/login_engine/config/boot.rb +45 -0
  68. data/sample/login_engine/config/environment.rb +140 -0
  69. data/sample/login_engine/config/environments/development.rb +21 -0
  70. data/sample/login_engine/config/environments/production.rb +18 -0
  71. data/sample/login_engine/config/environments/test.rb +19 -0
  72. data/sample/login_engine/config/routes.rb +23 -0
  73. data/sample/login_engine/db/migrate/001_create_users.rb +25 -0
  74. data/sample/login_engine/db/schema.rb +25 -0
  75. data/sample/login_engine/lib/config.rb +113 -0
  76. data/sample/login_engine/lib/hpricot_test_extension.rb +80 -0
  77. data/sample/login_engine/lib/login_engine/authenticated_system.rb +113 -0
  78. data/sample/login_engine/lib/login_engine/authenticated_user.rb +155 -0
  79. data/sample/login_engine/lib/login_engine.rb +62 -0
  80. data/sample/login_engine/public/dispatch.rb +10 -0
  81. data/sample/login_engine/test/functional/amrita2_test.rb +267 -0
  82. data/sample/login_engine/test/functional/user_controller_test.rb +544 -0
  83. data/sample/login_engine/test/mocks/mail.rb +14 -0
  84. data/sample/login_engine/test/mocks/time.rb +19 -0
  85. data/sample/login_engine/test/test_helper.rb +31 -0
  86. data/sample/login_engine/test/unit/user_test.rb +116 -0
  87. data/sample/login_engine/vendor/plugins/amrita2/init.rb +6 -0
  88. data/specs/attribute.rb +201 -0
  89. data/specs/datatypes.rb +231 -0
  90. data/specs/dictionary.rb +68 -0
  91. data/specs/erb_cdata.rb +187 -0
  92. data/specs/filters.rb +513 -0
  93. data/specs/gettext/erb_gettext.rb +42 -0
  94. data/specs/gettext/gettext_util.rb +65 -0
  95. data/specs/gettext/static_text.rb +103 -0
  96. data/specs/impl/code_generator.rb +87 -0
  97. data/specs/impl/dynamic_element.rb +92 -0
  98. data/specs/impl/hash_delegator.rb +57 -0
  99. data/specs/impl/parse_opt.rb +34 -0
  100. data/specs/impl/preprocess.rb +823 -0
  101. data/specs/impl/testsupport.rb +89 -0
  102. data/specs/inlineruby.rb +429 -0
  103. data/specs/intro.rb +654 -0
  104. data/specs/loop.rb +203 -0
  105. data/specs/macro.rb +532 -0
  106. data/specs/sample.rb +34 -0
  107. data/specs/sanitize.rb +110 -0
  108. data/specs/template.rb +189 -0
  109. data/specs/trace.rb +97 -0
  110. metadata +138 -19
  111. data/lib/amrita2/core.rb +0 -1897
  112. data/lib/amrita2/rd.rb +0 -314
@@ -0,0 +1,89 @@
1
+
2
+ require 'amrita2'
3
+ require 'amrita2/testsupport'
4
+
5
+ context "normalize xml"do
6
+ include Amrita2::TestSupport
7
+
8
+ specify "single tag" do
9
+ normalize("<img />").should == '<img />'
10
+ normalize("<a />").should == '<a />'
11
+ end
12
+
13
+ specify "single tag with attributes" do
14
+ normalize("<a aaa='aaa' bbb='bbb'/>").should == '<a aaa="aaa" bbb="bbb" />'
15
+ normalize("<a bbb='bbb' aaa='aaa'/>").should == '<a aaa="aaa" bbb="bbb" />'
16
+ end
17
+
18
+ specify "tag with text" do
19
+ normalize("<a>xx</a>").should == "<a>\nxx\n</a>"
20
+ end
21
+
22
+ specify "nested tag" do
23
+ normalize("<a><img></a>").should == "<a>\n<img />\n</a>"
24
+ end
25
+
26
+ specify "nested tag with text" do
27
+ normalize("<a><_>xx</_></a>").should == "<a>\n<_>\nxx\n</_>\n</a>"
28
+ end
29
+
30
+ specify "text" do
31
+ normalize("abc").should == "abc"
32
+ normalize(" abc ").should == "abc"
33
+ normalize(" \n abc \n ").should == "abc"
34
+ normalize(" \n abc \n abc").should == "abc abc"
35
+ normalize(" \n a b c \n a b c\n").should == "a b c a b c"
36
+ normalize("<a> \n a b c \n a b c\n</a>\n").should == "<a>\na b c a b c\n</a>"
37
+ end
38
+
39
+ specify "single tag with space" do
40
+ normalize('<_ am:src="title" />').should == '<_ am:src="title" />'
41
+ normalize(" <_ am:src='title' /> \n").should == '<_ am:src="title">'
42
+ end
43
+ end
44
+
45
+
46
+ context "should_same_xml_as" do
47
+
48
+ specify "xml" do
49
+ a = "<div class='aaa'><a href='bbb' title='ccc'>ddd</a></div>"
50
+ b = "<div class='aaa'><a href='bbb' title='ccc'>ddd</a></div>"
51
+ a.should_be_samexml_as b
52
+ Amrita2::SanitizedString[a].should_be_samexml_as b
53
+ end
54
+
55
+ specify "change order of attributes" do
56
+ a = "<div class='aaa'><a href='bbb' title='ccc'>ddd</a></div>"
57
+ a.should_be_samexml_as "<div class='aaa'><a title='ccc' href='bbb' >ddd</a></div>"
58
+ end
59
+
60
+ specify "add extra spaces" do
61
+ a = "<div class='aaa'> <a href='bbb' title='ccc'>\nddd</a>\n</div>"
62
+ b = "<div class='aaa'>\n<a href='bbb' title='ccc'>\nddd</a></div>"
63
+ a.should_be_samexml_as b
64
+ end
65
+
66
+ specify "ignore space between tags" do
67
+ a = "<ul><li>1</li><li>2</li></ul>"
68
+ b = "<ul><li>1</li> <li>2</li></ul>"
69
+ a.should_be_samexml_as b
70
+ end
71
+
72
+ specify "ignore space before tags" do
73
+ a = "\n aaa<span>bbb</san>ccc \n"
74
+ b = "aaa<span>bbb</san>ccc"
75
+ a.should_be_samexml_as b
76
+
77
+ a = Amrita2::SanitizedString["\nhook can write to stream direct<div>hook can render self</div>and add anything after that\n"]
78
+ b = "hook can write to stream direct<div>hook can render self</div>and add anything after that"
79
+ a.should_be_samexml_as b
80
+ end
81
+
82
+ specify "ignore newlines" do
83
+ a = "<th rowspan=\"2\">Red<br></br>eyes </th>"
84
+ b = "<th rowspan=\"2\">Red<br />eyes</th>"
85
+ a.should_be_samexml_as b
86
+ end
87
+
88
+ end
89
+
@@ -0,0 +1,429 @@
1
+
2
+ require 'rexml/document'
3
+ require 'amrita2'
4
+ require 'amrita2/testsupport'
5
+
6
+ include Amrita2
7
+ include Amrita2::Filters
8
+ include Amrita2::Runtime
9
+
10
+
11
+ context "Inline Ruby" do
12
+ include Amrita2::Runtime
13
+ specify "set context value" do
14
+ text = <<-END
15
+ <div>
16
+ <%
17
+ $_ = { :aaa => "abc" + a }
18
+ %>
19
+ <span am:src="aaa">abc</span>
20
+ </div>
21
+ END
22
+ t = Amrita2::Template.new(text, :inline_ruby)
23
+ a = "xyz"
24
+ t.test_with(binding) do |result|
25
+ result.should_be_samexml_as("<div>abcxyz</div>")
26
+ end
27
+ end
28
+
29
+ specify "with cdata" do
30
+ text = <<-'END'
31
+ <div>
32
+ <%
33
+ $_ = { :aaa => SanitizedString["<em>#{a}</em>"] }
34
+ %>
35
+ <span am:src="aaa">abc</span>
36
+ </div>
37
+ END
38
+ t = Amrita2::Template.new(text, :inline_ruby)
39
+ a = "xyz"
40
+ t.test_with(binding) do |result|
41
+ result.should_be_samexml_as("<div><em>xyz</em></div>")
42
+ end
43
+ end
44
+
45
+ specify "with an array of struct" do
46
+ text = <<-'END'
47
+ <ul>
48
+ <li am:for="data" am:skipif='$_.name !~ /amrita/'>
49
+ <%
50
+ $_ = {
51
+ :url => "http://raa.ruby-lang.org/list.rhtml?name=#{$_.name}",
52
+ :description => ($_.description or $_.name)
53
+ }
54
+ %>
55
+ <a am:filter='Attr[:href=>:url, :body=>:description]'/>
56
+ </li>
57
+ </ul>
58
+ END
59
+ s = Struct.new(:name, :description)
60
+ data = [
61
+ s.new('amrita', 'Amrita template library'),
62
+ s.new('amrita2'),
63
+ s.new('Ruby on Rails', 'this will be passed'),
64
+ ]
65
+ t = Amrita2::Template.new(text)
66
+ t.inline_ruby = true
67
+ t.test_with(binding) do |result|
68
+ result.should_be_samexml_as <<-END
69
+ <ul>
70
+ <li>
71
+ <a href='http://raa.ruby-lang.org/list.rhtml?name=amrita'>Amrita template library</a>
72
+ </li>
73
+ <li>
74
+ <a href='http://raa.ruby-lang.org/list.rhtml?name=amrita2'>amrita2</a>
75
+ </li>
76
+ </ul>
77
+ END
78
+ end
79
+ end
80
+
81
+ specify "with erb" do
82
+ text = <<-'END'
83
+ <ul>
84
+ <li am:for="data" am:skipif='$_.name !~ /amrita/'>
85
+ <![CDATA[
86
+ <%
87
+ name = $_.name
88
+ description = ($_.description or $_.name)
89
+ %>
90
+ <a href="http://raa.ruby-lang.org/list.rhtml?name=<%= name %>"><%= description %></a>
91
+ ]]>
92
+ </li>
93
+ </ul>
94
+ END
95
+ s = Struct.new(:name, :description)
96
+ data = [
97
+ s.new('amrita', 'Amrita template library'),
98
+ s.new('amrita2'),
99
+ s.new('Ruby on Rails', 'this will be passed'),
100
+ ]
101
+ t = Amrita2::Template.new(text)
102
+ t.inline_ruby = true
103
+ t.test_with(binding) do |result|
104
+ result.should_be_samexml_as <<-END
105
+ <ul>
106
+ <li>
107
+ <a href='http://raa.ruby-lang.org/list.rhtml?name=amrita'>Amrita template library</a>
108
+ </li>
109
+ <li>
110
+ <a href='http://raa.ruby-lang.org/list.rhtml?name=amrita2'>amrita2</a>
111
+ </li>
112
+ </ul>
113
+ END
114
+ end
115
+ end
116
+ end
117
+
118
+ context "Logic IF" do
119
+ include Amrita2::Runtime
120
+ setup do
121
+ @t = Amrita2::Template.new('<span am:skipif="a == 1">abc</span>', :inline_ruby)
122
+ end
123
+
124
+ specify "if true" do
125
+ a = 1
126
+ @t.test_with(binding) do |result|
127
+ result.should_be_samexml_as("")
128
+ end
129
+ end
130
+
131
+ specify "false" do
132
+ a = 0
133
+ @t.test_with(binding) do |result|
134
+ result.should_be_samexml_as("abc")
135
+ end
136
+ end
137
+
138
+ specify "with loop" do
139
+ text = <<-END
140
+ <ul>
141
+ <li am:for="1..5" am:skipif="($_ % 2) == 0" />
142
+ </ul>
143
+ END
144
+ t = Amrita2::Template.new(text, :inline_ruby)
145
+ t.test_with(binding) do |result|
146
+ result.should_be_samexml_as("<ul><li>1</li><li>3</li><li>5</li></ul>")
147
+ end
148
+ end
149
+ end
150
+
151
+ context "Logic IF amxml" do
152
+ include Amrita2::Runtime
153
+
154
+ specify "if" do
155
+ t = Amrita2::Template.new('<<img src="aaa" ?[a == 1]>>')
156
+ a = 1
157
+ t.test_with(binding) do |result|
158
+ result.should_be_samexml_as("<img src='aaa' />")
159
+ end
160
+ a = 0
161
+ t.test_with(binding) do |result|
162
+ result.should_be_samexml_as("")
163
+ end
164
+ end
165
+
166
+ specify "unless" do
167
+ t = Amrita2::Template.new('<<img src="aaa" ?![a == 1]>>')
168
+ a = 0
169
+ t.test_with(binding) do |result|
170
+ result.should_be_samexml_as("<img src='aaa' />")
171
+ end
172
+ a = 1
173
+ t.test_with(binding) do |result|
174
+ result.should_be_samexml_as("")
175
+ end
176
+ end
177
+
178
+ specify "if" do
179
+ t = Amrita2::Template.new('<<a href="aaa":xxx ?[a == 1]>>')
180
+ xxx = "123"
181
+ a = 1
182
+ t.test_with(binding) do |result|
183
+ result.should_be_samexml_as("<a href='aaa'>123</a>")
184
+ end
185
+ a = 0
186
+ t.test_with(binding) do |result|
187
+ result.should_be_samexml_as("")
188
+ end
189
+ end
190
+
191
+ specify "with loop" do
192
+ text = <<-END
193
+ <ul>
194
+ <<li :list ?![($_ % 2) == 0] >>
195
+ </ul>
196
+ END
197
+ t = Amrita2::Template.new(text, :inline_ruby)
198
+ t.test_with(:list=>1..5) do |result|
199
+ result.should_be_samexml_as("<ul><li>1</li><li>3</li><li>5</li></ul>")
200
+ end
201
+
202
+ text = <<-END
203
+ <ul>
204
+ <<li :list ?[($_ % 2) == 0] >>
205
+ </ul>
206
+ END
207
+ t = Amrita2::Template.new(text, :inline_ruby)
208
+ t.test_with(:list=>1..5) do |result|
209
+ result.should_be_samexml_as("<ul><li>2</li><li>4</li></ul>")
210
+ end
211
+ end
212
+ end
213
+
214
+ context "Logic for" do
215
+ include Amrita2::Runtime
216
+ setup do
217
+ @t = Amrita2::Template.new('<div><span am:for="a" /></div>', :inline_ruby)
218
+ end
219
+
220
+ specify "0" do
221
+ a = []
222
+ @t.test_with(binding) do |result|
223
+ result.should_be_samexml_as("<div></div>")
224
+ end
225
+ end
226
+ specify "1" do
227
+ a = [1]
228
+ @t.test_with(binding) do |result|
229
+ result.should_be_samexml_as("<div>1</div>")
230
+ end
231
+ end
232
+
233
+ specify "3" do
234
+ a = [1, 2, 3]
235
+ @t.test_with(binding) do |result|
236
+ result.should_be_samexml_as("<div>123</div>")
237
+ end
238
+ end
239
+ end
240
+
241
+ context "Logic value" do
242
+ include Amrita2::Runtime
243
+ specify "1" do
244
+ t = Amrita2::Template.new('<div><span am:v="a * 2" /></div>', :inline_ruby)
245
+ a = 1
246
+ t.test_with(binding) do |result|
247
+ result.should_be_samexml_as("<div>2</div>")
248
+ end
249
+ end
250
+
251
+ specify "method call" do
252
+ t = Amrita2::Template.new('<div><span am:v="aaa(a)" /></div>', :inline_ruby)
253
+ a = 123
254
+ t.test_with(binding) do |result|
255
+ result.should_be_samexml_as("<div>246</div>")
256
+ end
257
+ end
258
+
259
+ def aaa(x)
260
+ x*2
261
+ end
262
+
263
+ specify "filter" do
264
+ t = Amrita2::Template.new('<div><span am:src="a" am:v="$_ * 2" /></div>')
265
+ t.inline_ruby = true
266
+ a = 1
267
+ t.test_with(binding) do |result|
268
+ result.should_be_samexml_as("<div>2</div>")
269
+ end
270
+ a = "abc"
271
+ t.test_with(binding) do |result|
272
+ result.should_be_samexml_as("<div>abcabc</div>")
273
+ end
274
+ end
275
+
276
+ specify "quotation" do
277
+ t = Amrita2::Template.new(%[<div><span am:v=" 'abc' * a" /></div>], :inline_ruby)
278
+ a = 2
279
+ t.test_with(binding) do |result|
280
+ result.should_be_samexml_as("<div>abcabc</div>")
281
+ end
282
+
283
+ t = Amrita2::Template.new(%[<div><span am:v=' "abc" * a' /></div>], :inline_ruby)
284
+ a = 2
285
+ t.test_with(binding) do |result|
286
+ result.should_be_samexml_as("<div>abcabc</div>")
287
+ end
288
+ end
289
+
290
+ specify '#{ ...} in am:v' do
291
+ t = Amrita2::Template.new(%q[<div><span am:v=" %[#{a * 2}] " /></div>], :inline_ruby)
292
+ a = 2
293
+ t.test_with(binding) do |result|
294
+ result.should_be_samexml_as("<div>4</div>")
295
+ end
296
+ end
297
+
298
+ specify 'loop with if' do
299
+ t = Amrita2::Template.new <<-END
300
+ <<ul<
301
+ << [1..5] <
302
+ << ?[ ($_%2) == 0] <
303
+ <<li<
304
+ <%= $_ %>
305
+ END
306
+ t.test_with(binding) do |result|
307
+ result.should_be_samexml_as <<-END
308
+ <ul><li>2</li><li>4</li></ul>
309
+ END
310
+ end
311
+ end
312
+
313
+ specify 'all' do
314
+ t = Amrita2::Template.new <<-END
315
+ <<ul<
316
+ << [1..5] <
317
+ << ?[ ($_%2) == 0] <
318
+ << { :no => $_, :no2 => $_ ,:square=> $_*$_ }<
319
+ <<li<
320
+ <<:no>> * <<:no2>> = <<:square>>
321
+ END
322
+ t.test_with(binding) do |result|
323
+ result.should_be_samexml_as <<-END
324
+ <ul>
325
+ <li>2 * 2 = 4</li>
326
+ <li>4 * 4 = 16</li>
327
+ </ul>
328
+ END
329
+ end
330
+ end
331
+
332
+ specify 'all various format' do
333
+ t = Amrita2::Template.new <<-END
334
+ <<ul<
335
+ <<
336
+ [1..6] <
337
+ <<?[ ($_%2) == 0
338
+
339
+ ] <
340
+ << {
341
+ :no => $_,
342
+ :no2 => $_,
343
+ :square=> $_*$_
344
+ } <
345
+
346
+ <<li<
347
+ <<:no>> * <<:no2>> = <<:square>>
348
+ END
349
+ t.test_with(binding) do |result|
350
+ result.should_be_samexml_as <<-END
351
+ <ul>
352
+ <li>2 * 2 = 4</li>
353
+ <li>4 * 4 = 16</li>
354
+ <li>6 * 6 = 36</li>
355
+ </ul>
356
+ END
357
+ end
358
+ end
359
+ end
360
+
361
+ context "quotes in erb" do
362
+ include Amrita2::Runtime
363
+ specify "double quote" do
364
+ text = %q[<%= "#{1+2}" %>]
365
+ t = Amrita2::Template.new(text)
366
+ t.test_with(binding) do |result|
367
+ result.should_be_samexml_as("3")
368
+ end
369
+ end
370
+
371
+ specify "making quote in erb" do
372
+ text = %q[<%%= "#{1+<%= 1+2 %>}" %>]
373
+ t = Amrita2::Template.new(text)
374
+ t.test_with(binding) do |result|
375
+ result.should_be_samexml_as(%q[ <%= "#{1+3}" %> ])
376
+ t = Amrita2::Template.new(result)
377
+ t.test_with(binding) do |result|
378
+ result.should_be_samexml_as("4")
379
+ end
380
+ end
381
+ end
382
+ end
383
+
384
+ context "eval with " do
385
+ include Amrita2::Runtime
386
+ include Amrita2::Filters
387
+ specify "simple" do
388
+ text = <<-END
389
+ <<:people {
390
+ :name => "%s %s" % [$_.first, $_.last]
391
+ }<
392
+ Hello, <<:name>> <br />
393
+ END
394
+ t = Amrita2::Template.new(text)
395
+ People = Struct.new(:first, :last)
396
+ data = {
397
+ :people => [
398
+ People.new('Yukihiro', 'Matsumoto'),
399
+ People.new('Taku', 'Nakajima'),
400
+ ]
401
+ }
402
+ t.test_with(data, binding) do |result|
403
+ result.should_be_samexml_as <<-END
404
+ Hello, Yukihiro Matsumoto <br />
405
+ Hello, Taku Nakajima <br />
406
+ END
407
+ end
408
+ end
409
+ specify "simple with Hash" do
410
+ text = <<-END
411
+ <<:people {
412
+ :name => "%s %s" % [$_[:first], $_[:last]]
413
+ }<
414
+ Hello, <<:name>> <br />
415
+ END
416
+ t = Amrita2::Template.new(text)
417
+ data = {
418
+ :people => {
419
+ :first => 'Taku',
420
+ :last => 'Nakajima',
421
+ }
422
+ }
423
+ t.test_with(data, binding) do |result|
424
+ result.should_be_samexml_as <<-END
425
+ Hello, Taku Nakajima <br />
426
+ END
427
+ end
428
+ end
429
+ end