Kwartz-ruby 3.2 Reference Guide

release: $Release$

2   Directives in Presentation Data

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

presentation data (ex-elem.pdata)
<b kw:d="elem: expr">foo</b>
<b kw:d="Elem: expr">foo</b>
<b kw:d="ELEM: expr">foo</b>
compile
$ kwartz -l eruby ex-elem.pdata
<%= expr %>
<%=h expr %>
<%= expr %>

2-1-2   PHP

presentation data (ex-elem.pdata)
<b kw:d="elem($expr)">foo</b>
<b kw:d="Elem($expr)">foo</b>
<b kw:d="ELEM($expr)">foo</b>
compile
$ kwartz -l php ex-elem.pdata
<?php echo $expr; ?>
<?php echo htmlspecialchars($expr); ?>
<?php echo $expr; ?>

2-1-3   JSP

presentation data (ex-elem.pdata)
<b kw:d="elem(expr)">foo</b>
<b kw:d="Elem(expr)">foo</b>
<b kw:d="ELEM(expr)">foo</b>
compile
$ kwartz -l jstl ex-elem.pdata
${expr}
${expr}
<c:out value="${expr}" escapeXml="false"/>

2-1-4   Perl

presentation data (ex-elem.pdata)
<b kw:d="elem($expr)">foo</b>
<b kw:d="Elem($expr)">foo</b>
<b kw:d="ELEM($expr)">foo</b>
compile
$ 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

presentation data (ex-stag.pdata)
<b kw:d="stag: expr">foo</b>
<b kw:d="Stag: expr">foo</b>
<b kw:d="STAG: expr">foo</b>
compile
$ kwartz -l eruby ex-stag.pdata
<%= expr %>foo</b>
<%=h expr %>foo</b>
<%= expr %>foo</b>

2-2-2   PHP

presentation data (ex-stag.pdata)
<b kw:d="stag($expr)">foo</b>
<b kw:d="Stag($expr)">foo</b>
<b kw:d="STAG($expr)">foo</b>
compile
$ 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

presentation data (ex-stag.pdata)
<b kw:d="stag(expr)">foo</b>
<b kw:d="Stag(expr)">foo</b>
<b kw:d="STAG(expr)">foo</b>
compile
$ kwartz -l jstl ex-stag.pdata
${expr}foo</b>
${expr}foo</b>
<c:out value="${expr}" escapeXml="false"/>foo</b>

2-2-4   Perl

presentation data (ex-stag.pdata)
<b kw:d="stag($expr)">foo</b>
<b kw:d="Stag($expr)">foo</b>
<b kw:d="STAG($expr)">foo</b>
compile
$ 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

presentation data (ex-etag.pdata)
<b kw:d="etag: expr">foo</b>
<b kw:d="Etag: expr">foo</b>
<b kw:d="ETAG: expr">foo</b>
compile
$ kwartz -l eruby ex-etag.pdata
<b>foo<%= expr %>
<b>foo<%=h expr %>
<b>foo<%= expr %>

2-3-2   PHP

presentation data (ex-etag.pdata)
<b kw:d="etag($expr)">foo</b>
<b kw:d="Etag($expr)">foo</b>
<b kw:d="ETAG($expr)">foo</b>
compile
$ 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

presentation data (ex-etag.pdata)
<b kw:d="etag(expr)">foo</b>
<b kw:d="Etag(expr)">foo</b>
<b kw:d="ETAG(expr)">foo</b>
compile
$ kwartz -l jstl ex-etag.pdata
<b>foo${expr}
<b>foo${expr}
<b>foo<c:out value="${expr}" escapeXml="false"/>

2-3-4   Perl

presentation data (ex-etag.pdata)
<b kw:d="etag($expr)">foo</b>
<b kw:d="Etag($expr)">foo</b>
<b kw:d="ETAG($expr)">foo</b>
compile
$ 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

presentation data (ex-cont.pdata)
<b kw:d="cont: expr">foo</b>
<b kw:d="Cont: expr">foo</b>
<b kw:d="CONT: expr">foo</b>
compile
$ kwartz -l eruby ex-cont.pdata
<b><%= expr %></b>
<b><%=h expr %></b>
<b><%= expr %></b>

2-4-2   PHP

