Kwartz-ruby 3.0 Reference Guide
2 Directives
Directives are commands to embed presentation logics into presentation data.
For example, title="for item in @list" directive represents iteration of the element.
Directives are provided for 'choosability'. This is very important concept for Kwartz (and other products by kuwata-lab). In Kwartz, you can separate presentation logics from presentation data, or 'mix' them. It is the user or customer of Kwartz and not developer who determine which solution to adopt. All Kwartz can do is to provide the both solution to users.
Notice that the notation of directives are different for each target language.
For example, iteration directive is title="for item in list" in Ruby,
title="foreach($list as $item)" in PHP.
See the directive notation table for PHP, Java, and Perl user.
2-1 elem, Elem, ELEM
'elem', 'Elem', and 'ELEM' directive replaces element by expression.
'Elem' directive escapes expression automatically, while 'ELEM' never escape it. 'elem' directive escapes expression when command-line option '-e' is specified or PROPERTY_ESCAPE is true in configuration file.
2-1-1 Ruby
<b kw:d="elem: expr">foo</b> <b kw:d="Elem: expr">foo</b> <b kw:d="ELEM: expr">foo</b>
$ kwartz -l eruby ex-elem.pdata <%= expr %> <%=h expr %> <%= expr %>
2-1-2 PHP
<b kw:d="elem($expr)">foo</b> <b kw:d="Elem($expr)">foo</b> <b kw:d="ELEM($expr)">foo</b>
$ kwartz -l php ex-elem.pdata <?php echo $expr; ?> <?php echo htmlspecialchars($expr); ?> <?php echo $expr; ?>
2-1-3 JSP
<b kw:d="elem(expr)">foo</b> <b kw:d="Elem(expr)">foo</b> <b kw:d="ELEM(expr)">foo</b>
$ kwartz -l jstl ex-elem.pdata
${expr}
${expr}
<c:out value="${expr}" escapeXml="false"/>
2-1-4 Perl
<b kw:d="elem($expr)">foo</b> <b kw:d="Elem($expr)">foo</b> <b kw:d="ELEM($expr)">foo</b>
$ kwartz -l eperl ex-elem.pdata <?= $expr !> <?= encode_entities($expr) !> <?= $expr !>
2-2 stag, Stag, STAG
'stag', 'Stag', and 'STAG' directive replaces start-tag by expression.
'Stag' directive escapes expression automatically, while 'STAG' never escape it. 'stag' directive escapes expression when command-line option '-e' is specified or PROPERTY_ESCAPE is true in configuration file.
2-2-1 Ruby
<b kw:d="stag: expr">foo</b> <b kw:d="Stag: expr">foo</b> <b kw:d="STAG: expr">foo</b>
$ kwartz -l eruby ex-stag.pdata <%= expr %>foo</b> <%=h expr %>foo</b> <%= expr %>foo</b>
2-2-2 PHP
<b kw:d="stag($expr)">foo</b> <b kw:d="Stag($expr)">foo</b> <b kw:d="STAG($expr)">foo</b>
$ kwartz -l php ex-stag.pdata <?php echo $expr; ?>foo</b> <?php echo htmlspecialchars($expr); ?>foo</b> <?php echo $expr; ?>foo</b>
2-2-3 JSP
<b kw:d="stag(expr)">foo</b> <b kw:d="Stag(expr)">foo</b> <b kw:d="STAG(expr)">foo</b>
$ kwartz -l jstl ex-stag.pdata
${expr}foo</b>
${expr}foo</b>
<c:out value="${expr}" escapeXml="false"/>foo</b>
2-2-4 Perl
<b kw:d="stag($expr)">foo</b> <b kw:d="Stag($expr)">foo</b> <b kw:d="STAG($expr)">foo</b>
$ kwartz -l eperl ex-stag.pdata <?= $expr !>foo</b> <?= encode_entities($expr) !>foo</b> <?= $expr !>foo</b>
2-3 etag, Etag, ETAG
'etag', 'Etag', and 'ETAG' directive replaces start-tag by expression.
'Etag' directive escapes expression automatically, while 'ETAG' never escape it. 'etag' directive escapes expression when command-line option '-e' is specified or PROPERTY_ESCAPE is true in configuration file.
2-3-1 Ruby
<b kw:d="etag: expr">foo</b> <b kw:d="Etag: expr">foo</b> <b kw:d="ETAG: expr">foo</b>
$ kwartz -l eruby ex-etag.pdata <b>foo<%= expr %> <b>foo<%=h expr %> <b>foo<%= expr %>
2-3-2 PHP
<b kw:d="etag($expr)">foo</b> <b kw:d="Etag($expr)">foo</b> <b kw:d="ETAG($expr)">foo</b>
$ kwartz -l php ex-etag.pdata <b>foo<?php echo $expr; ?> <b>foo<?php echo htmlspecialchars($expr); ?> <b>foo<?php echo $expr; ?>
2-3-3 JSP
<b kw:d="etag(expr)">foo</b> <b kw:d="Etag(expr)">foo</b> <b kw:d="ETAG(expr)">foo</b>
$ kwartz -l jstl ex-etag.pdata
<b>foo${expr}
<b>foo${expr}
<b>foo<c:out value="${expr}" escapeXml="false"/>
2-3-4 Perl
<b kw:d="etag($expr)">foo</b> <b kw:d="Etag($expr)">foo</b> <b kw:d="ETAG($expr)">foo</b>
$ kwartz -l eperl ex-etag.pdata <b>foo<?= $expr !> <b>foo<?= encode_entities($expr) !> <b>foo<?= $expr !>
2-4 cont, Cont, CONT
'cont', 'Cont', and 'CONT' directives replace content by expression.
'Cont' directive escapes expression automatically, while 'CONT' never escape it. 'cont' directive escapes expression when command-line option '-e' is specified or PROPERTY_ESCAPE is true in configuration file.
2-4-1 Ruby
<b kw:d="cont: expr">foo</b> <b kw:d="Cont: expr">foo</b> <b kw:d="CONT: expr">foo</b>
$ kwartz -l eruby ex-cont.pdata <b><%= expr %></b> <b><%=h expr %></b> <b><%= expr %></b>
2-4-2 PHP
<b kw:d="cont($expr)">foo</b> <b kw:d="Cont($expr)">foo</b> <b kw:d="CONT($expr)">foo</b>
$ kwartz -l php ex-cont.pdata <b><?php echo $expr; ?></b> <b><?php echo htmlspecialchars($expr); ?></b> <b><?php echo $expr; ?></b>
2-4-3 JSP
<b kw:d="cont(expr)">foo</b> <b kw:d="Cont(expr)">foo</b> <b kw:d="CONT(expr)">foo</b>
$ kwartz -l jstl ex-cont.pdata
<b>${expr}</b>
<b>${expr}</b>
<b><c:out value="${expr}" escapeXml="false"/></b>
2-4-4 Perl
<b kw:d="cont($expr)">foo</b> <b kw:d="Cont($expr)">foo</b> <b kw:d="CONT($expr)">foo</b>
$ kwartz -l eperl ex-cont.pdata <b><?= $expr !></b> <b><?= encode_entities($expr) !></b> <b><?= $expr !></b>
2-5 value, Value, VALUE
'value', 'Value', and 'VALUE' directives are equivalent to 'cont', 'Cont', and 'CONT' directives respectively.
2-5-1 Ruby
<b kw:d="value: expr">foo</b> <b kw:d="Value: expr">foo</b> <b kw:d="VALUE: expr">foo</b>
$ kwartz -l eruby ex-value.pdata <b><%= expr %></b> <b><%=h expr %></b> <b><%= expr %></b>
2-5-2 PHP
<b kw:d="value($expr)">foo</b> <b kw:d="Value($expr)">foo</b> <b kw:d="VALUE($expr)">foo</b>
$ kwartz -l php ex-value.pdata <b><?php echo $expr; ?></b> <b><?php echo htmlspecialchars($expr); ?></b> <b><?php echo $expr; ?></b>
2-5-3 JSP
<b kw:d="value(expr)">foo</b> <b kw:d="Value(expr)">foo</b> <b kw:d="VALUE(expr)">foo</b>
$ kwartz -l jstl ex-value.pdata
<b>${expr}</b>
<b>${expr}</b>
<b><c:out value="${expr}" escapeXml="false"/></b>
2-5-4 Perl
<b kw:d="value($expr)">foo</b> <b kw:d="Value($expr)">foo</b> <b kw:d="VALUE($expr)">foo</b>
$ kwartz -l eperl ex-value.pdata <b><?= $expr !></b> <b><?= encode_entities($expr) !></b> <b><?= $expr !></b>
2-6 foreach
'foreach' directive interates element, while 'loop' directive iterates content.
2-6-1 Ruby
<tr kw:d="for item in list"> <td kw:d="cont item">foo</td> </tr> <tr kw:d="for key,value in hash"> <td kw:d="cont key">key</td> <td kw:d="cont value">value</td> </tr>
$ kwartz -l eruby ex-foreach.pdata <% for item in list do %> <tr> <td><%= item %></td> </tr> <% end %> <% hash.each do |key, value| %> <tr> <td><%= key %></td> <td><%= value %></td> </tr> <% end %>
2-6-2 PHP
<tr kw:d="foreach($list as $item)"> <td kw:d="cont($item)">foo</td> </tr> <tr kw:d="foreach($hash as $key=>$value)"> <td kw:d="cont($key)">key</td> <td kw:d="cont($value)">value</td> </tr>
$ kwartz -l php ex-foreach.pdata
<?php foreach ($list as $item) { ?>
<tr>
<td><?php echo $item; ?></td>
</tr>
<?php } ?>
<?php foreach ($hash as $key=>$value) { ?>
<tr>
<td><?php echo $key; ?></td>
<td><?php echo $value; ?></td>
</tr>
<?php } ?>
2-6-3 JSP
<tr kw:d="for(item: list)">
<td kw:d="cont(item)">foo</td>
</tr>
<tr kw:d="forEach('var'=>'v', 'items'=>'${params.list}', 'varStatus'=>'status')">
<td kw:d="cont(status.index)">1</td>
<td kw:d="cont(v)"></td>
</tr>
<tr kw:d="forEach('var'=>'n', 'begin'=>1, 'end'=>10, 'step'=>2)">
<td kw:d="cont(n)">key</td>
</tr>
$ kwartz -l jstl ex-foreach.pdata
<c:forEach var="item" items="${list}">
<tr>
<td>${item}</td>
</tr>
</c:forEach>
<c:forEach var="v" items="${params.list}" varStatus="status">
<tr>
<td>${status.index}</td>
<td>${v}</td>
</tr>
</c:forEach>
<c:forEach var="n" begin="1" end="10" step="2">
<tr>
<td>${n}</td>
</tr>
</c:forEach>
2-6-4 Perl
<tr kw:d="foreach($item in @list)"> <td kw:d="cont($item)">foo</td> </tr> <tr kw:d="foreach($key,$value in %hash)"> <td kw:d="cont($key)">key</td> <td kw:d="cont($value)">value</td> </tr>
$ kwartz -l eperl ex-foreach.pdata
<? foreach my $item (@list) { !>
<tr>
<td><?= $item !></td>
</tr>
<? } !>
<? foreach my $key (keys %hash) { !>
<? my $value = $hash{$key}; !>
<tr>
<td><?= $key !></td>
<td><?= $value !></td>
</tr>
<? } !>
2-7 list
'list' directive interates content, while 'foreach' directive iterates element.
2-7-1 Ruby
<tr kw:d="list item in list"> <td kw:d="cont item">foo</td> </tr> <tr kw:d="list key,value in hash"> <td kw:d="cont key">key</td> <td kw:d="cont value">value</td> </tr>
$ kwartz -l eruby ex-list.pdata <tr> <% for item in list do %> <td><%= item %></td> <% end %> </tr> <tr> <% hash.each do |key, value| %> <td><%= key %></td> <td><%= value %></td> <% end %> </tr>
2-7-2 PHP
<tr kw:d="list($list as $item)"> <td kw:d="cont($item)">foo</td> </tr> <tr kw:d="list($hash as $key=>$value)"> <td kw:d="cont($key)">key</td> <td kw:d="cont($value)">value</td> </tr>
$ kwartz -l php ex-list.pdata
<tr>
<?php foreach ($list as $item) { ?>
<td><?php echo $item; ?></td>
<?php } ?>
</tr>
<tr>
<?php foreach ($hash as $key=>$value) { ?>
<td><?php echo $key; ?></td>
<td><?php echo $value; ?></td>
<?php } ?>
</tr>
2-7-3 JSP
<tr kw:d="list(item: list)"> <td kw:d="cont(item)">foo</td> </tr>
$ kwartz -l jstl ex-list.pdata
<tr>
<c:forEach var="item" items="${list}">
<td>${item}</td>
</c:forEach>
</tr>
2-7-4 Perl
<tr kw:d="list($item in @list)"> <td kw:d="cont($item)">foo</td> </tr> <tr kw:d="list($key,$value in %hash)"> <td kw:d="cont($key)">key</td> <td kw:d="cont($value)">value</td> </tr>
$ kwartz -l eperl ex-list.pdata
<tr>
<? foreach my $item (@list) { !>
<td><?= $item !></td>
<? } !>
</tr>
<tr>
<? foreach my $key (keys %hash) { !>
<? my $value = $hash{$key}; !>
<td><?= $key !></td>
<td><?= $value !></td>
<? } !>
</tr>
2-8 Foreach, List
'Foreach' and 'List' directives iterate element or content with loop counter (starting with 1).
2-8-1 Ruby
<tr kw:d="For item in list"> <td kw:d="cont item">foo</td> </tr> <tr kw:d="List item in list"> <td kw:d="cont item">foo</td> </tr>
$ kwartz -l eruby ex-foreach_ctr.pdata <% item_ctr = 0 %> <% for item in list do %> <% item_ctr += 1 %> <tr> <td><%= item %></td> </tr> <% end %> <tr> <% item_ctr = 0 %> <% for item in list do %> <% item_ctr += 1 %> <td><%= item %></td> <% end %> </tr>
2-8-2 PHP
<tr kw:d="Foreach($list as $item)"> <td kw:d="cont($item)">foo</td> </tr> <tr kw:d="List($list as $item)"> <td kw:d="cont($item)">foo</td> </tr>
$ kwartz -l php ex-foreach_ctr.pdata
<?php $item_ctr = 0; ?>
<?php foreach ($list as $item) { ?>
<?php $item_ctr++; ?>
<tr>
<td><?php echo $item; ?></td>
</tr>
<?php } ?>
<tr>
<?php $item_ctr = 0; ?>
<?php foreach ($list as $item) { ?>
<?php $item_ctr++; ?>
<td><?php echo $item; ?></td>
<?php } ?>
</tr>
2-8-3 JSP
<tr kw:d="For(item: list)"> <td kw:d="cont(item)">foo</td> </tr> <tr kw:d="List(item: list)"> <td kw:d="cont(item)">foo</td> </tr>
$ kwartz -l jstl ex-foreach_ctr.pdata
<c:forEach var="item" items="${list}" varStatus="item_status">
<c:set var="item_ctr" value="${item_status.count}"/>
<tr>
<td>${item}</td>
</tr>
</c:forEach>
<tr>
<c:forEach var="item" items="${list}" varStatus="item_status">
<c:set var="item_ctr" value="${item_status.count}"/>
<td>${item}</td>
</c:forEach>
</tr>
2-8-4 Perl
<tr kw:d="Foreach($item in @list)"> <td kw:d="cont($item)">foo</td> </tr> <tr kw:d="List($item in @list)"> <td kw:d="cont($item)">foo</td> </tr>
$ kwartz -l eperl ex-foreach_ctr.pdata
<? my $item_ctr = 0; !>
<? foreach my $item (@list) { !>
<? $item_ctr++; !>
<tr>
<td><?= $item !></td>
</tr>
<? } !>
<tr>
<? my $item_ctr = 0; !>
<? foreach my $item (@list) { !>
<? $item_ctr++; !>
<td><?= $item !></td>
<? } !>
</tr>
2-9 FOREACH, LIST
'FOREACH' and 'LIST' directives iterate element or content with loop counter and toggle variable. Toggle values are "'odd'" and "'even'" in default. You can change them by command-line option '--odd' and '--even' or by properties(PROPERTY_ODD, PROPERTY_EVEN) in configuration file.
2-9-1 Ruby
<tr kw:d="FOR item in list"> <td kw:d="cont item">foo</td> </tr> <tr kw:d="LIST item in list"> <td kw:d="cont item">foo</td> </tr>
$ kwartz -l eruby ex-foreach_tgl.pdata <% item_ctr = 0 %> <% for item in list do %> <% item_ctr += 1 %> <% item_tgl = item_ctr%2==0 ? 'even' : 'odd' %> <tr> <td><%= item %></td> </tr> <% end %> <tr> <% item_ctr = 0 %> <% for item in list do %> <% item_ctr += 1 %> <% item_tgl = item_ctr%2==0 ? 'even' : 'odd' %> <td><%= item %></td> <% end %> </tr>
2-9-2 PHP
<tr kw:d="FOREACH($list as $item)"> <td kw:d="cont($item)">foo</td> </tr> <tr kw:d="LIST($list as $item)"> <td kw:d="cont($item)">foo</td> </tr>
$ kwartz -l php ex-foreach_tgl.pdata
<?php $item_ctr = 0; ?>
<?php foreach ($list as $item) { ?>
<?php $item_ctr++; ?>
<?php $item_tgl = $item_ctr%2==0 ? 'even' : 'odd'; ?>
<tr>
<td><?php echo $item; ?></td>
</tr>
<?php } ?>
<tr>
<?php $item_ctr = 0; ?>
<?php foreach ($list as $item) { ?>
<?php $item_ctr++; ?>
<?php $item_tgl = $item_ctr%2==0 ? 'even' : 'odd'; ?>
<td><?php echo $item; ?></td>
<?php } ?>
</tr>
2-9-3 JSP
<tr kw:d="FOR(item: list)"> <td kw:d="cont(item)">foo</td> </tr> <tr kw:d="LIST(item: list)"> <td kw:d="cont(item)">foo</td> </tr>
$ kwartz -l jstl ex-foreach_tgl.pdata
<c:forEach var="item" items="${list}" varStatus="item_status">
<c:set var="item_ctr" value="${item_status.count}"/>
<c:set var="item_tgl" value="${item_status.count%2==0 ? 'even' : 'odd'}"/>
<tr>
<td>${item}</td>
</tr>
</c:forEach>
<tr>
<c:forEach var="item" items="${list}" varStatus="item_status">
<c:set var="item_ctr" value="${item_status.count}"/>
<c:set var="item_tgl" value="${item_status.count%2==0 ? 'even' : 'odd'}"/>
<td>${item}</td>
</c:forEach>
</tr>
2-9-4 Perl
<tr kw:d="FOREACH($item in @list)"> <td kw:d="cont($item)">foo</td> </tr> <tr kw:d="LIST($item in @list)"> <td kw:d="cont($item)">foo</td> </tr>
$ kwartz -l eperl ex-foreach_tgl.pdata
<? my $item_ctr = 0; !>
<? foreach my $item (@list) { !>
<? $item_ctr++; !>
<? my $item_tgl = $item_ctr%2==0 ? 'even' : 'odd'; !>
<tr>
<td><?= $item !></td>
</tr>
<? } !>
<tr>
<? my $item_ctr = 0; !>
<? foreach my $item (@list) { !>
<? $item_ctr++; !>
<? my $item_tgl = $item_ctr%2==0 ? 'even' : 'odd'; !>
<td><?= $item !></td>
<? } !>
</tr>
2-10 while, loop
'while' and 'loop' directive iterates element or content until conditional expression is false.
JSTL doesn't support these directives because JSTL doesn't have 'while' custom tag.
2-10-1 Ruby
<tr kw:d="while (item = dbh.fetch) != nil"> <td kw:d="cont item.name">foo</td> </tr> <tr kw:d="loop (item = dbh.fetch) != nil"> <td kw:d="cont item.name">foo</td> </tr>
$ kwartz -l eruby ex-while.pdata <% while (item = dbh.fetch) != nil do %> <tr> <td><%= item.name %></td> </tr> <% end %> <tr> <% while (item = dbh.fetch) != nil do %> <td><%= item.name %></td> <% end %> </tr>
2-10-2 PHP
<tr kw:d="while(($item = $dbh->fetch()) != null)"> <td kw:d="cont($item->name)">foo</td> </tr> <tr kw:d="loop(($item = $dbh->fetch()) != null)"> <td kw:d="cont($item->name)">foo</td> </tr>
$ kwartz -l php ex-while.pdata
<?php while (($item = $dbh->fetch()) != null) { ?>
<tr>
<td><?php echo $item->name; ?></td>
</tr>
<?php } ?>
<tr>
<?php while (($item = $dbh->fetch()) != null) { ?>
<td><?php echo $item->name; ?></td>
<?php } ?>
</tr>
2-10-3 JSP
*** not supported ***
$ kwartz -l jstl ex-while.pdata *** not supported ***
2-10-4 Perl
<tr kw:d="while(($item = $dbh->fetch()) != null)"> <td kw:d="cont($item->name)">foo</td> </tr> <tr kw:d="loop(($item = $dbh->fetch()) != null)"> <td kw:d="cont($item->name)">foo</td> </tr>
$ kwartz -l eperl ex-while.pdata
<? while (($item = $dbh->fetch()) != null) { !>
<tr>
<td><?= $item->name !></td>
</tr>
<? } !>
<tr>
<? while (($item = $dbh->fetch()) != null) { !>
<td><?= $item->name !></td>
<? } !>
</tr>
2-11 if-then-else
'if', 'elsif'(or 'elseif'), and 'else' directives represent conditional branch.
Don't separate with empty lines between end-tag of 'if'/'elseif' directive and start-tag of 'elseif'/'else' directive.
2-11-1 Ruby
<div kw:d="if status=='error'"> <p class="error" kw:d="cont mesg">error</p> </div> <div kw:d="elsif status=='warning'"> <p class="warning" kw:d="cont mesg">waring</p> </div> <div kw:d="else"> <p kw:d="cont mesg">mesg</p> </div>
$ kwartz -l eruby ex-if.pdata <% if status=='error' then %> <div> <p class="error"><%= mesg %></p> </div> <% elsif status=='warning' then %> <div> <p class="warning"><%= mesg %></p> </div> <% else %> <div> <p><%= mesg %></p> </div> <% end %>
2-11-2 PHP
<div kw:d="if($status=='error')"> <p class="error" kw:d="cont($mesg)">error</p> </div> <div kw:d="elseif($status=='warning')"> <p class="warning" kw:d="cont($mesg)">waring</p> </div> <div kw:d="else"> <p kw:d="cont($mesg)">mesg</p> </div>
$ kwartz -l php ex-if.pdata
<?php if ($status=='error') { ?>
<div>
<p class="error"><?php echo $mesg; ?></p>
</div>
<?php } elseif ($status=='warning') { ?>
<div>
<p class="warning"><?php echo $mesg; ?></p>
</div>
<?php } else { ?>
<div>
<p><?php echo $mesg; ?></p>
</div>
<?php } ?>
2-11-3 JSP
<div kw:d="if(status=='error')"> <p class="error" kw:d="cont(mesg)">error</p> </div> <div kw:d="elseif(status=='warning')"> <p class="warning" kw:d="cont(mesg)">waring</p> </div> <div kw:d="else"> <p kw:d="cont(mesg)">mesg</p> </div>
$ kwartz -l jstl ex-if.pdata
<c:choose><c:when test="${status=='error'}">
<div>
<p class="error">${mesg}</p>
</div>
</c:when><c:when test="${status=='warning'}">
<div>
<p class="warning">${mesg}</p>
</div>
</c:when><c:otherwise>
<div>
<p>${mesg}</p>
</div>
</c:otherwise></c:choose>
2-11-4 Perl
<div kw:d="if($status=='error')"> <p class="error" kw:d="cont($mesg)">error</p> </div> <div kw:d="elsif($status=='warning')"> <p class="warning" kw:d="cont($mesg)">waring</p> </div> <div kw:d="else"> <p kw:d="cont($mesg)">mesg</p> </div>
$ kwartz -l eperl ex-if.pdata
<? if ($status=='error') { !>
<div>
<p class="error"><?= $mesg !></p>
</div>
<? } elsif ($status=='warning') { !>
<div>
<p class="warning"><?= $mesg !></p>
</div>
<? } else { !>
<div>
<p><?= $mesg !></p>
</div>
<? } !>
2-12 set
'set' directive executes any expression.
2-12-1 Ruby
<tr kw:d="set color=i%2==0 ? 'red' : 'blue'"> <td kw:d="cont: color">red</td> </tr>
$ kwartz -l eruby ex-set.pdata <% color=i%2==0 ? 'red' : 'blue' %> <tr> <td><%= color %></td> </tr>
2-12-2 PHP
<tr kw:d="set($color=$i%2==0 ? 'red' : 'blue')"> <td kw:d="cont($color)">red</td> </tr>
$ kwartz -l php ex-set.pdata <?php $color=$i%2==0 ? 'red' : 'blue'; ?> <tr> <td><?php echo $color; ?></td> </tr>
2-12-3 JSP
<tr kw:d="set(color=i%2==0 ? 'red' : 'blue')"> <td kw:d="cont(color)">red</td> </tr>
$ kwartz -l jstl ex-set.pdata
<c:set var="color=i%2=" value="${0 ? 'red' : 'blue'}"/>
<tr>
<td>${color}</td>
</tr>
2-12-4 Perl
<tr kw:d="set($color=i%2==0 ? 'red' : 'blue')"> <td kw:d="cont($color)">red</td> </tr>
$ kwartz -l eperl ex-set.pdata <? $color=i%2==0 ? 'red' : 'blue'; !> <tr> <td><?= $color !></td> </tr>
2-13 mark
'mark' directive marks the element by name. Name is used as selector of ruleset in presentation logic file. Id attribute is equivalent to 'mark' directive if other direcitve is not specified.
'mark' directive is language-independent when used with id attribute.
2-13-1 Ruby
<ul id="mark:list"> <li kw:d="id: item">foo</li> </ul>
$ kwartz -l eruby ex-mark.pdata <ul> <li>foo</li> </ul>
2-13-2 PHP
<ul id="mark:list"> <li kw:d="id(item)">foo</li> </ul>
$ kwartz -l php ex-mark.pdata <ul> <li>foo</li> </ul>
2-13-3 JSP
<ul id="mark:list"> <li kw:d="id(item)">foo</li> </ul>
$ kwartz -l jstl ex-mark.pdata <ul> <li>foo</li> </ul>
2-13-4 Perl
<ul id="mark:list"> <li kw:d="id(item)">foo</li> </ul>
$ kwartz -l eperl ex-mark.pdata <ul> <li>foo</li> </ul>
2-14 attr, Attr, ATTR
'attr', 'Attr', and 'ATTR' directives replace attribute value with expression. 'Attr' directive escapes expression automatically, while 'ATTR' never escape it. 'attr' directive escapes expression when command-line option '-e' is specified or PROPERTY_ESCAPE is true in configuration file.
More than one directives are available in an element with separating by ';', and available with other directive.
2-14-1 Ruby
<tr class="odd"
kw:d="FOR v in list; attr: 'class' v_tgl; attr: 'style' style">
<td kw:d="cont v.name">foo</td>
</tr>
$ kwartz -l eruby ex-attr.pdata <% v_ctr = 0 %> <% for v in list do %> <% v_ctr += 1 %> <% v_tgl = v_ctr%2==0 ? 'even' : 'odd' %> <tr class="<%= v_tgl %>" style="<%= style %>"> <td><%= v.name %></td> </tr> <% end %>
2-14-2 PHP
<tr class="odd"
kw:d="FOREACH($list as $v); attr('class',$v_tgl); attr('style',$style)">
<td kw:d="cont($v->name)">foo</td>
</tr>
$ kwartz -l php ex-attr.pdata
<?php $v_ctr = 0; ?>
<?php foreach ($list as $v) { ?>
<?php $v_ctr++; ?>
<?php $v_tgl = $v_ctr%2==0 ? 'even' : 'odd'; ?>
<tr class="<?php echo $v_tgl; ?>" style="<?php echo $style; ?>">
<td><?php echo $v->name; ?></td>
</tr>
<?php } ?>
2-14-3 JSP
<tr class="odd"
kw:d="FOR(v: list); attr('class',v_tgl); attr('style',style)">
<td kw:d="cont(v.name)">foo</td>
</tr>
$ kwartz -l jstl ex-attr.pdata
<c:forEach var="v" items="${list}" varStatus="v_status">
<c:set var="v_ctr" value="${v_status.count}"/>
<c:set var="v_tgl" value="${v_status.count%2==0 ? 'even' : 'odd'}"/>
<tr class="${v_tgl}" style="${style}">
<td>${v.name}</td>
</tr>
</c:forEach>
2-14-4 Perl
<tr class="odd"
kw:d="FOREACH($v in @list); attr('class',$v_tgl); attr('style',$style)">
<td kw:d="cont($v->name)">foo</td>
</tr>
$ kwartz -l eperl ex-attr.pdata
<? my $v_ctr = 0; !>
<? foreach my $v (@list) { !>
<? $v_ctr++; !>
<? my $v_tgl = $v_ctr%2==0 ? 'even' : 'odd'; !>
<tr class="<?= $v_tgl !>" style="<?= $style !>">
<td><?= $v->name !></td>
</tr>
<? } !>
2-15 append, Append, APPEND
'append', 'Append', and 'APPEND' directives append expression at the end of start-tag. 'Append' directive escapes expression automatically, while 'APPEND' never escape it. 'append' directive escapes expression when command-line option '-e' is specified or PROPERTY_ESCAPE is true in configuration file.
More than one directives are available in an element with separating by ';', and available with other directive.
2-15-1 Ruby
<input type="checkbox" kw:d="append: flag1 ? ' checked=\'checked\'' : ''">
$ kwartz -l eruby ex-append.pdata <input type="checkbox"<%= flag1 ? ' checked=\'checked\'' : '' %>>
2-15-2 PHP
<input type="checkbox" kw:d="append($flag1 ? ' checked=\'checked\'' : '')">
$ kwartz -l php ex-append.pdata <input type="checkbox"<?php echo $flag1 ? ' checked=\'checked\'' : ''; ?>>
2-15-3 JSP
<input type="checkbox" kw:d="append(flag1 ? ' checked=\'checked\'' : '')">
$ kwartz -l jstl ex-append.pdata
<input type="checkbox"${flag1 ? ' checked=\'checked\'' : ''}>
2-15-4 Perl
<input type="checkbox" kw:d="append($flag1 ? ' checked=\'checked\'' : '')">
$ kwartz -l eperl ex-append.pdata <input type="checkbox"<?= $flag1 ? ' checked=\'checked\'' : '' !>>
2-16 dummy
'dummy' directive removes the element. It is very useful when preview the HTML design in browser.
'dummy' directive is language-independent when used with id attribute.
2-16-1 Ruby
<ul> <li>foo</li> <li id="dummy:d1">bar</li> <li kw:d="dummy:">baz</li> </ul>
$ kwartz -l eruby ex-dummy.pdata <ul> <li>foo</li> </ul>
2-16-2 PHP
<ul> <li>foo</li> <li id="dummy:d1">bar</li> <li kw:d="dummy()">baz</li> </ul>
$ kwartz -l php ex-dummy.pdata <ul> <li>foo</li> </ul>
2-16-3 JSP
<ul> <li>foo</li> <li id="dummy:d1">bar</li> <li kw:d="dummy()">baz</li> </ul>
$ kwartz -l jstl ex-dummy.pdata <ul> <li>foo</li> </ul>
2-16-4 Perl
<ul> <li>foo</li> <li id="dummy:d1">bar</li> <li kw:d="dummy()">baz</li> </ul>
$ kwartz -l eperl ex-dummy.pdata <ul> <li>foo</li> </ul>
2-17 default, Default, DEFAULT
'default', 'Default', and 'DEFAULT' directive replaces content by expression only if expression is not nil, false, nor empty string.
'Default' directive escapes expression automatically, while 'DEFAULT' never escape it. 'default' directive escapes expression when command-line option '-e' is specified or PROPERTY_ESCAPE is true in configuration file.
2-17-1 Ruby
name: <em kw:d="default: user">Guest</em>
$ kwartz -l eruby ex-default.pdata name: <em><% if (user) && !(user).to_s.empty? then %><%= user %><% else %>Guest<% end %></em>
2-17-2 PHP
name: <em kw:d="default($user)">Guest</em>
$ kwartz -l php ex-default.pdata
name: <em><?php if ($user) { ?><?php echo $user; ?><?php } else { ?>Guest<?php } ?></em>
2-17-3 JSP
name: <em kw:d="default(user)">Guest</em>
$ kwartz -l jstl ex-default.pdata
name: <em><c:out value="${user}" default="Guest"/></em>
2-17-4 Perl
name: <em kw:d="default($user)">Guest</em>
$ kwartz -l eperl ex-default.pdata
name: <em><? if ($user) { !><?= $user !><? } else { !>Guest<? } !></em>
2-18 replace_element/content_with_element/content
'replace_element_with_element', 'replace_element_with_content', 'replace_content_with_element', and 'replace_content_with_content' directives replace element or content with other element or content.
These directives are language-independent when used with id attribute.
2-18-1 Ruby, PHP, JSP, Perl
<div id="mark:link"> back to <a href="/">home</a>. </div> <!-- replace element with other element --> <p id="replace_element_with_element:link"> back to home </p> <!-- replace element with other content--> <p id="replace_element_with_content:link"> back to home </p> <!-- replace content with other element --> <p id="replace_content_with_element:link"> back to home </p> <!-- replace content with other content --> <p id="replace_content_with_content:link"> back to home </p>
$ kwartz -l eruby ex-replace.pdata <div> back to <a href="/">home</a>. </div> <!-- replace element with other element --> <div> back to <a href="/">home</a>. </div> <!-- replace element with other content--> back to <a href="/">home</a>. <!-- replace content with other element --> <p> <div> back to <a href="/">home</a>. </div> </p> <!-- replace content with other content --> <p> back to <a href="/">home</a>. </p>