amrita2 1.9.6 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +112 -0
- data/init.rb +6 -0
- data/lib/amrita2/gettext.rb +116 -0
- data/lib/amrita2/macro.rb +153 -0
- data/lib/amrita2/rails_bridge.rb +172 -26
- data/lib/amrita2/template.rb +2634 -234
- data/lib/amrita2/testsupport.rb +171 -0
- data/lib/amrita2/version.rb +3 -3
- data/lib/amrita2.rb +1 -0
- data/sample/depot/app/controllers/admin_controller.rb +59 -0
- data/sample/depot/app/controllers/application.rb +20 -0
- data/sample/depot/app/controllers/info_controller.rb +19 -0
- data/sample/depot/app/controllers/login_controller.rb +85 -0
- data/sample/depot/app/controllers/store_controller.rb +68 -0
- data/sample/depot/app/helpers/admin_helper.rb +7 -0
- data/sample/depot/app/helpers/application_helper.rb +10 -0
- data/sample/depot/app/helpers/ar_form.rb +169 -0
- data/sample/depot/app/helpers/form_tag.rb +24 -0
- data/sample/depot/app/helpers/info_helper.rb +7 -0
- data/sample/depot/app/helpers/standard_form.rb +73 -0
- data/sample/depot/app/helpers/store_helper.rb +14 -0
- data/sample/depot/app/models/cart.rb +36 -0
- data/sample/depot/app/models/cart_item.rb +26 -0
- data/sample/depot/app/models/line_item.rb +34 -0
- data/sample/depot/app/models/order.rb +57 -0
- data/sample/depot/app/models/product.rb +41 -0
- data/sample/depot/app/models/user.rb +83 -0
- data/sample/depot/config/boot.rb +49 -0
- data/sample/depot/config/environment.rb +83 -0
- data/sample/depot/config/environments/development.rb +24 -0
- data/sample/depot/config/environments/production.rb +24 -0
- data/sample/depot/config/environments/test.rb +24 -0
- data/sample/depot/config/routes.rb +10 -0
- data/sample/depot/db/migrate/001_create_products.rb +18 -0
- data/sample/depot/db/migrate/002_add_price.rb +14 -0
- data/sample/depot/db/migrate/003_add_test_data.rb +68 -0
- data/sample/depot/db/migrate/004_add_sessions.rb +20 -0
- data/sample/depot/db/migrate/005_create_orders.rb +21 -0
- data/sample/depot/db/migrate/006_create_line_items.rb +27 -0
- data/sample/depot/db/migrate/007_create_users.rb +18 -0
- data/sample/depot/db/schema.rb +45 -0
- data/sample/depot/public/dispatch.rb +15 -0
- data/sample/depot/test/functional/admin_controller_test.rb +54 -0
- data/sample/depot/test/functional/info_controller_test.rb +23 -0
- data/sample/depot/test/functional/login_controller_test.rb +74 -0
- data/sample/depot/test/functional/store_controller_test.rb +57 -0
- data/sample/depot/test/integration/dsl_user_stories_test.rb +126 -0
- data/sample/depot/test/integration/user_stories_test.rb +70 -0
- data/sample/depot/test/performance/order_speed_test.rb +58 -0
- data/sample/depot/test/test_helper.rb +16 -0
- data/sample/depot/test/unit/cart_test.rb +39 -0
- data/sample/depot/test/unit/cart_test1.rb +31 -0
- data/sample/depot/test/unit/line_item_test.rb +15 -0
- data/sample/depot/test/unit/order_test.rb +15 -0
- data/sample/depot/test/unit/product_test.rb +98 -0
- data/sample/depot/vendor/plugins/amrita2/init.rb +6 -0
- data/sample/hello/hello.rb +22 -0
- data/sample/login_engine/app/controllers/application.rb +16 -0
- data/sample/login_engine/app/controllers/user_controller.rb +265 -0
- data/sample/login_engine/app/helpers/application_helper.rb +3 -0
- data/sample/login_engine/app/helpers/form_tag.rb +16 -0
- data/sample/login_engine/app/helpers/two_columns.rb +24 -0
- data/sample/login_engine/app/helpers/two_columns_form.rb +47 -0
- data/sample/login_engine/app/helpers/user_helper.rb +88 -0
- data/sample/login_engine/app/models/user.rb +7 -0
- data/sample/login_engine/app/models/user_notify.rb +75 -0
- data/sample/login_engine/config/boot.rb +45 -0
- data/sample/login_engine/config/environment.rb +140 -0
- data/sample/login_engine/config/environments/development.rb +21 -0
- data/sample/login_engine/config/environments/production.rb +18 -0
- data/sample/login_engine/config/environments/test.rb +19 -0
- data/sample/login_engine/config/routes.rb +23 -0
- data/sample/login_engine/db/migrate/001_create_users.rb +25 -0
- data/sample/login_engine/db/schema.rb +25 -0
- data/sample/login_engine/lib/config.rb +113 -0
- data/sample/login_engine/lib/hpricot_test_extension.rb +80 -0
- data/sample/login_engine/lib/login_engine/authenticated_system.rb +113 -0
- data/sample/login_engine/lib/login_engine/authenticated_user.rb +155 -0
- data/sample/login_engine/lib/login_engine.rb +62 -0
- data/sample/login_engine/public/dispatch.rb +10 -0
- data/sample/login_engine/test/functional/amrita2_test.rb +267 -0
- data/sample/login_engine/test/functional/user_controller_test.rb +544 -0
- data/sample/login_engine/test/mocks/mail.rb +14 -0
- data/sample/login_engine/test/mocks/time.rb +19 -0
- data/sample/login_engine/test/test_helper.rb +31 -0
- data/sample/login_engine/test/unit/user_test.rb +116 -0
- data/sample/login_engine/vendor/plugins/amrita2/init.rb +6 -0
- data/specs/attribute.rb +201 -0
- data/specs/datatypes.rb +231 -0
- data/specs/dictionary.rb +68 -0
- data/specs/erb_cdata.rb +187 -0
- data/specs/filters.rb +513 -0
- data/specs/gettext/erb_gettext.rb +42 -0
- data/specs/gettext/gettext_util.rb +65 -0
- data/specs/gettext/static_text.rb +103 -0
- data/specs/impl/code_generator.rb +87 -0
- data/specs/impl/dynamic_element.rb +92 -0
- data/specs/impl/hash_delegator.rb +57 -0
- data/specs/impl/parse_opt.rb +34 -0
- data/specs/impl/preprocess.rb +823 -0
- data/specs/impl/testsupport.rb +89 -0
- data/specs/inlineruby.rb +429 -0
- data/specs/intro.rb +654 -0
- data/specs/loop.rb +203 -0
- data/specs/macro.rb +532 -0
- data/specs/sample.rb +34 -0
- data/specs/sanitize.rb +110 -0
- data/specs/template.rb +189 -0
- data/specs/trace.rb +97 -0
- metadata +138 -19
- data/lib/amrita2/core.rb +0 -1897
- data/lib/amrita2/rd.rb +0 -314
data/specs/loop.rb
ADDED
@@ -0,0 +1,203 @@
|
|
1
|
+
|
2
|
+
require 'rexml/document'
|
3
|
+
require 'amrita2'
|
4
|
+
require 'amrita2/testsupport'
|
5
|
+
|
6
|
+
include Amrita2
|
7
|
+
include Amrita2::Filters
|
8
|
+
|
9
|
+
context "LOOP" do
|
10
|
+
|
11
|
+
specify "simple array" do
|
12
|
+
@t = Amrita2::Template.new <<EOF
|
13
|
+
<html>
|
14
|
+
<head>
|
15
|
+
<title am:src='title' />
|
16
|
+
</head>
|
17
|
+
<body>
|
18
|
+
<p class='text' am:src='text' />
|
19
|
+
<ul>
|
20
|
+
<li am:src='loop' />
|
21
|
+
</ul>
|
22
|
+
</body>
|
23
|
+
</html>
|
24
|
+
EOF
|
25
|
+
data = {
|
26
|
+
:title=>'Amrita2',
|
27
|
+
:text=>'Hello, Amrita2',
|
28
|
+
:loop=>[1,2,3]
|
29
|
+
}
|
30
|
+
@t.test_with(data) do |result|
|
31
|
+
result.should_be_samexml_as <<-EOF
|
32
|
+
<html>
|
33
|
+
<head>
|
34
|
+
<title>Amrita2</title>
|
35
|
+
</head>
|
36
|
+
<body>
|
37
|
+
<p class = "text">Hello, Amrita2</p>
|
38
|
+
<ul>
|
39
|
+
<li>1</li>
|
40
|
+
<li>2</li>
|
41
|
+
<li>3</li>
|
42
|
+
</ul>
|
43
|
+
</body>
|
44
|
+
</html>
|
45
|
+
EOF
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
specify "Each filter" do
|
50
|
+
t = Amrita2::Template.new <<-EOF
|
51
|
+
<ul>
|
52
|
+
<<li:list|ToHash[:body]|Each[:class=>['oddline', 'evenline']]|Attr[:class, :body]>>
|
53
|
+
</ul>
|
54
|
+
EOF
|
55
|
+
|
56
|
+
t.test_with(:list=>1..3) do |result|
|
57
|
+
result.should_be_samexml_as <<-EOF
|
58
|
+
<ul>
|
59
|
+
<li class='oddline'>1</li>
|
60
|
+
<li class='evenline'>2</li>
|
61
|
+
<li class='oddline'>3</li>
|
62
|
+
</ul>
|
63
|
+
EOF
|
64
|
+
end
|
65
|
+
|
66
|
+
t = Amrita2::Template.new <<-EOF
|
67
|
+
<ul>
|
68
|
+
<<li:list|Each[:class=>[:odd, :even]]|Attr[:class, :body]>>
|
69
|
+
</ul>
|
70
|
+
EOF
|
71
|
+
|
72
|
+
list = (1..3).collect do |n|
|
73
|
+
{ :body => n, :odd=>'oddline', :even=>'evenline' }
|
74
|
+
end
|
75
|
+
|
76
|
+
t.test_with(:list=>list) do |result|
|
77
|
+
result.should_be_samexml_as <<-EOF
|
78
|
+
<ul>
|
79
|
+
<li class='oddline'>1</li>
|
80
|
+
<li class='evenline'>2</li>
|
81
|
+
<li class='oddline'>3</li>
|
82
|
+
</ul>
|
83
|
+
EOF
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
specify "table" do
|
88
|
+
@t = Amrita2::Template.new <<EOF
|
89
|
+
<html>
|
90
|
+
<head>
|
91
|
+
<title am:src='title' />
|
92
|
+
</head>
|
93
|
+
<body>
|
94
|
+
<table>
|
95
|
+
<tr am:src='table'>
|
96
|
+
<td am:src='aaa' />
|
97
|
+
<td am:src='bbb' />
|
98
|
+
</tr>
|
99
|
+
</table>
|
100
|
+
</body>
|
101
|
+
</html>
|
102
|
+
EOF
|
103
|
+
data = {
|
104
|
+
:title=>'Amrita2',
|
105
|
+
:text=>'Hello, Amrita2',
|
106
|
+
:table=>[
|
107
|
+
{ :aaa=>'11', :bbb=>'12' },
|
108
|
+
{ :aaa=>'21', :bbb=>'22' },
|
109
|
+
{ :aaa=>'31', :bbb=>'32' },
|
110
|
+
]
|
111
|
+
}
|
112
|
+
@t.test_with(data) do |result|
|
113
|
+
result.should_be_samexml_as <<-EOF
|
114
|
+
<html>
|
115
|
+
<head>
|
116
|
+
<title>Amrita2</title>
|
117
|
+
</head>
|
118
|
+
<body>
|
119
|
+
<table>
|
120
|
+
<tr>
|
121
|
+
<td>11</td>
|
122
|
+
<td>12</td>
|
123
|
+
</tr>
|
124
|
+
<tr>
|
125
|
+
<td>21</td>
|
126
|
+
<td>22</td>
|
127
|
+
</tr>
|
128
|
+
<tr>
|
129
|
+
<td>31</td>
|
130
|
+
<td>32</td>
|
131
|
+
</tr>
|
132
|
+
</table>
|
133
|
+
</body>
|
134
|
+
</html>
|
135
|
+
EOF
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
specify "array of struct" do
|
140
|
+
@t = Amrita2::Template.new <<EOF
|
141
|
+
<table border='1'>
|
142
|
+
<tr><th>name</th><th>author</th><th>website</th></tr>
|
143
|
+
<tr am:src='table1'>
|
144
|
+
<td am:src='name'></td>
|
145
|
+
<td am:src='author'></td>
|
146
|
+
<td><a am:src='website|Attr[:href, :body]' /> </td>
|
147
|
+
</tr>
|
148
|
+
</table>
|
149
|
+
EOF
|
150
|
+
Lang1 = Struct.new(:name, :author, :site)
|
151
|
+
WebSite1 = Struct.new(:name, :url)
|
152
|
+
Lang1.module_eval do
|
153
|
+
def website
|
154
|
+
{
|
155
|
+
:href=>site.url,
|
156
|
+
:body=>site.name
|
157
|
+
}
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
data = {
|
162
|
+
:table1 => [
|
163
|
+
Lang1.new("Ruby", "matz", WebSite1.new('Ruby Home Page', 'http://www.ruby-lang.org/')),
|
164
|
+
Lang1.new("Perl", "Larry Wall", WebSite1.new('The Source for Perl', 'http://perl.com/')),
|
165
|
+
Lang1.new("Python","Guido van Rossum", WebSite1.new('Python Programing Language', 'http://www.python.org/'))
|
166
|
+
]
|
167
|
+
}
|
168
|
+
@t.test_with(data) do |result|
|
169
|
+
result.should_be_samexml_as <<-EOF
|
170
|
+
|
171
|
+
<table border='1'>
|
172
|
+
<tr>
|
173
|
+
<th>name</th>
|
174
|
+
<th>author</th>
|
175
|
+
<th>website</th>
|
176
|
+
</tr>
|
177
|
+
<tr>
|
178
|
+
<td>Ruby</td>
|
179
|
+
<td>matz</td>
|
180
|
+
<td>
|
181
|
+
<a href='http://www.ruby-lang.org/'>Ruby Home Page</a>
|
182
|
+
</td>
|
183
|
+
</tr>
|
184
|
+
<tr>
|
185
|
+
<td>Perl</td>
|
186
|
+
<td>Larry Wall</td>
|
187
|
+
<td>
|
188
|
+
<a href='http://perl.com/'>The Source for Perl</a>
|
189
|
+
</td>
|
190
|
+
</tr>
|
191
|
+
<tr>
|
192
|
+
<td>Python</td>
|
193
|
+
<td>Guido van Rossum</td>
|
194
|
+
<td>
|
195
|
+
<a href='http://www.python.org/'>Python Programing Language</a>
|
196
|
+
</td>
|
197
|
+
</tr>
|
198
|
+
</table>
|
199
|
+
EOF
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|