presentation data (ex-cont.pdata)
<b kw:d="cont($expr)">foo</b>
<b kw:d="Cont($expr)">foo</b>
<b kw:d="CONT($expr)">foo</b>
compile
$ 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

presentation data (ex-cont.pdata)
<b kw:d="cont(expr)">foo</b>
<b kw:d="Cont(expr)">foo</b>
<b kw:d="CONT(expr)">foo</b>
compile
$ kwartz -l jstl ex-cont.pdata
<b>${expr}</b>
<b>${expr}</b>
<b><c:out value="${expr}" escapeXml="false"/></b>

2-4-4   Perl

presentation data (ex-cont.pdata)
<b kw:d="cont($expr)">foo</b>
<b kw:d="Cont($expr)">foo</b>
<b kw:d="CONT($expr)">foo</b>
compile
$ 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

presentation data (ex-value.pdata)
<b kw:d="value: expr">foo</b>
<b kw:d="Value: expr">foo</b>
<b kw:d="VALUE: expr">foo</b>
compile
$ kwartz -l eruby ex-value.pdata
<b><%= expr %></b>
<b><%=h expr %></b>
<b><%= expr %></b>

2-5-2   PHP

presentation data (ex-value.pdata)
<b kw:d="value($expr)">foo</b>
<b kw:d="Value($expr)">foo</b>
<b kw:d="VALUE($expr)">foo</b>
compile
$ 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

presentation data (ex-value.pdata)
<b kw:d="value(expr)">foo</b>
<b kw:d="Value(expr)">foo</b>
<b kw:d="VALUE(expr)">foo</b>
compile
$ kwartz -l jstl ex-value.pdata
<b>${expr}</b>
<b>${expr}</b>
<b><c:out value="${expr}" escapeXml="false"/></b>

2-5-4   Perl

presentation data (ex-value.pdata)
<b kw:d="value($expr)">foo</b>
<b kw:d="Value($expr)">foo</b>
<b kw:d="VALUE($expr)">foo</b>
compile
$ 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

presentation data (ex-foreach.pdata)
<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>
compile
$ 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

presentation data (ex-foreach.pdata)
<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>
compile
$ 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

presentation data (ex-foreach.pdata)
<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>
compile
$ 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

presentation data (ex-foreach.pdata)
<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>
compile
$ 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

presentation data (ex-list.pdata)
<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>
compile
$ 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

presentation data (ex-list.pdata)
<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>
compile
$ 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

presentation data (ex-list.pdata)
<tr kw:d="list(item: list)">
  <td kw:d="cont(item)">foo</td>
</tr>
compile
$ kwartz -l jstl ex-list.pdata
<tr>
<c:forEach var="item" items="${list}">
  <td>${item}</td>
</c:forEach>
</tr>

2-7-4   Perl

presentation data (ex-list.pdata)
<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>
compile
$ 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

presentation data (ex-foreach_ctr.pdata)
<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>
compile
$ 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

presentation data (ex-foreach_ctr.pdata)
<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>
compile
$ 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

presentation data (ex-foreach_ctr.pdata)
<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>
compile
$ 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

presentation data (ex-foreach_ctr.pdata)
<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>
compile
$ 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

presentation data (ex-foreach_tgl.pdata)
<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>
compile
$ 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

presentation data (ex-foreach_tgl.pdata)
<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>
compile
$ 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

presentation data (ex-foreach_tgl.pdata)
<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>
compile
$ 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

presentation data (ex-foreach_tgl.pdata)
<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>
compile
$ 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

presentation data (ex-while.pdata)
<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>
compile
$ 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

presentation data (ex-while.pdata)
<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>
compile
$ 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

presentation data (ex-while.pdata)
*** not supported ***
compile
$ kwartz -l jstl ex-while.pdata
*** not supported ***

2-10-4   Perl

presentation data (ex-while.pdata)
<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>
compile
$ 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

presentation data (ex-if.pdata)
<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>
compile
$ 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

presentation data (ex-if.pdata)
<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>
compile
$ 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

presentation data (ex-if.pdata)
<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>
compile
$ 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

presentation data (ex-if.pdata)
<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>
compile
$ 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

presentation data (ex-set.pdata)
<tr kw:d="set color=i%2==0 ? 'red' : 'blue'">
 <td kw:d="cont: color">red</td>
