Kwartz-ruby 3.0 Reference Guide
$Release: 3.1.2 $
$Date: 2006-09-30 05:02:08 +0900 (Sat, 30 Sep 2006) $
Preface
This document(*1) is the reference manual of Kwartz-ruby.
Kwartz(*2) is a template system which realized the concept 'Independence of Presentation Logic'. It means that presentation logics are separated from both presentation data (typically HTML file) and business logic layer (typically main program). Kwartz-ruby is an implementation of Kwartz in Ruby.
If you are new to Kwartz, see Users' Guide at first.
- (*1)
- This document is generated automatically from unit-test data. Knuth had propsed integration of code and document. I propose integration of test and document :-)
- (*2)
- Development of Kwartz had subsidized by Exploratory Software Project of IPA (Information-Technology Promotion Agency Japan).
Table of Contents
Pesentation Logic
Presentation logic format in Kwartz is similar to Cascading Style Sheet (CSS).
- Presentation logic file is a set of ruleset.
- Ruleset is a pair of selector and declarations.
- Declaration is a pair of property and value.
plogic ::= ruleset* ruleset ::= selector '{' [ declaration ';' ]* '}' selector ::= '#' name declaration ::= property ':' value property ::= 'elem' | 'Elem' | 'ELEM' | 'stag' | 'Stag' | 'STAG' | 'etag' | 'Etag' | 'ETAG' | 'cont' | 'Cont' | 'CONT' | 'value' | 'Value' | 'VALUE' | 'attrs' | 'Attrs' | 'ATTRS' | 'append' | 'Append' | 'APPEND' | 'remove' | 'logic'
Notice that the tail semicolon of declaration is not omittable.
elem, Elem, ELEM
elem:
, Elem:
, and ELEM:
properties replaces the element
with expression value.
Elem:
always escape expression value while ELEM:
never escape it.
elem:
escapes when command-line option '-e' is specified or
configuration option 'PROPERTY_ESCAPE' is ture.
Ruby
<p id="mark:name1">aaa</p> <p id="mark:name2">bbb</p> <p id="mark:name3">ccc</p>
#name1 { elem: user[:name]; } #name2 { Elem: user[:name]; } #name3 { ELEM: user[:name]; }
$ kwartz -l eruby -p ex-elem.plogic ex-elem.pdata <%= user[:name] %> <%=h user[:name] %> <%= user[:name] %>
PHP
<p id="mark:name1">aaa</p> <p id="mark:name2">bbb</p> <p id="mark:name3">ccc</p>
#name1 { elem: $user['name']; } #name2 { Elem: $user['name']; } #name3 { ELEM: $user['name']; }
$ kwartz -l php -p ex-elem.plogic ex-elem.pdata <?php echo $user['name']; ?> <?php echo htmlspecialchars($user['name']); ?> <?php echo $user['name']; ?>
JSP
<p id="mark:name1">aaa</p> <p id="mark:name2">bbb</p> <p id="mark:name3">ccc</p>
#name1 { elem: user.name; } #name2 { Elem: user.name; } #name3 { ELEM: user.name; }
$ kwartz -l jstl -p ex-elem.plogic ex-elem.pdata <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> ${user.name} ${user.name} <c:out value="${user.name}" escapeXml="false"/>
Perl
<p id="mark:name1">aaa</p> <p id="mark:name2">bbb</p> <p id="mark:name3">ccc</p>
#name1 { elem: $user{'name'}; } #name2 { Elem: $user{'name'}; } #name3 { ELEM: $user{'name'}; }
$ kwartz -l eperl -p ex-elem.plogic ex-elem.pdata <?= $user{'name'} !> <?= encode_entities($user{'name'}) !> <?= $user{'name'} !>
cont, Cont, CONT
cont:
, Cont:
, and CONT:
properties replaces the element
with expression value.
Cont:
always escape expression value while CONT:
never escape it.
cont:
escapes when command-line option '-e' is specified or
configuration option 'PROPERTY_ESCAPE' is ture.
Ruby
<p id="mark:name1">aaa</p> <p id="mark:name2">bbb</p> <p id="mark:name3">ccc</p>
#name1 { cont: user[:name]; } #name2 { Cont: user[:name]; } #name3 { CONT: user[:name]; }
$ kwartz -l eruby -p ex-cont.plogic ex-cont.pdata <p><%= user[:name] %></p> <p><%=h user[:name] %></p> <p><%= user[:name] %></p>
PHP
<p id="mark:name1">aaa</p> <p id="mark:name2">bbb</p> <p id="mark:name3">ccc</p>
#name1 { cont: $user['name']; } #name2 { Cont: $user['name']; } #name3 { CONT: $user['name']; }
$ kwartz -l php -p ex-cont.plogic ex-cont.pdata <p><?php echo $user['name']; ?></p> <p><?php echo htmlspecialchars($user['name']); ?></p> <p><?php echo $user['name']; ?></p>
JSP
<p id="mark:name1">aaa</p> <p id="mark:name2">bbb</p> <p id="mark:name3">ccc</p>
#name1 { cont: user.name; } #name2 { Cont: user.name; } #name3 { CONT: user.name; }
$ kwartz -l jstl -p ex-cont.plogic ex-cont.pdata <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> <p>${user.name}</p> <p>${user.name}</p> <p><c:out value="${user.name}" escapeXml="false"/></p>
Perl
<p id="mark:name1">aaa</p> <p id="mark:name2">bbb</p> <p id="mark:name3">ccc</p>
#name1 { cont: $user{'name'}; } #name2 { Cont: $user{'name'}; } #name3 { CONT: $user{'name'}; }
$ kwartz -l eperl -p ex-cont.plogic ex-cont.pdata <p><?= $user{'name'} !></p> <p><?= encode_entities($user{'name'}) !></p> <p><?= $user{'name'} !></p>
value, Value, VALUE
value:
, Value:
, and VALUE:
properties replaces the element
with expression value.
These are the same as cont:
, Cont:
, and CONT:
properties
respectively.
Ruby
<p id="mark:name1">aaa</p> <p id="mark:name2">bbb</p> <p id="mark:name3">ccc</p>
#name1 { value: user[:name]; } #name2 { Value: user[:name]; } #name3 { VALUE: user[:name]; }
$ kwartz -l eruby -p ex-value.plogic ex-value.pdata <p><%= user[:name] %></p> <p><%=h user[:name] %></p> <p><%= user[:name] %></p>
PHP
<p id="mark:name1">aaa</p> <p id="mark:name2">bbb</p> <p id="mark:name3">ccc</p>
#name1 { value: $user['name']; } #name2 { Value: $user['name']; } #name3 { VALUE: $user['name']; }
$ kwartz -l php -p ex-value.plogic ex-value.pdata <p><?php echo $user['name']; ?></p> <p><?php echo htmlspecialchars($user['name']); ?></p> <p><?php echo $user['name']; ?></p>
JSP
<p id="mark:name1">aaa</p> <p id="mark:name2">bbb</p> <p id="mark:name3">ccc</p>
#name1 { value: user.name; } #name2 { Value: user.name; } #name3 { VALUE: user.name; }
$ kwartz -l jstl -p ex-value.plogic ex-value.pdata <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> <p>${user.name}</p> <p>${user.name}</p> <p><c:out value="${user.name}" escapeXml="false"/></p>
Perl
<p id="mark:name1">aaa</p> <p id="mark:name2">bbb</p> <p id="mark:name3">ccc</p>
#name1 { value: $user{'name'}; } #name2 { Value: $user{'name'}; } #name3 { VALUE: $user{'name'}; }
$ kwartz -l eperl -p ex-value.plogic ex-value.pdata <p><?= $user{'name'} !></p> <p><?= encode_entities($user{'name'}) !></p> <p><?= $user{'name'} !></p>
stag, Stag, STAG
stage:
, Stag:
, and STAG:
properties replaces the start-tag
with expression value.
Stag:
always escape expression value while STAG:
never escape it.
stag:
escapes when command-line option '-e' is specified or
configuration option 'PROPERTY_ESCAPE' is ture.
Ruby
<a href="#" id="mark:link1"><img src="button1.png"></a> <a href="#" id="mark:link2"><img src="button2.png"></a> <a href="#" id="mark:link3"><img src="button3.png"></a>
#link1 { stag: start_link_tag :action=>'list'; } #link2 { Stag: start_link_tag :action=>'list'; } #link3 { STAG: start_link_tag :action=>'list'; }
$ kwartz -l eruby -p ex-stag.plogic ex-stag.pdata <%= start_link_tag :action=>'list' %><img src="button1.png"></a> <%=h start_link_tag :action=>'list' %><img src="button2.png"></a> <%= start_link_tag :action=>'list' %><img src="button3.png"></a>
PHP
<a href="#" id="mark:link1"><img src="button1.png"></a> <a href="#" id="mark:link2"><img src="button2.png"></a> <a href="#" id="mark:link3"><img src="button3.png"></a>
#link1 { stag: start_link_tag('member/list'); } #link2 { Stag: start_link_tag('member/list'); } #link3 { STAG: start_link_tag('member/list'); }
$ kwartz -l php -p ex-stag.plogic ex-stag.pdata <?php echo start_link_tag('member/list'); ?><img src="button1.png"></a> <?php echo htmlspecialchars(start_link_tag('member/list')); ?><img src="button2.png"></a> <?php echo start_link_tag('member/list'); ?><img src="button3.png"></a>
JSP
<a href="#" id="mark:link1"><img src="button1.png"></a> <a href="#" id="mark:link2"><img src="button2.png"></a> <a href="#" id="mark:link3"><img src="button3.png"></a>
#link1 { stag: fn:start_link_tag('member', 'list'); } #link2 { Stag: fn:start_link_tag('member', 'list'); } #link3 { STAG: fn:start_link_tag('member', 'list'); }
$ kwartz -l jstl -p ex-stag.plogic ex-stag.pdata <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> ${fn:start_link_tag('member', 'list')}<img src="button1.png"></a> ${fn:start_link_tag('member', 'list')}<img src="button2.png"></a> <c:out value="${fn:start_link_tag('member', 'list')}" escapeXml="false"/><img src="button3.png"></a>
Perl
<a href="#" id="mark:link1"><img src="button1.png"></a> <a href="#" id="mark:link2"><img src="button2.png"></a> <a href="#" id="mark:link3"><img src="button3.png"></a>
#link1 { stag: start_link_tag('member/list'); } #link2 { Stag: start_link_tag('member/list'); } #link3 { STAG: start_link_tag('member/list'); }
$ kwartz -l eperl -p ex-stag.plogic ex-stag.pdata <?= start_link_tag('member/list') !><img src="button1.png"></a> <?= encode_entities(start_link_tag('member/list')) !><img src="button2.png"></a> <?= start_link_tag('member/list') !><img src="button3.png"></a>
etag, Etag, ETAG
stage:
, Etag:
, and ETAG:
properties replaces the end-tag
with expression value.
Etag:
always escape expression value while ETAG:
never escape it.
etag:
escapes when command-line option '-e' is specified or
configuration option 'PROPERTY_ESCAPE' is ture.
Ruby
<li id="mark:item1">foo</li> <li id="mark:item2">bar</li> <li id="mark:item3">baz</li>
#item1 { etag: is_xml ? '</li>' : ''; } #item2 { Etag: is_xml ? '</li>' : ''; } #item3 { ETAG: is_xml ? '</li>' : ''; }
$ kwartz -l eruby -p ex-etag.plogic ex-etag.pdata <li>foo<%= is_xml ? '</li>' : '' %> <li>bar<%=h is_xml ? '</li>' : '' %> <li>baz<%= is_xml ? '</li>' : '' %>
PHP
<li id="mark:item1">foo</li> <li id="mark:item2">bar</li> <li id="mark:item3">baz</li>
#item1 { etag: $is_xml ? '</li>' : ''; } #item2 { Etag: $is_xml ? '</li>' : ''; } #item3 { ETAG: $is_xml ? '</li>' : ''; }
$ kwartz -l php -p ex-etag.plogic ex-etag.pdata <li>foo<?php echo $is_xml ? '</li>' : ''; ?> <li>bar<?php echo htmlspecialchars($is_xml ? '</li>' : ''); ?> <li>baz<?php echo $is_xml ? '</li>' : ''; ?>
JSP
<li id="mark:item1">foo</li> <li id="mark:item2">bar</li> <li id="mark:item3">baz</li>
#item1 { etag: is_xml ? '</li>' : ''; } #item2 { Etag: is_xml ? '</li>' : ''; } #item3 { ETAG: is_xml ? '</li>' : ''; }
$ kwartz -l jstl -p ex-etag.plogic ex-etag.pdata <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> <li>foo${is_xml ? '</li>' : ''} <li>bar${is_xml ? '</li>' : ''} <li>baz<c:out value="${is_xml ? '</li>' : ''}" escapeXml="false"/>
Perl
<li id="mark:item1">foo</li> <li id="mark:item2">bar</li> <li id="mark:item3">baz</li>
#item1 { etag: $is_xml ? '</li>' : ''; } #item2 { Etag: $is_xml ? '</li>' : ''; } #item3 { ETAG: $is_xml ? '</li>' : ''; }
$ kwartz -l eperl -p ex-etag.plogic ex-etag.pdata <li>foo<?= $is_xml ? '</li>' : '' !> <li>bar<?= encode_entities($is_xml ? '</li>' : '') !> <li>baz<?= $is_xml ? '</li>' : '' !>
attrs, Attrs, ATTRS
attrs:
, Attrs:
, ATTRS:
, property replaces or adds attributes.
Attrs:
always escape expression value while ATTRS:
never escape it.
attrs:
escapes when command-line option '-e' is specified or
configuration option 'PROPERTY_ESCAPE' is ture.
Notice that the follwing will be parse error
because Kwartz parses attrs:
property with pattern matching.
#foo { attrs: 'class' klass, 'style' style; }
Ruby
<p id="mark:item" class="para"> AAA </p>
#item { attrs: 'class' klass, 'style' style; }
$ kwartz -l eruby -p ex-attrs.plogic ex-attrs.pdata <p class="<%= klass %>" style="<%= style %>"> AAA </p>
PHP
<p id="mark:item" class="para"> AAA </p>
#item { attrs: 'class' $class, 'style' $style; }
$ kwartz -l php -p ex-attrs.plogic ex-attrs.pdata <p class="<?php echo $class; ?>" style="<?php echo $style; ?>"> AAA </p>
JSP
<p id="mark:item" class="para"> AAA </p>
#item { attrs: 'class' klass, 'style' style; }
$ kwartz -l jstl -p ex-attrs.plogic ex-attrs.pdata <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> <p class="${klass}" style="${style}"> AAA </p>
Perl
<p id="mark:item" class="para"> AAA </p>
#item { attrs: 'class' $class, 'style' $style; }
$ kwartz -l eperl -p ex-attrs.plogic ex-attrs.pdata <p class="<?= $class !>" style="<?= $style !>"> AAA </p>
append, Append, APPEND
append:
, Append:
, APPEND:
directive appends
expressions to the start tag.
Append:
always escape expression value while APPEND:
never escape it.
append:
escapes when command-line option '-e' is specified or
configuration option 'PROPERTY_ESCAPE' is ture.
The following is an example to append several expressions.
#remember { append: expr1, expr2, expr3; }
Notice that the following will be parse error.
#remember { append: expr1, expr2, expr3; }
Ruby
<input type="checkboxk" id="mark:remember" value="y">Remeber me
#remember { append: flag ? ' checked' : ''; }
$ kwartz -l eruby -p ex-append.plogic ex-append.pdata <input type="checkboxk" value="y"<%= flag ? ' checked' : '' %>>Remeber me
PHP
<input type="checkboxk" id="mark:remember" value="y">Remeber me
#remember { append: $flag ? ' checked' : ''; }
$ kwartz -l php -p ex-append.plogic ex-append.pdata <input type="checkboxk" value="y"<?php echo $flag ? ' checked' : ''; ?>>Remeber me
JSP
<input type="checkboxk" id="mark:remember" value="y">Remeber me
#remember { append: flag ? ' checked' : ''; }
$ kwartz -l jstl -p ex-append.plogic ex-append.pdata <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> <input type="checkboxk" value="y"${flag ? ' checked' : ''}>Remeber me
Perl
<input type="checkboxk" id="mark:remember" value="y">Remeber me
#remember { append: $flag ? ' checked' : ''; }
$ kwartz -l eperl -p ex-append.plogic ex-append.pdata <input type="checkboxk" value="y"<?= $flag ? ' checked' : '' !>>Remeber me
remove
remove:
property removes attributes.
Ruby
<p id="foo" class="paragraph" style="color: red"> AAA </p>
#foo { remove: 'id', 'style'; }
$ kwartz -l eruby -p ex-remove.plogic ex-remove.pdata <p class="paragraph"> AAA </p>
PHP
<p id="foo" class="paragraph" style="color: red"> AAA </p>
#foo { remove: 'id', 'style'; }
$ kwartz -l php -p ex-remove.plogic ex-remove.pdata <p class="paragraph"> AAA </p>
JSP
<p id="foo" class="paragraph" style="color: red"> AAA </p>
#foo { remove: 'id', 'style'; }
$ kwartz -l jstl -p ex-remove.plogic ex-remove.pdata <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> <p class="paragraph"> AAA </p>
Perl
<p id="foo" class="paragraph" style="color: red"> AAA </p>
#foo { remove: 'id', 'style'; }
$ kwartz -l eperl -p ex-remove.plogic ex-remove.pdata <p class="paragraph"> AAA </p>
logic
logic:
property represents the presentation logic body of the element.
In the logic:
property, the folllowings are available.
-
_elem
- represents the element
-
_stag
- represents start-tag of the element
-
_cont
- represents content of the element
-
_stag
- represents end-tag of the element
-
_element(name)
- represents the other element marked as name.
-
_content(name)
- represents the content of other element marked as name.
In the logic:
property, it is able to write statements in target language
(Ruby, PHP, Java, Perl, and so on).
Ruby
<ul> <li id="mark:items">AAA</li> </ul>
#items { value: item; logic: { @list.each do |item| _stag _cont _etag end } }
$ kwartz -l eruby -p ex-logic.plogic ex-logic.pdata <ul> <% @list.each do |item| %> <li><%= item %></li> <% end %> </ul>
PHP
<ul> <li id="mark:items">AAA</li> </ul>
#items { value: $item; logic: { foreach ($list as $item) { _stag(); _cont(); _etag(); } } }
$ kwartz -l php -p ex-logic.plogic ex-logic.pdata <ul> <?php foreach ($list as $item) { ?> <li><?php echo $item; ?></li> <?php } ?> </ul>
JSP
<ul> <li id="mark:items">AAA</li> </ul>
#items { value: item; logic: { <c:forEach var="item" items="${list}"> _stag(); _cont(); _etag(); </c:forEach> } }
$ kwartz -l jstl -p ex-logic.plogic ex-logic.pdata <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> <ul> <c:forEach var="item" items="${list}"> <li>${item}</li> </c:forEach> </ul>
Perl
<ul> <li id="mark:items">AAA</li> </ul>
#items { value: $item; logic: { foreach ($item in @list) { _stag(); _cont(); _etag(); } } }
$ kwartz -l eperl -p ex-logic.plogic ex-logic.pdata <ul> <? foreach ($item in @list) { !> <li><?= $item !></li> <? } !> </ul>
begin, end
begin:
and end:
property represents the prework and postwork
of document respectively.
These properties takes target code block and are available only with
'#DOCUMENT' selector.
Ruby
<p>Hello <span id="mark:username">world</span>!</p> <ul> <li id="mark:menu">menu item</li> </ul>
#DOCUMENT { begin: { username = @context[:username] menulist = @context[:menulist] } end: { print "<!-- document end -->\n" } } #username { value: username; } #menu { value: menu; logic: { for menu in menulist _elem end } }
$ kwartz -l eruby -p ex-begin.plogic ex-begin.pdata <% username = @context[:username] %> <% menulist = @context[:menulist] %> <p>Hello <span><%= username %></span>!</p> <ul> <% for menu in menulist %> <li><%= menu %></li> <% end %> </ul> <%= "<!-- document end -->\n" %>
PHP
<p>Hello <span id="mark:username">world</span>!</p> <ul> <li id="mark:menu">menu item</li> </ul>
#DOCUMENT { begin: { $username = $context['username']; $menulist = $context['menulist']; } end: { print("<!-- document end -->\n"); } } #username { value: $username; } #menu { value: $menu; logic: { foreach ($menulist as $menu) { _elem(); } } }
$ kwartz -l php -p ex-begin.plogic ex-begin.pdata <?php $username = $context['username']; ?> <?php $menulist = $context['menulist']; ?> <p>Hello <span><?php echo $username; ?></span>!</p> <ul> <?php foreach ($menulist as $menu) { ?> <li><?php echo $menu; ?></li> <?php } ?> </ul> <?php echo "<!-- document end -->\n"; ?>
JSP
<p>Hello <span id="mark:username">world</span>!</p> <ul> <li id="mark:menu">menu item</li> </ul>
#DOCUMENT { begin: { <c:set var="username" value="${context.username}"/> <c:set var="menulist" value="${context.menulist}"/> } end: { <c:out value="<!-- document end -->\n"/> } } #username { value: username; } #menu { value: menu; logic: { <c:forEach var="menu" items="${menulist}"> _elem(); </c:forEach> } }
$ kwartz -l jstl -p ex-begin.plogic ex-begin.pdata <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> <c:set var="username" value="${context.username}"/> <c:set var="menulist" value="${context.menulist}"/> <p>Hello <span>${username}</span>!</p> <ul> <c:forEach var="menu" items="${menulist}"> <li>${menu}</li> </c:forEach> </ul> <c:out value="<!-- document end -->\n"/>
Perl
<p>Hello <span id="mark:username">world</span>!</p> <ul> <li id="mark:menu">menu item</li> </ul>
#DOCUMENT { begin: { $username = $context{'username'}; @menulist = $context{'menulist'}; } end: { print("<!-- document end -->\n"); } } #username { value: $username; } #menu { value: $menu; logic: { foreach ($menu in @menulist) { _elem(); } } }
$ kwartz -l eperl -p ex-begin.plogic ex-begin.pdata <? $username = $context{'username'}; !> <? @menulist = $context{'menulist'}; !> <p>Hello <span><?= $username !></span>!</p> <ul> <? foreach ($menu in @menulist) { !> <li><?= $menu !></li> <? } !> </ul> <?= "<!-- document end -->\n" !>
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.
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.
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 %>
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; ?>
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"/>
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 !>
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.
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>
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>
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>
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>
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.
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 %>
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; ?>
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"/>
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 !>
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.
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>
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>
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>
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>
value, Value, VALUE
'value', 'Value', and 'VALUE' directives are equivalent to 'cont', 'Cont', and 'CONT' directives respectively.
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>
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>
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>
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>
foreach
'foreach' directive interates element, while 'loop' directive iterates content.
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 %>
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 } ?>
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>
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> <? } !>
list
'list' directive interates content, while 'foreach' directive iterates element.
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>
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>
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>
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>
Foreach, List
'Foreach' and 'List' directives iterate element or content with loop counter (starting with 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>
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>
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>
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>
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.
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>
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>
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>
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>
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.
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>
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>
JSP
*** not supported ***
$ kwartz -l jstl ex-while.pdata *** not supported ***
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>
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.
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 %>
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 } ?>
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>
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> <? } !>
set
'set' directive executes any expression.
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>
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>
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>
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>
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.
Ruby
<ul id="mark:list"> <li kw:d="id: item">foo</li> </ul>
$ kwartz -l eruby ex-mark.pdata <ul> <li>foo</li> </ul>
PHP
<ul id="mark:list"> <li kw:d="id(item)">foo</li> </ul>
$ kwartz -l php ex-mark.pdata <ul> <li>foo</li> </ul>
JSP
<ul id="mark:list"> <li kw:d="id(item)">foo</li> </ul>
$ kwartz -l jstl ex-mark.pdata <ul> <li>foo</li> </ul>
Perl
<ul id="mark:list"> <li kw:d="id(item)">foo</li> </ul>
$ kwartz -l eperl ex-mark.pdata <ul> <li>foo</li> </ul>
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.
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 %>
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 } ?>
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>
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> <? } !>
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.
Ruby
<input type="checkbox" kw:d="append: flag1 ? ' checked=\'checked\'' : ''">
$ kwartz -l eruby ex-append.pdata <input type="checkbox"<%= flag1 ? ' checked=\'checked\'' : '' %>>
PHP
<input type="checkbox" kw:d="append($flag1 ? ' checked=\'checked\'' : '')">
$ kwartz -l php ex-append.pdata <input type="checkbox"<?php echo $flag1 ? ' checked=\'checked\'' : ''; ?>>
JSP
<input type="checkbox" kw:d="append(flag1 ? ' checked=\'checked\'' : '')">
$ kwartz -l jstl ex-append.pdata <input type="checkbox"${flag1 ? ' checked=\'checked\'' : ''}>
Perl
<input type="checkbox" kw:d="append($flag1 ? ' checked=\'checked\'' : '')">
$ kwartz -l eperl ex-append.pdata <input type="checkbox"<?= $flag1 ? ' checked=\'checked\'' : '' !>>
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.
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>
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>
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>
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>
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.
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>
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>
JSP
name: <em kw:d="default(user)">Guest</em>
$ kwartz -l jstl ex-default.pdata name: <em><c:out value="${user}" default="Guest"/></em>
Perl
name: <em kw:d="default($user)">Guest</em>
$ kwartz -l eperl ex-default.pdata name: <em><? if ($user) { !><?= $user !><? } else { !>Guest<? } !></em>
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.
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>
Command-Line Options
Usage: kwartz [..options..] [-p file.plogic] file.html > file.rhtml
Command-line options:
- -h
- Show help.
- -v
- Show version.
- -e
-
Escape (sanitize) expression value.
This is an alias of '
--escape=true
' - -l lang
- Target language ('eruby, 'php', 'eperl', 'rails', or 'jstl'). Default is 'eruby'.
- -k kanji
- Kanji code (euc/sjis/utf8). Default is null.
- -r library,...
- Require libraries.
- -p plogic,...
- Presentation logic files. Suffix '.plogic' is omittable.
- -i pdata,...
- Import presentation data files.
- -L layoutfile
- Layout file. '-L f1 f2' is equivalent to '-i f2 f1'.
- -x elem-id
- Extract content of element marked by elem-id.
- -X elem-id
- Extract element marked by elem-id.
- -f yamlfile
- YAML file for context values.
- -t
- Expand tab character in YAML file.
- -S
- Convert mapping key from string to symbol in YAML file.
Command-line properties:
- --dattr=str
- Directive attribute name.
- --odd=value
- Odd value for FOREACH/LOOP directive (default "'odd'").
- --even=value
- Even value for FOREACH/LOOP directive (default "'even'").
- --header=str
- Header text.
- --footer=str
- Footer text.
- --delspan={true|false}
- Delete dummy span tag (default false).
- --escape={true|false}
- Escape (sanitize) (default false).
- --jstl={1.2|1.1}
- JSTL version (default 1.2).
- --charset=charset
- Character-set for JSTL (default none).