kwartz 3.0.0 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +36 -1
- data/LGPL +504 -0
- data/README.txt +16 -2
- data/bin/kwartz +1 -1
- data/doc-api/classes/Kwartz.html +47 -1
- data/doc-api/classes/Kwartz/Assertion.html +6 -6
- data/doc-api/classes/Kwartz/AssertionError.html +6 -6
- data/doc-api/classes/Kwartz/AttrInfo.html +42 -42
- data/doc-api/classes/Kwartz/BaseError.html +12 -12
- data/doc-api/classes/Kwartz/BaseTranslator.html +210 -43
- data/doc-api/classes/Kwartz/CharacterType.html +24 -24
- data/doc-api/classes/Kwartz/CommandOptionError.html +7 -7
- data/doc-api/classes/Kwartz/CommandOptions.html +49 -49
- data/doc-api/classes/Kwartz/Config.html +6 -1
- data/doc-api/classes/Kwartz/ConvertError.html +14 -14
- data/doc-api/classes/Kwartz/Converter.html +31 -30
- data/doc-api/classes/Kwartz/CssStyleParser.html +79 -57
- data/doc-api/classes/Kwartz/Defun.html +313 -0
- data/doc-api/classes/Kwartz/DocumentRuleset.html +58 -58
- data/doc-api/classes/Kwartz/ElementExpander.html +32 -32
- data/doc-api/classes/Kwartz/ElementInfo.html +29 -29
- data/doc-api/classes/Kwartz/ElementRuleset.html +126 -96
- data/doc-api/classes/Kwartz/EperlHandler.html +108 -84
- data/doc-api/classes/Kwartz/EperlTranslator.html +7 -7
- data/doc-api/classes/Kwartz/ErubisHandler.html +2 -2
- data/doc-api/classes/Kwartz/ErubisTranslator.html +8 -8
- data/doc-api/classes/Kwartz/ErubyHandler.html +2 -220
- data/doc-api/classes/Kwartz/ErubyTranslator.html +7 -7
- data/doc-api/classes/Kwartz/ExpandStatement.html +20 -20
- data/doc-api/classes/Kwartz/Handler.html +122 -117
- data/doc-api/classes/Kwartz/HandlerArgument.html +215 -0
- data/doc-api/classes/Kwartz/Helper.html +112 -0
- data/doc-api/classes/Kwartz/Helper/ActionViewHelper.html +221 -0
- data/doc-api/classes/Kwartz/Helper/RailsTemplate.html +630 -0
- data/doc-api/classes/Kwartz/JstlHandler.html +208 -193
- data/doc-api/classes/Kwartz/JstlTranslator.html +15 -15
- data/doc-api/classes/Kwartz/KwartzError.html +6 -6
- data/doc-api/classes/Kwartz/Main.html +39 -23
- data/doc-api/classes/Kwartz/NativeExpression.html +18 -18
- data/doc-api/classes/Kwartz/NativeStatement.html +25 -25
- data/doc-api/classes/Kwartz/Node.html +6 -6
- data/doc-api/classes/Kwartz/PIErubisHandler.html +113 -0
- data/doc-api/classes/Kwartz/PIErubisTranslator.html +200 -0
- data/doc-api/classes/Kwartz/ParseError.html +6 -6
- data/doc-api/classes/Kwartz/PhpHandler.html +102 -83
- data/doc-api/classes/Kwartz/PhpTranslator.html +14 -14
- data/doc-api/classes/Kwartz/PresentationLogicParser.html +136 -128
- data/doc-api/classes/Kwartz/PrintStatement.html +19 -19
- data/doc-api/classes/Kwartz/RailsHandler.html +121 -118
- data/doc-api/classes/Kwartz/RailsTranslator.html +7 -7
- data/doc-api/classes/Kwartz/RubyHandler.html +349 -0
- data/doc-api/classes/Kwartz/RubyStyleParser.html +85 -85
- data/doc-api/classes/Kwartz/RubyTranslator.html +218 -0
- data/doc-api/classes/Kwartz/StatementHelper.html +479 -0
- data/doc-api/classes/Kwartz/StrutsTranslator.html +12 -12
- data/doc-api/classes/Kwartz/TagInfo.html +28 -28
- data/doc-api/classes/Kwartz/TextConverter.html +28 -28
- data/doc-api/classes/Kwartz/Translator.html +42 -42
- data/doc-api/classes/Kwartz/Util.html +284 -0
- data/doc-api/created.rid +1 -1
- data/doc-api/files/__/README_txt.html +30 -3
- data/doc-api/files/kwartz/assert_rb.html +1 -1
- data/doc-api/files/kwartz/binding/eperl_rb.html +2 -2
- data/doc-api/files/kwartz/binding/erubis_rb.html +3 -3
- data/doc-api/files/kwartz/binding/eruby_rb.html +3 -2
- data/doc-api/files/kwartz/binding/jstl_rb.html +2 -2
- data/doc-api/files/kwartz/binding/php_rb.html +2 -2
- data/doc-api/files/kwartz/binding/pierubis_rb.html +116 -0
- data/doc-api/files/kwartz/binding/rails_rb.html +2 -2
- data/doc-api/files/kwartz/binding/ruby_rb.html +115 -0
- data/doc-api/files/kwartz/binding/struts_rb.html +1 -1
- data/doc-api/files/kwartz/config_rb.html +2 -2
- data/doc-api/files/kwartz/converter_rb.html +3 -2
- data/doc-api/files/kwartz/defun_rb.html +116 -0
- data/doc-api/files/kwartz/error_rb.html +1 -1
- data/doc-api/files/kwartz/helper/rails_rb.html +123 -0
- data/doc-api/files/kwartz/main_rb.html +5 -2
- data/doc-api/files/kwartz/node_rb.html +2 -2
- data/doc-api/files/kwartz/parser_rb.html +2 -2
- data/doc-api/files/kwartz/translator_rb.html +2 -2
- data/doc-api/files/kwartz/util/assert-text-equal_rb.html +1 -1
- data/doc-api/files/kwartz/util/testcase-helper_rb.html +2 -2
- data/doc-api/files/kwartz/util_rb.html +107 -0
- data/doc-api/files/kwartz_rb.html +3 -2
- data/doc-api/fr_class_index.html +11 -0
- data/doc-api/fr_file_index.html +5 -0
- data/doc-api/fr_method_index.html +242 -190
- data/doc/p-pattern.html +94 -94
- data/doc/reference.html +847 -612
- data/doc/users-guide.html +744 -241
- data/examples/rails1/README +2 -2
- data/examples/rails1/application_helper.rb +2 -27
- data/examples/rails1/link_to.plogic +5 -5
- data/examples/rails1/list.plogic +2 -2
- data/examples/rails2/app/controllers/application.rb +14 -0
- data/examples/rails2/app/controllers/groups_controller.rb +47 -0
- data/examples/rails2/app/controllers/members_controller.rb +56 -0
- data/examples/rails2/app/helpers/application_helper.rb +6 -0
- data/examples/rails2/app/helpers/groups_helper.rb +2 -0
- data/examples/rails2/app/helpers/members_helper.rb +2 -0
- data/examples/rails2/app/models/group.rb +2 -0
- data/examples/rails2/app/models/member.rb +3 -0
- data/examples/rails2/app/views/groups/_form.html +30 -0
- data/examples/rails2/app/views/groups/_form.plogic +11 -0
- data/examples/rails2/app/views/groups/_link.plogic +19 -0
- data/examples/rails2/app/views/groups/_read.plogic +7 -0
- data/examples/rails2/app/views/groups/edit.cfg.yaml +2 -0
- data/examples/rails2/app/views/groups/edit.html +26 -0
- data/examples/rails2/app/views/groups/edit.plogic +9 -0
- data/examples/rails2/app/views/groups/list.html +48 -0
- data/examples/rails2/app/views/groups/list.plogic +32 -0
- data/examples/rails2/app/views/groups/new.cfg.yaml +2 -0
- data/examples/rails2/app/views/groups/new.html +27 -0
- data/examples/rails2/app/views/groups/new.plogic +9 -0
- data/examples/rails2/app/views/groups/show.html +27 -0
- data/examples/rails2/app/views/groups/show.plogic +2 -0
- data/examples/rails2/app/views/layouts/groups.html +23 -0
- data/examples/rails2/app/views/layouts/groups.plogic +11 -0
- data/examples/rails2/app/views/layouts/members.html +23 -0
- data/examples/rails2/app/views/layouts/members.plogic +11 -0
- data/examples/rails2/app/views/layouts/members2.html +24 -0
- data/examples/rails2/app/views/layouts/members2.plogic +11 -0
- data/examples/rails2/app/views/members/_form.plogic +27 -0
- data/examples/rails2/app/views/members/_link.plogic +19 -0
- data/examples/rails2/app/views/members/_read.plogic +29 -0
- data/examples/rails2/app/views/members/edit.cfg.yaml +6 -0
- data/examples/rails2/app/views/members/edit.html +27 -0
- data/examples/rails2/app/views/members/edit.plogic +10 -0
- data/examples/rails2/app/views/members/list.html +53 -0
- data/examples/rails2/app/views/members/list.plogic +32 -0
- data/examples/rails2/app/views/members/new.html +61 -0
- data/examples/rails2/app/views/members/new.plogic +17 -0
- data/examples/rails2/app/views/members/show.html +41 -0
- data/examples/rails2/app/views/members/show.plogic +3 -0
- data/examples/rails2/db/create-tables.mysql.sql +27 -0
- data/examples/rails2/db/create-tables.pgsql.sql +27 -0
- data/examples/rails2/db/insert-data.sql +21 -0
- data/examples/rails2/db/tabledef.yaml +51 -0
- data/kwartz.gemspec +4 -4
- data/lib/kwartz.rb +10 -2
- data/lib/kwartz/assert.rb +1 -1
- data/lib/kwartz/binding/eperl.rb +85 -61
- data/lib/kwartz/binding/erubis.rb +6 -8
- data/lib/kwartz/binding/eruby.rb +5 -120
- data/lib/kwartz/binding/jstl.rb +116 -101
- data/lib/kwartz/binding/php.rb +79 -60
- data/lib/kwartz/binding/pierubis.rb +58 -0
- data/lib/kwartz/binding/rails.rb +45 -42
- data/lib/kwartz/binding/ruby.rb +193 -0
- data/lib/kwartz/binding/struts.rb +1 -1
- data/lib/kwartz/config.rb +4 -3
- data/lib/kwartz/converter.rb +231 -68
- data/lib/kwartz/defun.rb +126 -0
- data/lib/kwartz/error.rb +1 -1
- data/lib/kwartz/helper/rails.rb +437 -0
- data/lib/kwartz/main.rb +30 -38
- data/lib/kwartz/node.rb +46 -31
- data/lib/kwartz/parser.rb +43 -15
- data/lib/kwartz/translator.rb +104 -6
- data/lib/kwartz/util.rb +113 -0
- data/lib/kwartz/util/assert-text-equal.rb +1 -1
- data/lib/kwartz/util/testcase-helper.rb +26 -8
- data/test/test-compile.rb +3 -3
- data/test/test-compile.yaml +135 -5
- data/test/test-converter.rb +16 -8
- data/test/test-converter.yaml +307 -76
- data/test/test-directives.rb +1 -1
- data/test/test-directives.yaml +964 -979
- data/test/test-main.rb +61 -146
- data/test/test-main.yaml +235 -0
- data/test/test-parser.rb +10 -12
- data/test/test-parser.yaml +484 -326
- data/test/test-rails.rb +1 -1
- data/test/test-rails.yaml +37 -37
- data/test/test-ruleset.rb +1 -1
- data/test/test-ruleset.yaml +34 -40
- data/test/test.rb +1 -1
- metadata +82 -3
- data/COPYING +0 -340
data/doc/users-guide.html
CHANGED
@@ -16,7 +16,7 @@
|
|
16
16
|
<div align="left"><h1>Kwartz 3.0 Users' Guide</h1></div>
|
17
17
|
<div align="left">
|
18
18
|
Makoto Kuwata <kwa(at)kuwata-lab.com><br>
|
19
|
-
last update: $Date: 2006-
|
19
|
+
last update: $Date: 2006-09-24 19:37:59 +0900 (Sun, 24 Sep 2006) $<br>
|
20
20
|
</div>
|
21
21
|
|
22
22
|
<a name="preface"></a>
|
@@ -59,6 +59,8 @@ a template system which realized the concept of 'Independence of Presentation Lo
|
|
59
59
|
</li>
|
60
60
|
<li><a href="#directives">Directives</a>
|
61
61
|
</li>
|
62
|
+
<li><a href="#embed_expr">Embed Expression in Presentation Data</a>
|
63
|
+
</li>
|
62
64
|
<li><a href="#escape">Escape</a>
|
63
65
|
</li>
|
64
66
|
<li><a href="#langs">Multi-language</a>
|
@@ -75,19 +77,35 @@ a template system which realized the concept of 'Independence of Presentation Lo
|
|
75
77
|
</li>
|
76
78
|
<li><a href="#begin">Add Code at Beginning/End of Document</a>
|
77
79
|
</li>
|
80
|
+
<li><a href="#detail-defun">Compile Template into a Function of Ruby or PHP</a>
|
81
|
+
</li>
|
82
|
+
</ul>
|
83
|
+
</li>
|
84
|
+
<li><a href="#rails">Ruby on Rails Support</a>
|
85
|
+
<ul>
|
86
|
+
<li><a href="#rails_template">Support of Ruby on Rails</a>
|
87
|
+
</li>
|
88
|
+
<li><a href="#rails_start_link_tag"><code>link_to()</code> method in Ruby on Rails</a>
|
89
|
+
</li>
|
90
|
+
<li><a href="#rails-layout">Layout Option in Controller</a>
|
91
|
+
</li>
|
92
|
+
<li><a href="#rails-scaffold">Scaffold Kwartz Template</a>
|
93
|
+
</li>
|
94
|
+
<li><a href="#rails-helper-methods">Rails Helper Methods</a>
|
95
|
+
</li>
|
78
96
|
</ul>
|
79
97
|
</li>
|
80
98
|
<li><a href="#topics">Other Topics</a>
|
81
99
|
<ul>
|
82
|
-
<li><a href="#restriction1">Restrictions around presentation logic</a>
|
100
|
+
<li><a href="#topics-restriction1">Restrictions around presentation logic</a>
|
83
101
|
</li>
|
84
|
-
<li><a href="#restriction2">Restrictions around presentation data</a>
|
102
|
+
<li><a href="#topics-restriction2">Restrictions around presentation data</a>
|
85
103
|
</li>
|
86
|
-
<li><a href="#makefile">Makefile and Rakefile</a>
|
104
|
+
<li><a href="#topics-makefile">Makefile and Rakefile</a>
|
87
105
|
</li>
|
88
|
-
<li><a href="#kwartz-lib">Use Kwartz as Library</a>
|
106
|
+
<li><a href="#topics-kwartz-lib">Use Kwartz as Library</a>
|
89
107
|
</li>
|
90
|
-
<li><a href="#
|
108
|
+
<li><a href="#topics-erubis">Use Kwartz with Non-Supported Language</a>
|
91
109
|
</li>
|
92
110
|
</ul>
|
93
111
|
</li>
|
@@ -103,7 +121,7 @@ a template system which realized the concept of 'Independence of Presentation Lo
|
|
103
121
|
<a name="whatis"></a>
|
104
122
|
<h3 class="section2">What's Kwartz?</h3>
|
105
123
|
<p>Kwartz<sup>(<a href="#fnref:2" name="fnlink:2">*2</a>)</sup> is a template system
|
106
|
-
which realized the concept of <
|
124
|
+
which realized the concept of <strong>'Independence of Presentation Logic'(IoPL)</strong>.
|
107
125
|
It means that Kwartz separates presentaion logics from both presentation data (typically HTML document) and business logics.
|
108
126
|
</p>
|
109
127
|
<p>You know CSS (Cascading Style Sheet). CSS separates design from HTML file.
|
@@ -181,7 +199,7 @@ Doesn't break HTML design at all</dt>
|
|
181
199
|
<code>{foreach ...}{/foreach}</code> in <a href="http://smarty.php.net/">Smarty</a> or
|
182
200
|
<code>#foreach(...)</code> in <a href="http://jakarta.apache.org/velocity/">Jakarta Velocity</a>.
|
183
201
|
These directives break the HTML design of template.
|
184
|
-
Kwartz doesn't break HTML design because Kwartz uses id or
|
202
|
+
Kwartz doesn't break HTML design because Kwartz uses id or kw:d attributes for marking in an HTML template.
|
185
203
|
</p>
|
186
204
|
</dd>
|
187
205
|
<dt class="dt2">
|
@@ -220,9 +238,9 @@ They may be described in separate files.
|
|
220
238
|
<p>This is an example of a presentation data file.
|
221
239
|
</p>
|
222
240
|
<ul type="disc">
|
223
|
-
<li>'<
|
241
|
+
<li>'<strong><code>id="list1"</code></strong>' means "I'll operate this element in presentation logic" (called 'marking' in Kwartz).
|
224
242
|
</li>
|
225
|
-
<li>'<
|
243
|
+
<li>'<strong><code>id="mark:item1"</code></strong>' is also an marking.
|
226
244
|
Difference between <code>id="mark:item1"</code> and <code>id="item1"</code> is that id attribute in the former format is removed automatically and the latter format is leaved.
|
227
245
|
</li>
|
228
246
|
</ul>
|
@@ -230,8 +248,8 @@ They may be described in separate files.
|
|
230
248
|
</p>
|
231
249
|
<a name="example1.html"></a>
|
232
250
|
<pre class="program"><table>
|
233
|
-
<tr <
|
234
|
-
<td <
|
251
|
+
<tr <strong>id="list1"</strong>>
|
252
|
+
<td <strong>id="mark:item1"</strong>>foo</td>
|
235
253
|
</tr>
|
236
254
|
</table>
|
237
255
|
</pre>
|
@@ -239,24 +257,24 @@ They may be described in separate files.
|
|
239
257
|
In presentation logic, you can operate on elements which are marked in presentation data.
|
240
258
|
</p>
|
241
259
|
<ul type="disc">
|
242
|
-
<li>'<
|
260
|
+
<li>'<strong><code>#list1 { ... }</code></strong>' represents an element marked with name 'list1' (= '<tr>...</tr>')
|
243
261
|
<ul type="circle">
|
244
|
-
<li>'<
|
262
|
+
<li>'<strong><code>logic: { ... }</code></strong>' represents presentation logic of the element.
|
245
263
|
</li>
|
246
|
-
<li>'<
|
264
|
+
<li>'<strong><code>_stag</code></strong>' represents a start tag (= '<tr>').
|
247
265
|
</li>
|
248
|
-
<li>'<
|
266
|
+
<li>'<strong><code>_cont</code></strong>' represents content(= '<td id="mark:item1">foo</td>').
|
249
267
|
</li>
|
250
|
-
<li>'<
|
268
|
+
<li>'<strong><code>_etag</code></strong>' represents an end tag(= '</tr>').
|
251
269
|
</li>
|
252
|
-
<li>'<
|
270
|
+
<li>'<strong><code>for <em>var</em> in <em>list</em> ...</code></strong>' is a Ruby code to loop.
|
253
271
|
In this case, the element(= start-tag + content + end-tag) is looped.
|
254
272
|
</li>
|
255
273
|
</ul>
|
256
274
|
</li>
|
257
|
-
<li>'<
|
275
|
+
<li>'<strong><code>#item1 { ... }</code></strong>' represents an element marked with name 'item1' (= '<td>...</td>').
|
258
276
|
<ul type="circle">
|
259
|
-
<li>'<
|
277
|
+
<li>'<strong><code>value: <em>expression</em>;</code></strong>' represents that the content of the element is replaced by value of <code><em>expression</em></code>, which is value of a variable <code>member</code> in this case.
|
260
278
|
</li>
|
261
279
|
</ul>
|
262
280
|
</li>
|
@@ -265,18 +283,18 @@ In presentation logic, you can operate on elements which are marked in presentat
|
|
265
283
|
<div class="program_caption">
|
266
284
|
Presentation logic file(example1.plogic):</div>
|
267
285
|
<pre class="program">/* The element which is marked by 'id="list1"' */
|
268
|
-
<
|
286
|
+
<strong>#list1</strong> {
|
269
287
|
logic: {
|
270
288
|
for member in @members
|
271
|
-
<
|
272
|
-
<
|
273
|
-
<
|
289
|
+
<strong>_stag</strong> # start tag
|
290
|
+
<strong>_cont</strong> # content
|
291
|
+
<strong>_etag</strong> # end tag
|
274
292
|
end
|
275
293
|
}
|
276
294
|
}
|
277
295
|
|
278
296
|
/* The element which is marked by 'id="mark:item1"' */
|
279
|
-
<
|
297
|
+
<strong>#item1</strong> {
|
280
298
|
/* replace the content with value of a variable 'member' */
|
281
299
|
value: member;
|
282
300
|
}
|
@@ -314,10 +332,10 @@ generated eRuby script</div>
|
|
314
332
|
<div class="program_caption">
|
315
333
|
Presentation Data (example2.html):</div>
|
316
334
|
<pre class="program"><table>
|
317
|
-
<tr bgcolor="#CCCCFF" <
|
318
|
-
<td <
|
335
|
+
<tr bgcolor="#CCCCFF" <strong>id="mark:list"</strong>>
|
336
|
+
<td <strong>id="mark:name"</strong>>foo</td>
|
319
337
|
<td>
|
320
|
-
<a href="mailto:foo@mail.com" <
|
338
|
+
<a href="mailto:foo@mail.com" <strong>id="mark:email"</strong>>foo@mail.com</a>
|
321
339
|
</td>
|
322
340
|
</tr>
|
323
341
|
</table>
|
@@ -332,7 +350,7 @@ In the presentation logic, you should detect whether odd or even line in the ite
|
|
332
350
|
* an element which is marked by 'id="mark:list"'
|
333
351
|
* - print value of a variable 'color' as bgcolor attribute value.
|
334
352
|
*/
|
335
|
-
<
|
353
|
+
<strong>#list</strong> {
|
336
354
|
attrs: "bgcolor" color;
|
337
355
|
logic: {
|
338
356
|
@members.each_with_index do |member, i|
|
@@ -348,7 +366,7 @@ In the presentation logic, you should detect whether odd or even line in the ite
|
|
348
366
|
* an element which is marked by 'id="mark:name"':
|
349
367
|
* - print value of member[:name] as content of the element.
|
350
368
|
*/
|
351
|
-
<
|
369
|
+
<strong>#name</strong> {
|
352
370
|
value: member[:name];
|
353
371
|
}
|
354
372
|
|
@@ -357,7 +375,7 @@ In the presentation logic, you should detect whether odd or even line in the ite
|
|
357
375
|
* - print value of member[:email] as contentn of the element.
|
358
376
|
* - print "mailto:" and member[:email] as href attribute value.
|
359
377
|
*/
|
360
|
-
<
|
378
|
+
<strong>#email</strong> {
|
361
379
|
value: member[:email];
|
362
380
|
attrs: "href" "mailto:#{member[:email]}";
|
363
381
|
}
|
@@ -375,15 +393,15 @@ compilation</div>
|
|
375
393
|
<div class="program_caption">
|
376
394
|
output script</div>
|
377
395
|
<pre class="program"><table>
|
378
|
-
<
|
379
|
-
<
|
380
|
-
<tr bgcolor="<
|
381
|
-
<td><
|
396
|
+
<strong><% @members.each_with_index do |member, i| %></strong>
|
397
|
+
<strong><% color = i % 2 == 0 ? '#FFCCCC' : '#CCCCFF'; %></strong>
|
398
|
+
<tr bgcolor="<strong><%= color %></strong>">
|
399
|
+
<td><strong><%= member[:name] %></strong></td>
|
382
400
|
<td>
|
383
|
-
<a href="<
|
401
|
+
<a href="<strong><%= "mailto:#{member[:email]}" %></strong>"><strong><%= member[:email] %></strong></a>
|
384
402
|
</td>
|
385
403
|
</tr>
|
386
|
-
<
|
404
|
+
<strong><% end %></strong>
|
387
405
|
</table>
|
388
406
|
</pre>
|
389
407
|
<br>
|
@@ -552,42 +570,42 @@ These are similar to CSS. If you are familiar with CSS, you'll be so with Kwartz
|
|
552
570
|
</p>
|
553
571
|
<dl class="dl3">
|
554
572
|
<dt class="dt3"><b>
|
555
|
-
stag: <
|
573
|
+
stag: <em>expr</em>; </b></dt>
|
556
574
|
<dd class="dd3">
|
557
575
|
Replace start-tag by expression value.
|
558
576
|
</dd>
|
559
577
|
</dl>
|
560
578
|
<dl class="dl3">
|
561
579
|
<dt class="dt3"><b>
|
562
|
-
etag: <
|
580
|
+
etag: <em>expr</em>; </b></dt>
|
563
581
|
<dd class="dd3">
|
564
582
|
Replace end-tag by expression value.
|
565
583
|
</dd>
|
566
584
|
</dl>
|
567
585
|
<dl class="dl3">
|
568
586
|
<dt class="dt3"><b>
|
569
|
-
elem: <
|
587
|
+
elem: <em>expr</em>; </b></dt>
|
570
588
|
<dd class="dd3">
|
571
589
|
Replace elemnt by expression value.
|
572
590
|
</dd>
|
573
591
|
</dl>
|
574
592
|
<dl class="dl3">
|
575
593
|
<dt class="dt3"><b>
|
576
|
-
cont: <
|
594
|
+
cont: <em>expr</em>; </b></dt>
|
577
595
|
<dd class="dd3">
|
578
596
|
Replace content of element by expressin value.
|
579
597
|
</dd>
|
580
598
|
</dl>
|
581
599
|
<dl class="dl3">
|
582
600
|
<dt class="dt3"><b>
|
583
|
-
value: <
|
601
|
+
value: <em>expr</em>; </b></dt>
|
584
602
|
<dd class="dd3">
|
585
|
-
Equivarent to <code>cont: <
|
603
|
+
Equivarent to <code>cont: <em>expr</em></code>.
|
586
604
|
</dd>
|
587
605
|
</dl>
|
588
606
|
<dl class="dl3">
|
589
607
|
<dt class="dt3"><b>
|
590
|
-
attrs: 'attrname' <
|
608
|
+
attrs: 'attrname' <em>expr</em>; </b></dt>
|
591
609
|
<dd class="dd3">
|
592
610
|
Replace attribute value by expression.
|
593
611
|
The following is an example to specify some attributes.
|
@@ -601,7 +619,7 @@ attrs: 'attrname' <i>expr</i>; </b></dt>
|
|
601
619
|
</dl>
|
602
620
|
<dl class="dl3">
|
603
621
|
<dt class="dt3"><b>
|
604
|
-
append: <
|
622
|
+
append: <em>expr</em>; </b></dt>
|
605
623
|
<dd class="dd3">
|
606
624
|
Append expression value to tail of tag.
|
607
625
|
This is used especially to add 'checked="checked"', 'selected="selected"'
|
@@ -635,38 +653,38 @@ The following is an examle to use Kwartz in Ruby on Rails.
|
|
635
653
|
<a name="form1.html"></a>
|
636
654
|
<div class="program_caption">
|
637
655
|
presentation data (form1.html)</div>
|
638
|
-
<pre class="program"><form <
|
639
|
-
Name: <input type="text" <
|
640
|
-
Birthday: <select <
|
656
|
+
<pre class="program"><form <strong>id="form"</strong>>
|
657
|
+
Name: <input type="text" <strong>id="member_name"</strong>><br>
|
658
|
+
Birthday: <select <strong>id="member_birth"</strong>>
|
641
659
|
<option> - </option>
|
642
660
|
</select><br>
|
643
|
-
<input type="submit" <
|
661
|
+
<input type="submit" <strong>id="submit"</strong>>
|
644
662
|
</form>
|
645
663
|
</pre>
|
646
664
|
<a name="form1.plogic"></a>
|
647
665
|
<div class="program_caption">
|
648
666
|
presentation logic (form1.plogic)</div>
|
649
|
-
<pre class="program"><
|
650
|
-
<
|
667
|
+
<pre class="program"><strong>#form</strong> {
|
668
|
+
<strong>stag:</strong> start_form_tag :action=>'new';
|
651
669
|
}
|
652
|
-
<
|
653
|
-
<
|
670
|
+
<strong>#member_name</strong> {
|
671
|
+
<strong>elem:</strong> text_field 'member', 'name';
|
654
672
|
}
|
655
|
-
<
|
656
|
-
<
|
673
|
+
<strong>#member_birth</strong> {
|
674
|
+
<strong>elem:</strong> date_select 'member', birth';
|
657
675
|
}
|
658
|
-
<
|
659
|
-
<
|
676
|
+
<strong>#submit</strong> {
|
677
|
+
<strong>elem:</strong> submit_to 'Submit';
|
660
678
|
}
|
661
679
|
</pre>
|
662
680
|
<a name="form1.expected"></a>
|
663
681
|
<div class="terminal_caption">
|
664
682
|
compile</div>
|
665
683
|
<pre class="terminal">$ kwartz -p form1.plogic form1.html
|
666
|
-
<
|
667
|
-
Name: <
|
668
|
-
Birthday: <
|
669
|
-
<
|
684
|
+
<strong><%= start_form_tag :action=>'new' %></strong>
|
685
|
+
Name: <strong><%= text_field 'member', 'name' %></strong><br>
|
686
|
+
Birthday: <strong><%= date_select 'member', birth' %></strong><br>
|
687
|
+
<strong><%= submit_to 'Submit' %></strong>
|
670
688
|
</form>
|
671
689
|
</pre>
|
672
690
|
<br>
|
@@ -677,7 +695,7 @@ compile</div>
|
|
677
695
|
<p>Presentation logic may be embedded into presentation data in Kwartz.
|
678
696
|
You can choose to separate or not to sepearate presentation logic from presentation data.
|
679
697
|
</p>
|
680
|
-
<p>The reason to provide both solutions (separate or not) is <
|
698
|
+
<p>The reason to provide both solutions (separate or not) is <strong>choosability</strong>.
|
681
699
|
Some preferes to separate presentation logic from presentaion data, and others may
|
682
700
|
prefere to mix them.
|
683
701
|
Both approaches have own advantages and disadvantages.
|
@@ -687,34 +705,34 @@ Kwartz doesn't enforce you to adopt a solution.
|
|
687
705
|
</p>
|
688
706
|
<p>To embed presentation logic into presentation data, use directives.
|
689
707
|
Directive is a command to embed presentation logic into presentation data.
|
690
|
-
In Kwartz, '
|
708
|
+
In Kwartz, 'kw:d' attributes<sup>(<a href="#fnref:4" name="fnlink:4">*4</a>)</sup> are used to describe directives.
|
691
709
|
</p>
|
692
710
|
<p>The following is an example to use directives.
|
693
711
|
</p>
|
694
712
|
<ul type="disc">
|
695
|
-
<li>Directive <code>
|
713
|
+
<li>Directive <code>kw:d="for <em>var</em> in <em>list</em>"</code> means to iterate the element.
|
696
714
|
</li>
|
697
|
-
<li>Directive <code>
|
715
|
+
<li>Directive <code>kw:d="value: <em>expression</em>"</code> means to print value of expression as content of the element.
|
698
716
|
</li>
|
699
|
-
<li>Directive <code>
|
717
|
+
<li>Directive <code>kw:d="dummy:"</code> means that the element is a dummy and is not printed out.
|
700
718
|
</li>
|
701
719
|
</ul>
|
702
720
|
<a name="directive1.html"></a>
|
703
721
|
<div class="program_caption">
|
704
722
|
Presentation Data(directive1.html):</div>
|
705
723
|
<pre class="program"><table>
|
706
|
-
<tr <
|
707
|
-
<td <
|
724
|
+
<tr <strong>kw:d="for member in @members"</strong>>
|
725
|
+
<td <strong>kw:d="value: member.name"</strong>>foo</td>
|
708
726
|
<td>
|
709
727
|
<a href="mailto:<%= member.email %>"
|
710
|
-
|
728
|
+
kw:d="<strong>value: member.email</strong>">foo@mai.com</a>
|
711
729
|
</td>
|
712
730
|
</tr>
|
713
|
-
<tr <
|
731
|
+
<tr <strong>kw:d="dummy:"</strong>>
|
714
732
|
<td>bar</td>
|
715
733
|
<td><a href="mailto:bar@mail.org">bar@mail.org</a></td>
|
716
734
|
</tr>
|
717
|
-
<tr <
|
735
|
+
<tr <strong>kw:d="dummy:"</strong>>
|
718
736
|
<td>baz</td>
|
719
737
|
<td><a href="mailto:baz@mail.net">baz@mail.net</a></td>
|
720
738
|
</tr>
|
@@ -728,14 +746,14 @@ Compile:</div>
|
|
728
746
|
<div class="program_caption">
|
729
747
|
Output script:</div>
|
730
748
|
<pre class="program"><table>
|
731
|
-
<
|
749
|
+
<strong><% for member in @members do %></strong>
|
732
750
|
<tr>
|
733
|
-
<td><
|
751
|
+
<td><strong><%= member.name %></strong></td>
|
734
752
|
<td>
|
735
|
-
<a href="mailto:<
|
753
|
+
<a href="mailto:<strong><%= member.email %></strong>"><strong><%= member.email %></strong></a>
|
736
754
|
</td>
|
737
755
|
</tr>
|
738
|
-
<
|
756
|
+
<strong><% end %></strong>
|
739
757
|
</table>
|
740
758
|
</pre>
|
741
759
|
<p>If the first character of target attribute is a space, Kwartz recognize it as non-directive<sup>(<a href="#fnref:5" name="fnlink:5">*5</a>)</sup>.
|
@@ -743,15 +761,15 @@ Output script:</div>
|
|
743
761
|
<a name="directive2.html"></a>
|
744
762
|
<div class="program_caption">
|
745
763
|
presentation data (directive2.html)</div>
|
746
|
-
<pre class="program"><span <
|
747
|
-
<span <
|
764
|
+
<pre class="program"><span <strong>kw:d="value: expr1"</strong>>foo</span>
|
765
|
+
<span <strong>kw:d=" value: expr2"</strong>>bar</span>
|
748
766
|
</pre>
|
749
767
|
<a name="directive2.expected"></a>
|
750
768
|
<div class="terminal_caption">
|
751
769
|
compile</div>
|
752
770
|
<pre class="terminal">$ kwartz directive2.html
|
753
|
-
<span><
|
754
|
-
<span <
|
771
|
+
<span><strong><%= expr1 %></strong></span>
|
772
|
+
<span <strong>kw:d="value: expr2"</strong>>bar</span>
|
755
773
|
</pre>
|
756
774
|
<p>Directives are different in each target language.
|
757
775
|
For example, foreach loop is 'for item in list' in eRuby, 'foreach($list as $item)' in PHP, 'forEach(item in list)' in JSTL.
|
@@ -768,22 +786,73 @@ See reference manual for details about directives.
|
|
768
786
|
<br>
|
769
787
|
|
770
788
|
|
789
|
+
<a name="embed_expr"></a>
|
790
|
+
<h3 class="section2">Embed Expression in Presentation Data</h3>
|
791
|
+
<p>It is able to embed expressions in presentation data file in each language format.
|
792
|
+
For example, you can use '<%= ... %>' with eRuby, '#{...}' with Ruby, '<?php echo ... ?>' with PHP, and so on.
|
793
|
+
</p>
|
794
|
+
<p>(Experimental) '@{...}@' and '@!{...}@' are also available as embedded expression notation in all languages.
|
795
|
+
The former escapes expression and the latter does not escape expression.
|
796
|
+
</p>
|
797
|
+
<a name="embed1_eruby.html"></a>
|
798
|
+
<div class="program_caption">
|
799
|
+
presentation data (embed1_eruby.html)</div>
|
800
|
+
<pre class="program"><p class="<strong><%= klass %></strong>">Hello <strong><%=h user %></strong></p>
|
801
|
+
<p class="<strong>@!{klass}@</strong>">Hello <strong>@{user}@</strong></p>
|
802
|
+
</pre>
|
803
|
+
<a name="embed1_eruby.expected"></a>
|
804
|
+
<div class="terminal_caption">
|
805
|
+
compile</div>
|
806
|
+
<pre class="terminal">$ kwartz -l eruby embed1_eruby.html
|
807
|
+
<p class="<strong><%= klass %></strong>">Hello <strong><%=h user %></strong></p>
|
808
|
+
<p class="<strong><%= klass %></strong>">Hello <strong><%=h user %></strong></p>
|
809
|
+
</pre>
|
810
|
+
<a name="embed1_ruby.html"></a>
|
811
|
+
<div class="program_caption">
|
812
|
+
presentation data (embed1_ruby.html)</div>
|
813
|
+
<pre class="program"><p class="<strong>#{klass}</strong>">Hello <strong>#{ERB::Util.h user}</strong></p>
|
814
|
+
<p class="<strong>@!{klass}@</strong>">Hello <strong>@{user}@</strong></p>
|
815
|
+
</pre>
|
816
|
+
<a name="embed1_ruby.expected"></a>
|
817
|
+
<div class="terminal_caption">
|
818
|
+
compile</div>
|
819
|
+
<pre class="terminal">$ kwartz -l eruby embed1_ruby.html
|
820
|
+
_buf = ""; _buf << "<p class=\"<strong>#{klass}</strong>\">Hello <strong>#{ERB::Util.h user}</strong></p>
|
821
|
+
<p class=\""; _buf << <strong>(klass).to_s</strong>; _buf << "\">Hello "; _buf << <strong>ERB::Util.h(user)</strong>; _buf << "</p>\n";
|
822
|
+
; _buf
|
823
|
+
</pre>
|
824
|
+
<a name="embed1_php.html"></a>
|
825
|
+
<div class="program_caption">
|
826
|
+
presentation data (embed1_php.html)</div>
|
827
|
+
<pre class="program"><p class="<strong><?php echo $klass; ?></strong>">Hello <strong><?php echo htmlspecialchars($user); ?></strong></p>
|
828
|
+
<p class="<strong>@!{$klass}@</strong>">Hello <strong>@{$user}@</strong></p>
|
829
|
+
</pre>
|
830
|
+
<a name="embed1_php.expected"></a>
|
831
|
+
<div class="terminal_caption">
|
832
|
+
compile</div>
|
833
|
+
<pre class="terminal">$ kwartz -l eruby embed1_php.html
|
834
|
+
<p class="<strong><?php echo $klass; ?></strong>">Hello <strong><?php echo htmlspecialchars($user); ?></strong></p>
|
835
|
+
<p class="<strong><?php echo $klass; ?></strong>">Hello <strong><?php echo htmlspecialchars($user); ?></strong></p>
|
836
|
+
</pre>
|
837
|
+
<br>
|
838
|
+
|
839
|
+
|
771
840
|
<a name="escape"></a>
|
772
841
|
<h3 class="section2">Escape</h3>
|
773
842
|
<p>Kwartz supports Automatic-escape and Partial-escape/unescape.
|
774
843
|
</p>
|
775
844
|
<ul type="disc">
|
776
|
-
<li>If command-line option '<code>-e</code>' is specified, values of '<code>value: <
|
845
|
+
<li>If command-line option '<code>-e</code>' is specified, values of '<code>value: <em>expr</em></code>'
|
777
846
|
are escaped. (Automatic-escape)
|
778
847
|
</li>
|
779
|
-
<li>'<code>Value: <
|
848
|
+
<li>'<code>Value: <em>expr</em></code>' always escapes value even when '<code>-e</code>' is not specified. (Partial-escape)
|
780
849
|
</li>
|
781
|
-
<li>'<code>VALUE: <
|
850
|
+
<li>'<code>VALUE: <em>expr</em></code>' always doesn't escapes value even when '<code>-e</code>' is specified. (Partial-unescape)
|
782
851
|
</li>
|
783
852
|
</ul>
|
784
853
|
<a name="escape1.html"></a>
|
785
854
|
<div class="program_caption">
|
786
|
-
presentation
|
855
|
+
presentation data (escape1.html):</div>
|
787
856
|
<pre class="program"><tr>
|
788
857
|
<td id="mark:val1">foo</td>
|
789
858
|
<td id="mark:val2">bar</td>
|
@@ -794,13 +863,13 @@ presentation Data (escape1.html):</div>
|
|
794
863
|
<div class="program_caption">
|
795
864
|
presentation logic (escape1.plogic)</div>
|
796
865
|
<pre class="program">#val1 {
|
797
|
-
<
|
866
|
+
<strong>value:</strong> expr;
|
798
867
|
}
|
799
868
|
#val2 {
|
800
|
-
<
|
869
|
+
<strong>Value:</strong> expr;
|
801
870
|
}
|
802
871
|
#val3 {
|
803
|
-
<
|
872
|
+
<strong>VALUE:</strong> expr;
|
804
873
|
}
|
805
874
|
</pre>
|
806
875
|
<a name="escape1.expected"></a>
|
@@ -816,11 +885,11 @@ compile without '<code>-e</code>' option.</div>
|
|
816
885
|
<a name="escape1e.expected"></a>
|
817
886
|
<div class="terminal_caption">
|
818
887
|
comple with '<code>-e</code>' option.</div>
|
819
|
-
<pre class="terminal">$ kwartz <
|
888
|
+
<pre class="terminal">$ kwartz <strong>-e</strong> -p escape1.plogic escape1.html
|
820
889
|
<tr>
|
821
|
-
<td><
|
822
|
-
<td><
|
823
|
-
<td><
|
890
|
+
<td><strong><%=h expr %></strong></td>
|
891
|
+
<td><strong><%=h expr %></strong></td>
|
892
|
+
<td><strong><%= expr %></strong></td>
|
824
893
|
</tr>
|
825
894
|
</pre>
|
826
895
|
<p>In the same way, '<code>Stag:</code>', '<code>Etag:</code>', '<code>Elem:</code>',
|
@@ -833,9 +902,9 @@ never escaped.
|
|
833
902
|
'h()' is used in eRuby and 'htmlspecialchars()' in PHP.
|
834
903
|
JSTL prints escaped value in default.
|
835
904
|
</p>
|
836
|
-
<p>Directives <code>
|
905
|
+
<p>Directives <code>kw:d="Value: <em>expr</em>"</code>, <code>kw:d="Attr: '<em>name</em>' <em>expr</em>"</code>, and <code>kw:d="Append: <em>expr</em>"</code> always escape expression value even when the command-line option '<code>-e</code>' is not specified.
|
837
906
|
</p>
|
838
|
-
<p>Directives <code>
|
907
|
+
<p>Directives <code>kw:d="VALUE: <em>expr</em>:"</code>, <code>kw:d="ATTR: '<em>name</em>' <em>expr</em>"</code>, and <code>kw:d="APPEND: <em>expr</em>"</code> doesn't escape expression value even when the command-line option '<code>-e</code>' is specified.
|
839
908
|
</p>
|
840
909
|
<p>Configuration option PROPERTY_ESCAPE in 'kwartz/config.rb' determines whether values are escaped or not in default.
|
841
910
|
If this is true then Kwartz will escape values in default.
|
@@ -848,20 +917,20 @@ If this is true then Kwartz will escape values in default.
|
|
848
917
|
<p>Kwartz-ruby now supports the following programming language.
|
849
918
|
</p>
|
850
919
|
<ul type="disc">
|
851
|
-
<li>Ruby (
|
920
|
+
<li>Ruby, eRuby(ERB, Erubis)
|
852
921
|
</li>
|
853
922
|
<li>PHP
|
854
923
|
</li>
|
855
924
|
<li>JSP (JSTL 1.1 and 1.2)
|
856
925
|
</li>
|
857
|
-
<li>
|
926
|
+
<li>ePerl [experimental]
|
858
927
|
</li>
|
859
928
|
</ul>
|
860
929
|
<p>Presentation logics must be described in each target language.
|
861
930
|
It means that if you have wrote presentation logics in Ruby, they were not reusable
|
862
931
|
for PHP project (but you can get full-power of Ruby in presentation logic).
|
863
932
|
</p>
|
864
|
-
<p>The followings are examples of Ruby, PHP, JSP, and
|
933
|
+
<p>The followings are examples of Ruby, eRuby, PHP, JSP, and ePerl.
|
865
934
|
</p>
|
866
935
|
<a name="table1.html"></a>
|
867
936
|
<div class="program_caption">
|
@@ -870,15 +939,15 @@ table1.html</div>
|
|
870
939
|
<body>
|
871
940
|
|
872
941
|
<table>
|
873
|
-
<tr bgcolor="#CCCCFF" <
|
874
|
-
<td <
|
875
|
-
<td <
|
942
|
+
<tr bgcolor="#CCCCFF" <strong>id="mark:row"</strong>>
|
943
|
+
<td <strong>id="mark:name"</strong>>Foo</td>
|
944
|
+
<td <strong>id="mark:mail"</strong>>foo@mail.com</td>
|
876
945
|
</tr>
|
877
|
-
<tr bgcolor="#FFCCCC" <
|
946
|
+
<tr bgcolor="#FFCCCC" <strong>id="dummy:row1"</strong>>
|
878
947
|
<td>Bar</td>
|
879
948
|
<td>bar@mail.net</td>
|
880
949
|
</tr>
|
881
|
-
<tr bgcolor="#CCCCFF" <
|
950
|
+
<tr bgcolor="#CCCCFF" <strong>id="dummy:row2"</strong>>
|
882
951
|
<td>Baz</td>
|
883
952
|
<td>baz@mail.org</td>
|
884
953
|
</tr>
|
@@ -887,16 +956,16 @@ table1.html</div>
|
|
887
956
|
</body>
|
888
957
|
</html>
|
889
958
|
</pre>
|
890
|
-
<a name="table1.
|
959
|
+
<a name="table1.ruby.plogic"></a>
|
891
960
|
<div class="program_caption">
|
892
|
-
table1.
|
961
|
+
table1.ruby.plogic</div>
|
893
962
|
<pre class="program">#row {
|
894
963
|
attrs: "bgcolor" color;
|
895
964
|
logic: {
|
896
965
|
@list.each_with_index do |user, i|
|
897
|
-
color = i % 2 == 1 ? '#FFCCCC' : '#CCCCFF'
|
966
|
+
color = i % 2 == 1 ? '#FFCCCC' : '#CCCCFF'
|
898
967
|
_elem
|
899
|
-
|
968
|
+
end
|
900
969
|
}
|
901
970
|
}
|
902
971
|
|
@@ -975,25 +1044,85 @@ table1.eperl.plogic</div>
|
|
975
1044
|
</pre>
|
976
1045
|
<div class="terminal_caption">
|
977
1046
|
compile</div>
|
978
|
-
<pre class="terminal">$ kwartz -l eruby
|
979
|
-
$ kwartz -l
|
980
|
-
$ kwartz -l
|
981
|
-
$ kwartz -l
|
1047
|
+
<pre class="terminal">$ kwartz -l eruby -p table1.ruby.plogic table1.html > table1.eruby
|
1048
|
+
$ kwartz -l ruby -p table1.ruby.plogic table1.html > table1.rb
|
1049
|
+
$ kwartz -l pierubis -p table1.ruby.plogic table1.html > table1.pierubis
|
1050
|
+
$ kwartz -l php -p table1.php.plogic table1.html > table1.php
|
1051
|
+
$ kwartz -l jstl -p table1.jstl.plogic table1.html > table1.jsp
|
1052
|
+
$ kwartz -l eperl -p table1.eperl.plogic table1.html > table1.eperl
|
1053
|
+
</pre>
|
1054
|
+
<a name="table1.eruby"></a>
|
1055
|
+
<div class="program_caption">
|
1056
|
+
output script (table1.eruby)</div>
|
1057
|
+
<pre class="program"><html>
|
1058
|
+
<body>
|
1059
|
+
|
1060
|
+
<table>
|
1061
|
+
<strong><% @list.each_with_index do |user, i| %></strong>
|
1062
|
+
<strong><% color = i % 2 == 1 ? '#FFCCCC' : '#CCCCFF' %></strong>
|
1063
|
+
<tr bgcolor="<strong><%= color %></strong>">
|
1064
|
+
<td><strong><%=h user[:name] %></strong></td>
|
1065
|
+
<td><strong><%= user[:mail] %></strong></td>
|
1066
|
+
</tr>
|
1067
|
+
<strong><% end %></strong>
|
1068
|
+
</table>
|
1069
|
+
|
1070
|
+
</body>
|
1071
|
+
</html>
|
1072
|
+
</pre>
|
1073
|
+
<a name="table1.rb"></a>
|
1074
|
+
<div class="program_caption">
|
1075
|
+
output script (table1.rb)</div>
|
1076
|
+
<pre class="program">_buf = ""; _buf << "<html>
|
1077
|
+
<body>
|
1078
|
+
|
1079
|
+
<table>\n";
|
1080
|
+
<strong>@list.each_with_index do |user, i|</strong>
|
1081
|
+
<strong>color = i % 2 == 1 ? '#FFCCCC' : '#CCCCFF'</strong>
|
1082
|
+
_buf << " <tr bgcolor=\""; _buf << (color).to_s; _buf << "\">
|
1083
|
+
<td>"; <strong>_buf << ERB::Util.h(user[:name]);</strong> _buf << "</td>
|
1084
|
+
<td>"; <strong>_buf << (user[:mail]).to_s;</strong> _buf << "</td>
|
1085
|
+
</tr>\n";
|
1086
|
+
<strong>end</strong>
|
1087
|
+
_buf << " </table>
|
1088
|
+
|
1089
|
+
</body>
|
1090
|
+
</html>\n";
|
1091
|
+
; _buf
|
982
1092
|
</pre>
|
983
|
-
<a name="table1.
|
1093
|
+
<a name="table1.rails"></a>
|
984
1094
|
<div class="program_caption">
|
985
|
-
output script (table1.
|
1095
|
+
output script (table1.rails)</div>
|
986
1096
|
<pre class="program"><html>
|
987
1097
|
<body>
|
988
1098
|
|
989
1099
|
<table>
|
990
|
-
<
|
991
|
-
<
|
992
|
-
<tr bgcolor="<
|
993
|
-
<td><
|
994
|
-
<td><
|
1100
|
+
<strong><% @list.each_with_index do |user, i| -%></strong>
|
1101
|
+
<strong><% color = i % 2 == 1 ? '#FFCCCC' : '#CCCCFF' -%></strong>
|
1102
|
+
<tr bgcolor="<strong><%= color %></strong>">
|
1103
|
+
<td><strong><%=h user[:name] %></strong></td>
|
1104
|
+
<td><strong><%= user[:mail] %></strong></td>
|
995
1105
|
</tr>
|
996
|
-
<
|
1106
|
+
<strong><% end -%></strong>
|
1107
|
+
</table>
|
1108
|
+
|
1109
|
+
</body>
|
1110
|
+
</html>
|
1111
|
+
</pre>
|
1112
|
+
<a name="table1.pierubis"></a>
|
1113
|
+
<div class="program_caption">
|
1114
|
+
output script (table1.pierubis)</div>
|
1115
|
+
<pre class="program"><html>
|
1116
|
+
<body>
|
1117
|
+
|
1118
|
+
<table>
|
1119
|
+
<strong><?rb @list.each_with_index do |user, i| ?></strong>
|
1120
|
+
<strong><?rb color = i % 2 == 1 ? '#FFCCCC' : '#CCCCFF' ?></strong>
|
1121
|
+
<tr bgcolor="<strong>@!{color}@</strong>">
|
1122
|
+
<td><strong>@{user[:name]}@</strong></td>
|
1123
|
+
<td><strong>@!{user[:mail]}@</strong></td>
|
1124
|
+
</tr>
|
1125
|
+
<strong><?rb end ?></strong>
|
997
1126
|
</table>
|
998
1127
|
|
999
1128
|
</body>
|
@@ -1006,14 +1135,14 @@ output script (table1.php)</div>
|
|
1006
1135
|
<body>
|
1007
1136
|
|
1008
1137
|
<table>
|
1009
|
-
<
|
1010
|
-
<
|
1011
|
-
<
|
1012
|
-
<tr bgcolor="<
|
1013
|
-
<td><
|
1014
|
-
<td><
|
1138
|
+
<strong><?php $i = 0; ?></strong>
|
1139
|
+
<strong><?php foreach ($list as $user) { ?></strong>
|
1140
|
+
<strong><?php $color = ++$i % 2 == 0 ? '#FFCCCC' : '#CCCCFF'; ?></strong>
|
1141
|
+
<tr bgcolor="<strong><?php echo $color; ?></strong>">
|
1142
|
+
<td><strong><?php echo htmlspecialchars($user['name']); ?></strong></td>
|
1143
|
+
<td><strong><?php echo $user['mail']; ?></strong></td>
|
1015
1144
|
</tr>
|
1016
|
-
<
|
1145
|
+
<strong><?php } ?></strong>
|
1017
1146
|
</table>
|
1018
1147
|
|
1019
1148
|
</body>
|
@@ -1028,33 +1157,33 @@ output script (JSTL 1.2)</div>
|
|
1028
1157
|
<body>
|
1029
1158
|
|
1030
1159
|
<table>
|
1031
|
-
<
|
1032
|
-
<
|
1033
|
-
<tr bgcolor="<
|
1034
|
-
<td><
|
1035
|
-
<td><
|
1160
|
+
<strong><c:forEach var="user" items="${list}" varStatus="loop"></strong>
|
1161
|
+
<strong><c:set var="color" value="${loop.index % 2 == 0 ? '#FFCCCC' : '#CCCCFF'}"/></strong>
|
1162
|
+
<tr bgcolor="<strong>${color}</strong>">
|
1163
|
+
<td><strong>${user.name}</strong></td>
|
1164
|
+
<td><strong>${user.mail}</strong></td>
|
1036
1165
|
</tr>
|
1037
|
-
<
|
1166
|
+
<strong></c:forEach></strong>
|
1038
1167
|
</table>
|
1039
1168
|
|
1040
1169
|
</body>
|
1041
1170
|
</html>
|
1042
1171
|
</pre>
|
1043
|
-
<a name="table1.
|
1172
|
+
<a name="table1.eperl"></a>
|
1044
1173
|
<div class="program_caption">
|
1045
1174
|
output script (ePerl)</div>
|
1046
1175
|
<pre class="program"><html>
|
1047
1176
|
<body>
|
1048
1177
|
|
1049
1178
|
<table>
|
1050
|
-
<
|
1051
|
-
<
|
1052
|
-
<
|
1053
|
-
<tr bgcolor="<
|
1054
|
-
<td><
|
1055
|
-
<td><
|
1179
|
+
<strong><? $i = 0; !></strong>
|
1180
|
+
<strong><? foreach ($user in @list) { !></strong>
|
1181
|
+
<strong><? $color = ++$i % 2 == 0 ? '#FFCCCC' : '#CCCCFF'; !></strong>
|
1182
|
+
<tr bgcolor="<strong><?= $color !></strong>">
|
1183
|
+
<td><strong><?= encode_entities($user{'name'}) !></strong></td>
|
1184
|
+
<td><strong><?= $user{'mail'} !></strong></td>
|
1056
1185
|
</tr>
|
1057
|
-
<
|
1186
|
+
<strong><? } !></strong>
|
1058
1187
|
</table>
|
1059
1188
|
|
1060
1189
|
</body>
|
@@ -1070,9 +1199,9 @@ output script (ePerl)</div>
|
|
1070
1199
|
<a name="delspan1.html"></a>
|
1071
1200
|
<div class="program_caption">
|
1072
1201
|
presentation data (delspan1.html)</div>
|
1073
|
-
<pre class="program"><h1><span <
|
1202
|
+
<pre class="program"><h1><span <strong>id="mark:title"</strong>>title</span></h1>
|
1074
1203
|
|
1075
|
-
Hello <span <
|
1204
|
+
Hello <span <strong>kw:d="value: user"</strong>>World</span>!
|
1076
1205
|
</pre>
|
1077
1206
|
<a name="delspan1.plogic"></a>
|
1078
1207
|
<div class="program_caption">
|
@@ -1084,23 +1213,23 @@ presentation logic (delspan1.plogic)</div>
|
|
1084
1213
|
<a name="delspan1.expected"></a>
|
1085
1214
|
<div class="terminal_caption">
|
1086
1215
|
compile</div>
|
1087
|
-
<pre class="terminal">$ kwartz -p delspan1.plogic <
|
1088
|
-
<h1><
|
1216
|
+
<pre class="terminal">$ kwartz -p delspan1.plogic <strong>--delspan</strong> delspan1.html
|
1217
|
+
<h1><strong><%= title %></strong></h1>
|
1089
1218
|
|
1090
|
-
Hello <
|
1219
|
+
Hello <strong><%= user %></strong>!
|
1091
1220
|
</pre>
|
1092
1221
|
<p>The span tags are not removed when they have other attributes.
|
1093
1222
|
</p>
|
1094
1223
|
<a name="delspan2.html"></a>
|
1095
1224
|
<div class="program_caption">
|
1096
1225
|
presentation data (delspan2.html)</div>
|
1097
|
-
<pre class="program">Hello <span <
|
1226
|
+
<pre class="program">Hello <span <strong>kw:d="value: user" style="color:black"</strong>>World</span>!
|
1098
1227
|
</pre>
|
1099
1228
|
<a name="delspan2.expected"></a>
|
1100
1229
|
<div class="terminal_caption">
|
1101
1230
|
compile</div>
|
1102
|
-
<pre class="terminal">$ kwartz <
|
1103
|
-
Hello <
|
1231
|
+
<pre class="terminal">$ kwartz <strong>--delspan</strong> delspan2.html
|
1232
|
+
Hello <strong><span style="color:black"></strong><%= user %><strong></span></strong>!
|
1104
1233
|
</pre>
|
1105
1234
|
<br>
|
1106
1235
|
|
@@ -1113,20 +1242,20 @@ This is useful to share common presentation logic in many files.
|
|
1113
1242
|
<a name="link_to2.plogic"></a>
|
1114
1243
|
<div class="program_caption">
|
1115
1244
|
link_to.plogic</div>
|
1116
|
-
<pre class="program"><
|
1117
|
-
elem:
|
1245
|
+
<pre class="program"><strong>#link_to_new</strong> {
|
1246
|
+
elem: start_link_tag :action=>'new';
|
1118
1247
|
}
|
1119
|
-
<
|
1120
|
-
elem:
|
1248
|
+
<strong>#link_to_show</strong> {
|
1249
|
+
elem: start_link_tag :action=>'show', :id=>@member;
|
1121
1250
|
}
|
1122
|
-
<
|
1123
|
-
elem:
|
1251
|
+
<strong>#link_to_edit</strong> {
|
1252
|
+
elem: start_link_tag :action=>'edit', :id=>@member;
|
1124
1253
|
}
|
1125
|
-
<
|
1126
|
-
elem:
|
1254
|
+
<strong>#link_to_list</strong> {
|
1255
|
+
elem: start_link_tag :action=>'list';
|
1127
1256
|
}
|
1128
|
-
<
|
1129
|
-
stag:
|
1257
|
+
<strong>#link_to_destroy</strong> {
|
1258
|
+
stag: start_link_tag({:action=>'destroy', :id=>@member}, :confirm=>'Are you sure?');
|
1130
1259
|
}
|
1131
1260
|
</pre>
|
1132
1261
|
<a name="show2.html"></a>
|
@@ -1136,13 +1265,13 @@ show.html</div>
|
|
1136
1265
|
Name: <span id="mark:name">foo</span> <br>
|
1137
1266
|
Email: <span id="mark:email">foo@mail.com</span> <br>
|
1138
1267
|
</p>
|
1139
|
-
<a href="#" <
|
1140
|
-
<a href="#" <
|
1141
|
-
<a href="#" <
|
1268
|
+
<a href="#" <strong>id="link_to_edit"</strong>>Edit this member</a> |
|
1269
|
+
<a href="#" <strong>id="link_to_new"</strong>>Create new member</a> |
|
1270
|
+
<a href="#" <strong>id="link_to_list"</strong>>Return to list</a>
|
1142
1271
|
</pre>
|
1143
1272
|
<div class="program_caption">
|
1144
1273
|
show.plogic</div>
|
1145
|
-
<pre class="program"><
|
1274
|
+
<pre class="program"><strong>@import 'link_to.plogic';</strong>
|
1146
1275
|
|
1147
1276
|
#name {
|
1148
1277
|
Value: @member.name;
|
@@ -1159,24 +1288,24 @@ compile</div>
|
|
1159
1288
|
Name: <span><%=h @member.name %></span> <br>
|
1160
1289
|
Email: <span><%=h @member.email %></span> <br>
|
1161
1290
|
</p>
|
1162
|
-
<%=
|
1163
|
-
<%=
|
1164
|
-
<%=
|
1291
|
+
<%= start_link_tag :action=>'edit', :id=>@member %> |
|
1292
|
+
<%= start_link_tag :action=>'new' %> |
|
1293
|
+
<%= start_link_tag :action=>'list' %>
|
1165
1294
|
</pre>
|
1166
1295
|
<br>
|
1167
1296
|
|
1168
1297
|
|
1169
1298
|
<a name="import-elem"></a>
|
1170
1299
|
<h3 class="section2">Import Elements in Other Files</h3>
|
1171
|
-
<p>Command-line option '-i <
|
1300
|
+
<p>Command-line option '-i <em>filename,...</em>' imports element definitions form other files.
|
1172
1301
|
</p>
|
1173
1302
|
<a name="form.html"></a>
|
1174
1303
|
<div class="program_caption">
|
1175
1304
|
form.html</div>
|
1176
1305
|
<pre class="program"><form>
|
1177
|
-
<div <
|
1178
|
-
<
|
1179
|
-
<
|
1306
|
+
<div <strong>id="mark:form_content"</strong>>
|
1307
|
+
<strong>Name: <input type="text"><br></strong>
|
1308
|
+
<strong>Password: <input type="password"><br></strong>
|
1180
1309
|
</div>
|
1181
1310
|
<input type="submit">
|
1182
1311
|
</form>
|
@@ -1185,7 +1314,7 @@ form.html</div>
|
|
1185
1314
|
<div class="program_caption">
|
1186
1315
|
new.html</div>
|
1187
1316
|
<pre class="program"><form action="/new">
|
1188
|
-
<div <
|
1317
|
+
<div <strong>id="mark:placeholder"</strong>></div>
|
1189
1318
|
<input type="submit" value="Create">
|
1190
1319
|
</form>
|
1191
1320
|
</pre>
|
@@ -1193,19 +1322,19 @@ new.html</div>
|
|
1193
1322
|
<div class="program_caption">
|
1194
1323
|
new.plogic</div>
|
1195
1324
|
<pre class="program">/* use element which is defined other file */
|
1196
|
-
<
|
1325
|
+
<strong>#placeholder</strong> {
|
1197
1326
|
logic: {
|
1198
|
-
<
|
1327
|
+
<strong>_content(form_content)</strong>
|
1199
1328
|
}
|
1200
1329
|
}
|
1201
1330
|
</pre>
|
1202
1331
|
<a name="new.expected"></a>
|
1203
1332
|
<div class="terminal_caption">
|
1204
1333
|
compile</div>
|
1205
|
-
<pre class="terminal">$ kwartz <
|
1334
|
+
<pre class="terminal">$ kwartz <strong>-i form.html</strong> -p new.plogic new.html
|
1206
1335
|
<form action="/new">
|
1207
|
-
<
|
1208
|
-
<
|
1336
|
+
<strong>Name: <input type="text"><br></strong>
|
1337
|
+
<strong>Password: <input type="password"><br></strong>
|
1209
1338
|
<input type="submit" value="Create">
|
1210
1339
|
</form>
|
1211
1340
|
</pre>
|
@@ -1214,15 +1343,15 @@ compile</div>
|
|
1214
1343
|
|
1215
1344
|
<a name="extract"></a>
|
1216
1345
|
<h3 class="section2">Extract Element</h3>
|
1217
|
-
<p>Command option '-X <
|
1218
|
-
and command option '-x <
|
1346
|
+
<p>Command option '-X <em>name</em>' extracts element marked as <em>name</em>
|
1347
|
+
and command option '-x <em>name</em>' extracts content of element.
|
1219
1348
|
</p>
|
1220
1349
|
<a name="show.html"></a>
|
1221
1350
|
<div class="program_caption">
|
1222
1351
|
show.html</div>
|
1223
1352
|
<pre class="program"><html>
|
1224
1353
|
<body>
|
1225
|
-
<div <
|
1354
|
+
<div <strong>id="mark:content"</strong>>
|
1226
1355
|
<h1>Show</h1>
|
1227
1356
|
<p>Name: <span id="mark:name">foo</span></p>
|
1228
1357
|
<p>Email: <span id="mark:email">foo@mail.com</span></p>
|
@@ -1242,7 +1371,7 @@ show.plogic</div>
|
|
1242
1371
|
</pre>
|
1243
1372
|
<div class="terminal_caption">
|
1244
1373
|
compile with '-X'</div>
|
1245
|
-
<pre class="terminal">$ kwartz <
|
1374
|
+
<pre class="terminal">$ kwartz <strong>-X content</strong> -p show.plogic show.html
|
1246
1375
|
<div>
|
1247
1376
|
<h1>Show</h1>
|
1248
1377
|
<p>Name: <span><%= user.name %></span></p>
|
@@ -1252,7 +1381,7 @@ compile with '-X'</div>
|
|
1252
1381
|
<a name="test_show_cont.expected"></a>
|
1253
1382
|
<div class="terminal_caption">
|
1254
1383
|
compile with '-x'</div>
|
1255
|
-
<pre class="terminal">$ kwartz <
|
1384
|
+
<pre class="terminal">$ kwartz <strong>-x content</strong> -p show.plogic show.html
|
1256
1385
|
<h1>Show</h1>
|
1257
1386
|
<p>Name: <span><%= user.name %></span></p>
|
1258
1387
|
<p>Email: <span><%= user.email %></span></p>
|
@@ -1278,7 +1407,7 @@ print-stmt.eruby.plogic</div>
|
|
1278
1407
|
logic: {
|
1279
1408
|
for item in list
|
1280
1409
|
_stag
|
1281
|
-
<
|
1410
|
+
<strong>print item</strong>
|
1282
1411
|
_etag
|
1283
1412
|
end
|
1284
1413
|
}
|
@@ -1290,7 +1419,7 @@ compile</div>
|
|
1290
1419
|
<pre class="terminal">$ kwartz -l eruby -p print-stmt.eruby.plogic print-stmt.html
|
1291
1420
|
<ul>
|
1292
1421
|
<% for item in list %>
|
1293
|
-
<li id="items"><
|
1422
|
+
<li id="items"><strong><%= item %></strong></li>
|
1294
1423
|
<% end %>
|
1295
1424
|
</ul>
|
1296
1425
|
</pre>
|
@@ -1301,7 +1430,7 @@ print-stmt.php.plogic</div>
|
|
1301
1430
|
logic: {
|
1302
1431
|
foreach ($list as $item) {
|
1303
1432
|
_stag();
|
1304
|
-
<
|
1433
|
+
<strong>print($item);</strong>
|
1305
1434
|
_etag();
|
1306
1435
|
}
|
1307
1436
|
}
|
@@ -1313,7 +1442,7 @@ compile</div>
|
|
1313
1442
|
<pre class="terminal">$ kwartz -l php -p print-stmt.php.plogic print-stmt.html
|
1314
1443
|
<ul>
|
1315
1444
|
<?php foreach ($list as $item) { ?>
|
1316
|
-
<li id="items"><
|
1445
|
+
<li id="items"><strong><?php echo $item; ?></strong></li>
|
1317
1446
|
<?php } ?>
|
1318
1447
|
</ul>
|
1319
1448
|
</pre>
|
@@ -1324,7 +1453,7 @@ print-stmt.jstl.plogic</div>
|
|
1324
1453
|
logic: {
|
1325
1454
|
<c:forEach var="item" items="${list}">
|
1326
1455
|
_stag
|
1327
|
-
<
|
1456
|
+
<strong>print item</strong>
|
1328
1457
|
_etag
|
1329
1458
|
</c:forEach>
|
1330
1459
|
}
|
@@ -1338,7 +1467,7 @@ compile (JSTL 1.2)</div>
|
|
1338
1467
|
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
|
1339
1468
|
<ul>
|
1340
1469
|
<c:forEach var="item" items="${list}">
|
1341
|
-
<li id="items"><
|
1470
|
+
<li id="items"><strong>${item}</strong></li>
|
1342
1471
|
</c:forEach>
|
1343
1472
|
</ul>
|
1344
1473
|
</pre>
|
@@ -1349,7 +1478,7 @@ compile (JSTL 1.1)</div>
|
|
1349
1478
|
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
|
1350
1479
|
<ul>
|
1351
1480
|
<c:forEach var="item" items="${list}">
|
1352
|
-
<li id="items"><
|
1481
|
+
<li id="items"><strong><c:out value="${item}"/></strong></li>
|
1353
1482
|
</c:forEach>
|
1354
1483
|
</ul>
|
1355
1484
|
</pre>
|
@@ -1374,12 +1503,12 @@ document-test.html</div>
|
|
1374
1503
|
<a name="document-test.plogic"></a>
|
1375
1504
|
<div class="program_caption">
|
1376
1505
|
document-test.plogic</div>
|
1377
|
-
<pre class="program"><
|
1378
|
-
<
|
1506
|
+
<pre class="program"><strong>#DOCUMENT</strong> {
|
1507
|
+
<strong>begin:</strong> {
|
1379
1508
|
title = _context[:title]
|
1380
1509
|
user = _context[:user]
|
1381
1510
|
}
|
1382
|
-
<
|
1511
|
+
<strong>end:</strong> {
|
1383
1512
|
print "<!--end-->\n"
|
1384
1513
|
}
|
1385
1514
|
}
|
@@ -1388,12 +1517,368 @@ document-test.plogic</div>
|
|
1388
1517
|
<div class="terminal_caption">
|
1389
1518
|
compile</div>
|
1390
1519
|
<pre class="terminal">$ kwartz -p document-test.plogic document-test.html
|
1391
|
-
<
|
1392
|
-
<
|
1520
|
+
<strong><% title = _context[:title] %></strong>
|
1521
|
+
<strong><% user = _context[:user] %></strong>
|
1393
1522
|
<html>
|
1394
1523
|
<body>hello</body>
|
1395
1524
|
</html>
|
1396
|
-
<
|
1525
|
+
<strong><%= "<!--end-->\n" %></strong>
|
1526
|
+
</pre>
|
1527
|
+
<br>
|
1528
|
+
|
1529
|
+
|
1530
|
+
<a name="detail-defun"></a>
|
1531
|
+
<h3 class="section2">Compile Template into a Function of Ruby or PHP</h3>
|
1532
|
+
<p>Using the command-line option '<code>-a defun</code>', you can compile templates into a function of Ruby or PHP.
|
1533
|
+
</p>
|
1534
|
+
<a name="defun1.html"></a>
|
1535
|
+
<div class="program_caption">
|
1536
|
+
defun1.html : presentation data</div>
|
1537
|
+
<pre class="program">Hello <span id="user">user</span> !
|
1538
|
+
<ul id="mark:list">
|
1539
|
+
<li id="mark:item">xxx</li>
|
1540
|
+
</ul>
|
1541
|
+
</pre>
|
1542
|
+
<a name="defun1.plogic"></a>
|
1543
|
+
<div class="program_caption">
|
1544
|
+
defun1.plogic : presentation logic</div>
|
1545
|
+
<pre class="program">#user {
|
1546
|
+
elem: @user;
|
1547
|
+
}
|
1548
|
+
|
1549
|
+
#list {
|
1550
|
+
logic: {
|
1551
|
+
_stag
|
1552
|
+
for item in @list
|
1553
|
+
_cont
|
1554
|
+
end
|
1555
|
+
_etag
|
1556
|
+
}
|
1557
|
+
}
|
1558
|
+
|
1559
|
+
#item {
|
1560
|
+
value: item;
|
1561
|
+
}
|
1562
|
+
</pre>
|
1563
|
+
<a name="defun1.expected"></a>
|
1564
|
+
<div class="terminal_caption">
|
1565
|
+
Compile</div>
|
1566
|
+
<pre class="terminal">$ kwartz -l eruby <strong>-a defun</strong> -p defun1.plogic defun1.html | tee defun1.rb
|
1567
|
+
<strong>module View</strong>
|
1568
|
+
|
1569
|
+
(@@proc_table ||= {})['defun1'] = proc do
|
1570
|
+
_erbout = ''; _erbout.concat "Hello "; _erbout.concat(( @user ).to_s); _erbout.concat " !\n"
|
1571
|
+
_erbout.concat "<ul>\n"
|
1572
|
+
for item in @list
|
1573
|
+
_erbout.concat " <li>"; _erbout.concat(( item ).to_s); _erbout.concat "</li>\n"
|
1574
|
+
end
|
1575
|
+
_erbout.concat "</ul>\n"
|
1576
|
+
_erbout
|
1577
|
+
end#proc
|
1578
|
+
|
1579
|
+
<strong>module_function</strong>
|
1580
|
+
<strong>def expand_defun1(context={})</strong>
|
1581
|
+
if context.is_a?(Hash)
|
1582
|
+
hash = context
|
1583
|
+
context = Object.new
|
1584
|
+
hash.each { |key, val| context.instance_variable_set("@#{key}", val) }
|
1585
|
+
end
|
1586
|
+
proc_obj = @@proc_table['defun1']
|
1587
|
+
context.instance_eval(&proc_obj)
|
1588
|
+
<strong>end</strong>
|
1589
|
+
|
1590
|
+
<strong>end</strong>
|
1591
|
+
</pre>
|
1592
|
+
<p>The following command-line properties are available with '-a defun'.
|
1593
|
+
</p>
|
1594
|
+
<dl class="dl1">
|
1595
|
+
<dt class="dt1">
|
1596
|
+
--module=<em>name</em></dt>
|
1597
|
+
<dd class="dd1">
|
1598
|
+
Module name. If false or null then no module is used. Default is 'View'.
|
1599
|
+
</dd>
|
1600
|
+
<dt class="dt1">
|
1601
|
+
--verb=<em>name</em></dt>
|
1602
|
+
<dd class="dd1">
|
1603
|
+
Verb. Default is 'expand'.
|
1604
|
+
</dd>
|
1605
|
+
<dt class="dt1">
|
1606
|
+
--method=<em>name</em></dt>
|
1607
|
+
<dd class="dd1">
|
1608
|
+
Method name. Default is "#{verb}_#{basename}".
|
1609
|
+
</dd>
|
1610
|
+
</dl>
|
1611
|
+
<p>The following languages are available with '-a defun'.
|
1612
|
+
</p>
|
1613
|
+
<ul type="disc">
|
1614
|
+
<li>-l eruby
|
1615
|
+
</li>
|
1616
|
+
<li>-l ruby
|
1617
|
+
</li>
|
1618
|
+
<li>-l erubis
|
1619
|
+
</li>
|
1620
|
+
<li>-l pierubis
|
1621
|
+
</li>
|
1622
|
+
<li>-l php
|
1623
|
+
</li>
|
1624
|
+
</ul>
|
1625
|
+
<br>
|
1626
|
+
|
1627
|
+
|
1628
|
+
<br>
|
1629
|
+
|
1630
|
+
|
1631
|
+
<a name="rails"></a>
|
1632
|
+
<h2 class="section1">Ruby on Rails Support</h2>
|
1633
|
+
<p>This section shows how to use Kwartz with Ruby on Rails.
|
1634
|
+
See 'examples/rails1' and 'examples/rails2' for examples.
|
1635
|
+
</p>
|
1636
|
+
<a name="rails_template"></a>
|
1637
|
+
<h3 class="section2">Support of Ruby on Rails</h3>
|
1638
|
+
<p>If you want to use Kwartz with Ruby on Rails, add the following code in your 'app/controllers/application.rb' and restart web server.
|
1639
|
+
</p>
|
1640
|
+
<pre class="program">require 'kwartz/helper/rails'
|
1641
|
+
ActionView::Base.register_template_handler('html', Kwartz::Helper::RailsTemplate)
|
1642
|
+
#Kwartz::Helper::RailsTemplate.lang = 'rails' # or eruby/ruby/erubis/pierubis
|
1643
|
+
#Kwartz::Helper::RailsTemplate.pdata_suffix = '.html'
|
1644
|
+
#Kwartz::Helper::RailsTemplate.plogic_suffix = '.plogic'
|
1645
|
+
#Kwartz::Helper::RailsTemplate.default_properties = { :escape=>false }
|
1646
|
+
#Kwartz::Helper::RailsTemplate.use_cache = true
|
1647
|
+
#Kwartz::Helper::RailsTemplate.debug = true
|
1648
|
+
</pre>
|
1649
|
+
<p>Layout files ('app/views/layouts/xxx.{html,plogic}') are also available.
|
1650
|
+
The following is an example to use layout files.
|
1651
|
+
</p>
|
1652
|
+
<div class="program_caption">
|
1653
|
+
app/views/member/list.html</div>
|
1654
|
+
<pre class="program"><html>
|
1655
|
+
<body>
|
1656
|
+
<h1 <strong>id="page_title"</strong>></h1>
|
1657
|
+
<div <strong>id="page_content"</strong>>
|
1658
|
+
<ul id="mark:list">
|
1659
|
+
<li id="mark:item"></li>
|
1660
|
+
</ul>
|
1661
|
+
</div>
|
1662
|
+
</body>
|
1663
|
+
</html>
|
1664
|
+
</pre>
|
1665
|
+
<div class="program_caption">
|
1666
|
+
app/views/xxx/index.plogic</div>
|
1667
|
+
<pre class="program">#list {
|
1668
|
+
logic: {
|
1669
|
+
for item in @list
|
1670
|
+
_elem
|
1671
|
+
end
|
1672
|
+
}
|
1673
|
+
}
|
1674
|
+
|
1675
|
+
#item {
|
1676
|
+
value: item;
|
1677
|
+
}
|
1678
|
+
</pre>
|
1679
|
+
<div class="program_caption">
|
1680
|
+
app/views/layouts/xxx.html</div>
|
1681
|
+
<pre class="program"><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
1682
|
+
<html>
|
1683
|
+
<head>
|
1684
|
+
<title id="mark:header_title"></title>
|
1685
|
+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
1686
|
+
</head>
|
1687
|
+
<body>
|
1688
|
+
|
1689
|
+
<h1 class="title" <strong>id="replace_content_with_content:page_title"</strong>>...page title...</h1>
|
1690
|
+
<div <strong>id="replace_element_with_content:page_content"</strong>>
|
1691
|
+
...page content...
|
1692
|
+
</div>
|
1693
|
+
|
1694
|
+
<p>copyright&copy; 2006 kuwata-lab.com all rights reserved.</p>
|
1695
|
+
|
1696
|
+
</body>
|
1697
|
+
</html>
|
1698
|
+
</pre>
|
1699
|
+
<div class="program_caption">
|
1700
|
+
app/views/layouts/xxx.plogic</div>
|
1701
|
+
<pre class="program">#header_title {
|
1702
|
+
cont: 'Member: ' + controller.action_name;
|
1703
|
+
}
|
1704
|
+
</pre>
|
1705
|
+
<p>See the 'examples/rails2' directory for example of using Kwartz with Ruby on Rails.
|
1706
|
+
</p>
|
1707
|
+
<br>
|
1708
|
+
|
1709
|
+
|
1710
|
+
<a name="rails_start_link_tag"></a>
|
1711
|
+
<h3 class="section2"><code>link_to()</code> method in Ruby on Rails</h3>
|
1712
|
+
<p><code>link_to()</code> method in Ruby on Rails is a little incompatible with Kwartz
|
1713
|
+
because you must specify link label in both presentation data and presentation logic.
|
1714
|
+
It's not DRY.
|
1715
|
+
</p>
|
1716
|
+
<div class="program_caption">
|
1717
|
+
presentation data</div>
|
1718
|
+
<pre class="program"><a href="#" id="mark:link_to_new"><strong>Create new recipe</strong></a>
|
1719
|
+
</pre>
|
1720
|
+
<div class="program_caption">
|
1721
|
+
presentation logic</div>
|
1722
|
+
<pre class="program">#link_to_new {
|
1723
|
+
elem: link_to <strong>'Create new recipe'</strong>, :action=>'new';
|
1724
|
+
}
|
1725
|
+
</pre>
|
1726
|
+
<p>It is recommended to use start_link_tag() and start_remote_link_tag() instead of link_to() and link_to_remote() because the formers print only start tag of anchor.
|
1727
|
+
</p>
|
1728
|
+
<div class="program_caption">
|
1729
|
+
presentation data</div>
|
1730
|
+
<pre class="program"><a href="#" id="mark:link_to_new">Create new recipe</a>
|
1731
|
+
</pre>
|
1732
|
+
<div class="program_caption">
|
1733
|
+
presentation logic</div>
|
1734
|
+
<pre class="program">#link_to_new {
|
1735
|
+
stag: <strong>start_link_tag</strong> :action=>'new', :controller=>'recipes';
|
1736
|
+
}
|
1737
|
+
</pre>
|
1738
|
+
<div class="program_caption">
|
1739
|
+
expected result</div>
|
1740
|
+
<pre class="program"><a href="/recipes/new">Create new recipe</a>
|
1741
|
+
</pre>
|
1742
|
+
<p>To use start_link_tag() and start_remote_link_tag(), include Kwartz::Helper::ActionViewHelper to ApplicationHelper module in 'app/helpers/application_helper.rb'.
|
1743
|
+
</p>
|
1744
|
+
<div class="program_caption">
|
1745
|
+
app/helpers/application_helper.rb</div>
|
1746
|
+
<pre class="program"><strong>require 'kwartz/helper/rails'</strong>
|
1747
|
+
module ApplicationHelper
|
1748
|
+
<strong>include Kwartz::Helper::ActionViewHelper</strong>
|
1749
|
+
end
|
1750
|
+
</pre>
|
1751
|
+
<p>The following is the definition of start_link_tag() and start_remote_link_tag().
|
1752
|
+
They are defined in Kwartz::Helper::ActionViewHelper module which is defined in
|
1753
|
+
'kwartz/helper/rails.rb'.
|
1754
|
+
</p>
|
1755
|
+
<div class="program_caption">
|
1756
|
+
definition of start_link_tag() and start_remote_link_tag()</div>
|
1757
|
+
<pre class="program">module Kwartz::Helper::ActionViewHelper
|
1758
|
+
|
1759
|
+
def start_link_tag(options = {}, html_options = nil, *parameters_for_method_reference)
|
1760
|
+
s = link_to('', options, html_options, *parameters_for_method_reference)
|
1761
|
+
s.sub!(/<\/a>\z/, '')
|
1762
|
+
s
|
1763
|
+
end
|
1764
|
+
alias anchor start_link_tag
|
1765
|
+
|
1766
|
+
def start_remote_link_tag(options = {}, html_options = {})
|
1767
|
+
s = link_to_remote(options, html_options)
|
1768
|
+
s.sub!(/<\/a>\z/, '')
|
1769
|
+
s
|
1770
|
+
end
|
1771
|
+
alias anchor_remote start_remote_link_tag
|
1772
|
+
|
1773
|
+
end
|
1774
|
+
</pre>
|
1775
|
+
<br>
|
1776
|
+
|
1777
|
+
|
1778
|
+
<a name="rails-layout"></a>
|
1779
|
+
<h3 class="section2">Layout Option in Controller</h3>
|
1780
|
+
<ul type="disc">
|
1781
|
+
<li><code>layout()</code> is available.
|
1782
|
+
<pre class="program">class MemberController < ApplicationController
|
1783
|
+
<strong>layout 'members2', :except=>['show', 'edit']</strong>
|
1784
|
+
...
|
1785
|
+
end
|
1786
|
+
</pre>
|
1787
|
+
</li>
|
1788
|
+
</ul>
|
1789
|
+
<ul type="disc">
|
1790
|
+
<li><code>render()</code> with <code>:layout</code> parameter is available.
|
1791
|
+
<pre class="program">class MemberController < ApplicationController
|
1792
|
+
def list
|
1793
|
+
@member_pages, @members = paginate :members, :per_page => 10
|
1794
|
+
<strong>render :layout => 'members2'</strong>
|
1795
|
+
end
|
1796
|
+
...
|
1797
|
+
end
|
1798
|
+
</pre>
|
1799
|
+
</li>
|
1800
|
+
</ul>
|
1801
|
+
<br>
|
1802
|
+
|
1803
|
+
|
1804
|
+
<a name="rails-scaffold"></a>
|
1805
|
+
<h3 class="section2">Scaffold Kwartz Template</h3>
|
1806
|
+
<p>There is no 'generate scaffold' script for Kwartz template.
|
1807
|
+
Instead, use <a href="http://kwatable.rubyforge.net">Kwatable</a>.
|
1808
|
+
</p>
|
1809
|
+
<p><a href="http://kwatable.rubyforge.net">Kwatable</a> is a script to generate severail files (SQL, DTO, Kwartz template, and so on) from table definition file.
|
1810
|
+
It's more sophisticated than Rails' scaffold generating script.
|
1811
|
+
</p>
|
1812
|
+
<br>
|
1813
|
+
|
1814
|
+
|
1815
|
+
<a name="rails-helper-methods"></a>
|
1816
|
+
<h3 class="section2">Rails Helper Methods</h3>
|
1817
|
+
<p>(Notice: this is experimental feature. The spec may be changed in the future.)
|
1818
|
+
</p>
|
1819
|
+
<p>It is able to embed Rails' helper method in kw:d attribute.
|
1820
|
+
</p>
|
1821
|
+
<pre class="program">## text_field, password_field
|
1822
|
+
<input type="text" size="10" maxsize="20" <strong>kw:d="text_field 'user', 'name'"</strong>>
|
1823
|
+
=> <%= text_field 'user', 'name', :size=>10, :maxsize=>20 %>
|
1824
|
+
<input type="text" name="user[name]" <strong>kw:d="text_field :size=>10"</strong>>
|
1825
|
+
=> <%= text_field "user", "name", :size=>10 %>
|
1826
|
+
<input type="text" id="user_name" size="10" <strong>kw:d="text_field"</strong>>
|
1827
|
+
=> <%= text_field "user", "name", :size=>10 %>
|
1828
|
+
|
1829
|
+
## link_to, link_to_remote
|
1830
|
+
<a href="#" <strong>kw:d="link_to :action=>'list'"</strong>>Show list</a>
|
1831
|
+
=> <%= link_to 'Show list', :action=>'list' %>
|
1832
|
+
|
1833
|
+
## start_link_tag, start_remote_link_tag
|
1834
|
+
<a href="#" <strong>kw:d="start_link_tag :action=>'list'"</strong>>Show list</a>
|
1835
|
+
=> <%= start_link_tag 'action'=>'list' %>Show list</a>
|
1836
|
+
|
1837
|
+
## mail_to
|
1838
|
+
<a href="mail:www@example.com" <strong>kw:d="mail_to"</strong>>admin</a>
|
1839
|
+
=> <%= mail_to "www@example.com", "admin" %>
|
1840
|
+
|
1841
|
+
## form_tag
|
1842
|
+
<form action="show" <strong>kw:d="form_tag :id=>2"</strong>> ... </form>
|
1843
|
+
=> <%= form_tag :action=>"show", :id=>2 %> ... </form>
|
1844
|
+
|
1845
|
+
## submit_tag
|
1846
|
+
<input type="submit" value="OK" <strong>kw:d="submit_tag"</strong>>
|
1847
|
+
=> <%= submit_tag "OK" %>
|
1848
|
+
|
1849
|
+
## text_area
|
1850
|
+
<textarea cols="30" rows="3" id="user_desc" <strong>kw:d="text_area"</strong>></textarea>
|
1851
|
+
=> <%= text_area "user", "desc", :cols=>30, :rows=>3 %>
|
1852
|
+
<textarea cols="30" rows="3" name="user[desc]" <strong>kw:d="text_area"</strong>></textarea>
|
1853
|
+
=> <%= text_area "user", "desc", :cols=>30, :rows=>3 %>
|
1854
|
+
|
1855
|
+
## hidden_field
|
1856
|
+
<input type="hidden" id="user_id" <strong>kw:d="hidden_field"</strong>>
|
1857
|
+
=> <%= hidden_field "user", "id" %>
|
1858
|
+
<input type="hidden" name="user[id]" <strong>kw:d="hidden_field"</strong>>
|
1859
|
+
=> <%= hidden_field "user", "id" %>
|
1860
|
+
|
1861
|
+
## check_box
|
1862
|
+
<input type="checkbox" id="user_chk1" <strong>kw:d="check_box"</strong>>
|
1863
|
+
=> <%= check_box "user", "chk1" %>
|
1864
|
+
<input type="checkbox" name="user[chk2]" <strong>kw:d="check_box"</strong>>
|
1865
|
+
=> <%= check_box "user", "chk2" %>
|
1866
|
+
|
1867
|
+
## radio_button
|
1868
|
+
<input type="radio" id="user_radio" value="val1" <strong>kw:d="radio_button"</strong>>
|
1869
|
+
=> <%= radio_button "user", "radio", "val1" %>
|
1870
|
+
<input type="radio" name="user[radio]" value="val2" <strong>kw:d="radio_button"</strong>>
|
1871
|
+
=> <%= radio_button "user", "radio", "val2" %>
|
1872
|
+
|
1873
|
+
## select, collection_select, country_select, time_zone_select, date_select, datetime_select
|
1874
|
+
<select name="user[birth]" <strong>kw:d="date_select :start_year=>1970"</strong>>
|
1875
|
+
<option value="2000">2000</option>
|
1876
|
+
</select>
|
1877
|
+
=> <% date_select "user", "birth", :start_year=>1970 %>
|
1878
|
+
|
1879
|
+
## image_tag, link_image_to, link_to_image
|
1880
|
+
<img src="foo.gif" alt="text" width="20" heigth="10" <strong>kw:d="image_tag :size=>'30x40'"</strong>>
|
1881
|
+
=> <%= image_tag "foo.gif", :alt=>"text", :size=>'30x40' %>
|
1397
1882
|
</pre>
|
1398
1883
|
<br>
|
1399
1884
|
|
@@ -1403,7 +1888,7 @@ compile</div>
|
|
1403
1888
|
|
1404
1889
|
<a name="topics"></a>
|
1405
1890
|
<h2 class="section1">Other Topics</h2>
|
1406
|
-
<a name="restriction1"></a>
|
1891
|
+
<a name="topics-restriction1"></a>
|
1407
1892
|
<h3 class="section2">Restrictions around presentation logic</h3>
|
1408
1893
|
<p>There are several restrictions in presentation logic file.
|
1409
1894
|
</p>
|
@@ -1477,7 +1962,7 @@ compile</div>
|
|
1477
1962
|
<br>
|
1478
1963
|
|
1479
1964
|
|
1480
|
-
<a name="restriction2"></a>
|
1965
|
+
<a name="topics-restriction2"></a>
|
1481
1966
|
<h3 class="section2">Restrictions around presentation data</h3>
|
1482
1967
|
<p>Kwartz parses presentation data file by regular expression pattern matching.
|
1483
1968
|
It means that Kwartz doesn't use HTML parser nor XML parser for parsing presentation data.
|
@@ -1506,14 +1991,14 @@ This approach enables Kwartz to handle any type of text file, and also brings th
|
|
1506
1991
|
<ul type="disc">
|
1507
1992
|
<li>Attribute values should be surrounded with '<code>"</code>'.
|
1508
1993
|
<pre class="program"><!-- Kwartz fails parsing because attribute value is not surrounded with '"'. -->
|
1509
|
-
<h1 id=
|
1994
|
+
<h1 id='id:title' class=title>title</h1>
|
1510
1995
|
</pre>
|
1511
1996
|
</li>
|
1512
1997
|
</ul>
|
1513
1998
|
<br>
|
1514
1999
|
|
1515
2000
|
|
1516
|
-
<a name="makefile"></a>
|
2001
|
+
<a name="topics-makefile"></a>
|
1517
2002
|
<h3 class="section2">Makefile and Rakefile</h3>
|
1518
2003
|
<p>The followings are examples of Makefile, Rakefile, Rantfile, and Rookbook.
|
1519
2004
|
</p>
|
@@ -1567,94 +2052,112 @@ file "file3.rhtml" => ["file3.html", "file3.plogic", layout] do |t|
|
|
1567
2052
|
end
|
1568
2053
|
</pre>
|
1569
2054
|
<div class="program_caption">
|
1570
|
-
example of Rookbook for <a href="http://www.rubyforge.org/projects/rook">Rook</a></div>
|
2055
|
+
example of Rookbook.yaml for <a href="http://www.rubyforge.org/projects/rook">Rook</a></div>
|
1571
2056
|
<pre class="program">properties:
|
1572
2057
|
- layout : layout.html
|
1573
2058
|
|
1574
|
-
|
1575
|
-
- all : [ file1.rhtml,
|
2059
|
+
parameters:
|
2060
|
+
- all : [ file1.rhtml, file2.rhtml, file3.rhtml ]
|
1576
2061
|
- rook_product: $(all)
|
1577
2062
|
|
1578
2063
|
recipes:
|
1579
2064
|
|
1580
2065
|
- product: *.rhtml
|
1581
2066
|
ingreds: [ $(1).html, $(1).plogic ]
|
1582
|
-
method
|
2067
|
+
method*: |
|
1583
2068
|
pdata, plogic = @ingreds
|
1584
2069
|
sys "kwartz -p #{plogic} #{pdata} > #{@product}"
|
1585
2070
|
|
1586
2071
|
- product: file3.rhtml
|
1587
2072
|
ingres: [ file3.html, file3.plogic, $(layout) ]
|
1588
|
-
method
|
2073
|
+
method*: |
|
1589
2074
|
pdata, plogic, layout = @ingreds
|
1590
2075
|
sys "kwartz- p #{plogic} -L $(layout) #{pdata} > #{@product}"
|
1591
2076
|
</pre>
|
1592
2077
|
<br>
|
1593
2078
|
|
1594
2079
|
|
1595
|
-
<a name="kwartz-lib"></a>
|
2080
|
+
<a name="topics-kwartz-lib"></a>
|
1596
2081
|
<h3 class="section2">Use Kwartz as Library</h3>
|
1597
2082
|
<p>If you want to use Kwartz library in your Ruby script, use Kwartz::Main class.
|
1598
2083
|
</p>
|
1599
2084
|
<div class="program_caption">
|
1600
2085
|
usage of Kwartz::Main class</div>
|
1601
|
-
<pre class="program"><
|
1602
|
-
<
|
2086
|
+
<pre class="program"><strong>require 'kwartz'</strong>
|
2087
|
+
<strong>require 'kwartz/main'</strong>
|
1603
2088
|
|
1604
2089
|
argv = %w[-p hello.plogic -L layout.html hello.html]
|
1605
|
-
<
|
1606
|
-
<
|
2090
|
+
<strong>main = Kwartz::Main.new(argv)</strong>
|
2091
|
+
<strong>output = main.execute()</strong>
|
1607
2092
|
File.open('hello.rhtml', 'w') { |f| f.write(output) }
|
1608
2093
|
</pre>
|
1609
2094
|
<br>
|
1610
2095
|
|
1611
2096
|
|
1612
|
-
<a name="
|
1613
|
-
<h3 class="section2"
|
1614
|
-
<p
|
1615
|
-
|
1616
|
-
|
2097
|
+
<a name="topics-erubis"></a>
|
2098
|
+
<h3 class="section2">Use Kwartz with Non-Supported Language</h3>
|
2099
|
+
<p>Using <a href="http://www.kuwata-lab.com/erubis">Erubis</a>, it is able to use Kwartz with Java, JavaScript, Scheme, and so on.
|
2100
|
+
Erubis is an implementation of eRuby which supports not only Ruby but also other languages.
|
2101
|
+
</p>
|
2102
|
+
<p>The followings are examples of using JavaScript with Kwartz and Erubis.
|
1617
2103
|
</p>
|
2104
|
+
<a name="js-example.html"></a>
|
1618
2105
|
<div class="program_caption">
|
1619
|
-
presentation data</div>
|
1620
|
-
<pre class="program"><
|
2106
|
+
presentation data (js-example.html)</div>
|
2107
|
+
<pre class="program"><table>
|
2108
|
+
<tr class="odd" <strong>id="mark:list"</strong>>
|
2109
|
+
<td><strong>@!{item}@</strong></td>
|
2110
|
+
</tr>
|
2111
|
+
<tr class="even" <strong>id="dummy:d1"</strong>>
|
2112
|
+
<td>foo</td>
|
2113
|
+
</tr>
|
2114
|
+
</table>
|
1621
2115
|
</pre>
|
2116
|
+
<a name="js-example.plogic"></a>
|
1622
2117
|
<div class="program_caption">
|
1623
|
-
presentation logic</div>
|
1624
|
-
<pre class="program">#
|
1625
|
-
|
2118
|
+
presentation logic (js-example.plogic)</div>
|
2119
|
+
<pre class="program">#list {
|
2120
|
+
attrs: 'class' klass;
|
2121
|
+
logic: {
|
2122
|
+
for (var i=0, len=list.length; i < len; i++) {
|
2123
|
+
klass = i % 1 == 0 ? 'even' : 'odd';
|
2124
|
+
item = list[i];
|
2125
|
+
_elem;
|
2126
|
+
}
|
2127
|
+
}
|
1626
2128
|
}
|
1627
2129
|
</pre>
|
1628
|
-
<
|
1629
|
-
|
1630
|
-
</p
|
1631
|
-
<pre class="program">module ApplicationHelper
|
1632
|
-
|
1633
|
-
def start_link_to(options = {}, html_options = nil, *parameters_for_method_reference)
|
1634
|
-
s = link_to('', options, html_options, *parameters_for_method_reference)
|
1635
|
-
s.sub!(/<\/a>\z/, '')
|
1636
|
-
end
|
1637
|
-
alias anchor start_link_to
|
1638
|
-
|
1639
|
-
def start_link_to_remote(options = {}, html_options = {})
|
1640
|
-
s = link_to_remote(options, html_options)
|
1641
|
-
s.sub!(/<\/a>\z/, '')
|
1642
|
-
end
|
1643
|
-
alias anchor_remote start_link_to_remote
|
1644
|
-
|
1645
|
-
end
|
2130
|
+
<div class="terminal_caption">
|
2131
|
+
compile</div>
|
2132
|
+
<pre class="terminal">$ kwartz <strong>-l erubis</strong> -p js-example.plogic js-example.html > js-example.jshtml
|
1646
2133
|
</pre>
|
1647
|
-
<
|
1648
|
-
</p>
|
2134
|
+
<a name="js-example.jshtml"></a>
|
1649
2135
|
<div class="program_caption">
|
1650
|
-
|
1651
|
-
<pre class="program"><
|
2136
|
+
output script (js-example.jshtml)</div>
|
2137
|
+
<pre class="program"><table>
|
2138
|
+
<strong><% for (var i=0, len=list.length; i < len; i++) { %></strong>
|
2139
|
+
<strong><% klass = i % 1 == 0 ? 'even' : 'odd'; %></strong>
|
2140
|
+
<strong><% item = list[i]; %></strong>
|
2141
|
+
<tr class="<strong><%= klass %></strong>">
|
2142
|
+
<td><strong><%= item %></strong></td>
|
2143
|
+
</tr>
|
2144
|
+
<strong><% } %></strong>
|
2145
|
+
</table>
|
1652
2146
|
</pre>
|
1653
|
-
<
|
1654
|
-
|
1655
|
-
|
1656
|
-
|
1657
|
-
|
2147
|
+
<a name="js-example.expected"></a>
|
2148
|
+
<div class="terminal_caption">
|
2149
|
+
convert into JavaScript code with erubis</div>
|
2150
|
+
<pre class="terminal">$ erubis -l javascript -x js-example.jshtml
|
2151
|
+
var _buf = []; _buf.push("<table>\n");
|
2152
|
+
<strong>for (var i=0, len=list.length; i < len; i++) {</strong>
|
2153
|
+
<strong>klass = i % 1 == 0 ? 'even' : 'odd';</strong>
|
2154
|
+
<strong>item = list[i];</strong>
|
2155
|
+
_buf.push(" <tr class=\""); _buf.push(<strong>klass</strong>); _buf.push("\">\n\
|
2156
|
+
<td>"); _buf.push(<strong>item</strong>); _buf.push("</td>\n\
|
2157
|
+
</tr>\n");
|
2158
|
+
<strong>}</strong>
|
2159
|
+
_buf.push("</table>\n");
|
2160
|
+
document.write(_buf.join(""));
|
1658
2161
|
</pre>
|
1659
2162
|
<br>
|
1660
2163
|
|