</tr>
compile
$ kwartz -l eruby ex-set.pdata
<% color=i%2==0 ? 'red' : 'blue' %>
<tr>
 <td><%= color %></td>
</tr>

2-12-2   PHP

presentation data (ex-set.pdata)
<tr kw:d="set($color=$i%2==0 ? 'red' : 'blue')">
 <td kw:d="cont($color)">red</td>
</tr>
compile
$ kwartz -l php ex-set.pdata
<?php $color=$i%2==0 ? 'red' : 'blue'; ?>
<tr>
 <td><?php echo $color; ?></td>
</tr>

2-12-3   JSP

presentation data (ex-set.pdata)
<tr kw:d="set(color=i%2==0 ? 'red' : 'blue')">
 <td kw:d="cont(color)">red</td>
</tr>
compile
$ 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

presentation data (ex-set.pdata)
<tr kw:d="set($color=i%2==0 ? 'red' : 'blue')">
 <td kw:d="cont($color)">red</td>
</tr>
compile
$ 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

presentation data (ex-mark.pdata)
<ul id="mark:list">
 <li kw:d="id: item">foo</li>
</ul>
compile
$ kwartz -l eruby ex-mark.pdata
<ul>
 <li>foo</li>
</ul>

2-13-2   PHP

presentation data (ex-mark.pdata)
<ul id="mark:list">
 <li kw:d="id(item)">foo</li>
</ul>
compile
$ kwartz -l php ex-mark.pdata
<ul>
 <li>foo</li>
</ul>

2-13-3   JSP

presentation data (ex-mark.pdata)
<ul id="mark:list">
 <li kw:d="id(item)">foo</li>
</ul>
compile
$ kwartz -l jstl ex-mark.pdata
<ul>
 <li>foo</li>
</ul>

2-13-4   Perl

presentation data (ex-mark.pdata)
<ul id="mark:list">
 <li kw:d="id(item)">foo</li>
</ul>
compile
$ 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

presentation data (ex-attr.pdata)
<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>
compile
$ 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

presentation data (ex-attr.pdata)
<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>
compile
$ 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

presentation data (ex-attr.pdata)
<tr class="odd"
    kw:d="FOR(v: list); attr('class',v_tgl); attr('style',style)">
 <td kw:d="cont(v.name)">foo</td>
</tr>
compile
$ 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

presentation data (ex-attr.pdata)
<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>
compile
$ 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

presentation data (ex-append.pdata)
<input type="checkbox"
   kw:d="append: flag1 ? ' checked=\'checked\'' : ''">
compile
$ kwartz -l eruby ex-append.pdata
<input type="checkbox"<%= flag1 ? ' checked=\'checked\'' : '' %>>

2-15-2   PHP

presentation data (ex-append.pdata)
<input type="checkbox"
   kw:d="append($flag1 ? ' checked=\'checked\'' : '')">
compile
$ kwartz -l php ex-append.pdata
<input type="checkbox"<?php echo $flag1 ? ' checked=\'checked\'' : ''; ?>>

2-15-3   JSP

presentation data (ex-append.pdata)
<input type="checkbox"
   kw:d="append(flag1 ? ' checked=\'checked\'' : '')">
compile
$ kwartz -l jstl ex-append.pdata
<input type="checkbox"${flag1 ? ' checked=\'checked\'' : ''}>

2-15-4   Perl

presentation data (ex-append.pdata)
<input type="checkbox"
   kw:d="append($flag1 ? ' checked=\'checked\'' : '')">
compile
$ 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

presentation data (ex-dummy.pdata)
<ul>
  <li>foo</li>
  <li id="dummy:d1">bar</li>
  <li kw:d="dummy:">baz</li>
</ul>
compile
$ kwartz -l eruby ex-dummy.pdata
<ul>
  <li>foo</li>
</ul>

2-16-2   PHP

presentation data (ex-dummy.pdata)
<ul>
  <li>foo</li>
  <li id="dummy:d1">bar</li>
  <li kw:d="dummy()">baz</li>
</ul>
compile
$ kwartz -l php ex-dummy.pdata
<ul>
  <li>foo</li>
</ul>

2-16-3   JSP

presentation data (ex-dummy.pdata)
<ul>
  <li>foo</li>
  <li id="dummy:d1">bar</li>
  <li kw:d="dummy()">baz</li>
</ul>
compile
$ kwartz -l jstl ex-dummy.pdata
<ul>
  <li>foo</li>
</ul>

2-16-4   Perl

presentation data (ex-dummy.pdata)
<ul>
  <li>foo</li>
  <li id="dummy:d1">bar</li>
  <li kw:d="dummy()">baz</li>
</ul>
compile
$ 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

presentation data (ex-default.pdata)
name: <em kw:d="default: user">Guest</em>
compile
$ kwartz -l eruby ex-default.pdata
name: <em><% if (user) && !(user).to_s.empty? then %><%= user %><% else %>Guest<% end %></em>

2-17-2   PHP

presentation data (ex-default.pdata)
name: <em kw:d="default($user)">Guest</em>
compile
$ kwartz -l php ex-default.pdata
name: <em><?php if ($user) { ?><?php echo $user; ?><?php } else { ?>Guest<?php } ?></em>

2-17-3   JSP

presentation data (ex-default.pdata)
name: <em kw:d="default(user)">Guest</em>
compile
$ kwartz -l jstl ex-default.pdata
name: <em><c:out value="${user}" default="Guest"/></em>

2-17-4   Perl

presentation data (ex-default.pdata)
name: <em kw:d="default($user)">Guest</em>
compile
$ 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

presentation data (ex-replace.pdata)
<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>
compile
$ 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>

2-19   Language-independent Directive

Some directives can be language-independent.

  • 'mark' and 'replace_(element|content)_with_(element|content)' directives can be language-independent because their argument is element name which is language-independent.
  • 'dummy' directive can be language-independent because it takes dummy argument.
  • 'value', 'elem', 'stag', 'etag', 'cont', and 'default' directives can be language-independent if their expression argument is one of the following format.
    • variable
    • object.property
    • hash['key'], hash["key"], hash[:key]
    • array[123], array[var]

Language-independent directives are always described with id attribute.

2-19-1   Ruby

presentation data (ex-expr.pdata)
<p id="value:user">foo</p>
<p id="value:user.name">foo</p>
<p id="value:user['name']">foo</p>
<p id="value:user[:name]">foo</p>
<p id="value:user[0]">foo</p>
<p id="value:user[index]">foo</p>
compile
$ kwartz -l eruby ex-expr.pdata
<p><%= user %></p>
<p><%= user.name %></p>
<p><%= user['name'] %></p>
<p><%= user[:name] %></p>
<p><%= user[0] %></p>
<p><%= user[index] %></p>

2-19-2   PHP

presentation data (ex-expr.pdata)
<p id="value:user">foo</p>
<p id="value:user.name">foo</p>
<p id="value:user['name']">foo</p>
<p id="value:user[:name]">foo</p>
<p id="value:user[0]">foo</p>
<p id="value:user[index]">foo</p>
compile
$ kwartz -l php ex-expr.pdata
<p><?php echo $user; ?></p>
<p><?php echo $user->name; ?></p>
<p><?php echo $user['name']; ?></p>
<p><?php echo $user['name']; ?></p>
<p><?php echo $user[0]; ?></p>
<p><?php echo $user[$index]; ?></p>

2-19-3   JSP

presentation data (ex-expr.pdata)
<p id="value:user">foo</p>
<p id="value:user.name">foo</p>
<p id="value:user['name']">foo</p>
<p id="value:user[:name]">foo</p>
<p id="value:user[0]">foo</p>
<p id="value:user[index]">foo</p>
compile
$ kwartz -l jstl ex-expr.pdata
<p>${user}</p>
<p>${user.name}</p>
<p>${user['name']}</p>
<p>${user['name']}</p>
<p>${user[0]}</p>
<p>${user[index]}</p>

2-19-4   Perl

presentation data (ex-expr.pdata)
<p id="value:user">foo</p>
<p id="value:user.name">foo</p>
<p id="value:user['name']">foo</p>
<p id="value:user[:name]">foo</p>
<p id="value:user[0]">foo</p>
<p id="value:user[index]">foo</p>
compile
$ kwartz -l eperl ex-expr.pdata
<p><?= $user !></p>
<p><?= $user->{name} !></p>
<p><?= $user{'name'} !></p>
<p><?= $user{'name'} !></p>
<p><?= $user[0] !></p>
<p><?= $user[$index] !></p>