Kwartz-ruby 3.2 Reference Guide

release: $Release: 3.2.0 $
last update: $Date$

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



Properties in Pesentation Logic

Presentation logic format in Kwartz is similar to Cascading Style Sheet (CSS).

Pseudo-EBNF syntax of presentation logic
plogic        ::=  rulesets
rulesets      ::=  rulesets ruleset
                |  ruleset
ruleset       ::=  selectors '{' declarations '}'
                |  selectors '{' '}'
selectors     ::=  selectors ',' selector
                |  selector
desclarations ::=  declarations declaration
                |  declaration
selector      ::=  '#' name
                |  '.' name
		|  name
declaration   ::=  property ':' value ';'
                |  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'
	        |  'before'
	        |  'after'

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

presentation data (ex-elem.pdata)
<p id="mark:name1">aaa</p>
<p id="mark:name2">bbb</p>
<p id="mark:name3">ccc</p>
presentation logic (ex-elem.plogic)
#name1 {
  elem: user[:name];
}
#name2 {
  Elem: user[:name];
}
#name3 {
  ELEM: user[:name];
}
compile
$ kwartz -l eruby -p ex-elem.plogic ex-elem.pdata
<%= user[:name] %>
<%=h user[:name] %>
<%= user[:name] %>

PHP

presentation data (ex-elem.pdata)
<p id="mark:name1">aaa</p>
<p id="mark:name2">bbb</p>
<p id="mark:name3">ccc</p>
presentation logic (ex-elem.plogic)
#name1 {
  elem: $user['name'];
}
#name2 {
  Elem: $user['name'];
}
#name3 {
  ELEM: $user['name'];
}
compile
$ kwartz -l php -p ex-elem.plogic ex-elem.pdata
<?php echo $user['name']; ?>
<?php echo htmlspecialchars($user['name']); ?>
<?php echo $user['name']; ?>

JSP

presentation data (ex-elem.pdata)
<p id="mark:name1">aaa</p>
<p id="mark:name2">bbb</p>
<p id="mark:name3">ccc</p>
presentation logic (ex-elem.plogic)
#name1 {
  elem: user.name;
}
#name2 {
  Elem: user.name;
}
#name3 {
  ELEM: user.name;
}
compile
$ 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

presentation data (ex-elem.pdata)
<p id="mark:name1">aaa</p>
<p id="mark:name2">bbb</p>
<p id="mark:name3">ccc</p>
presentation logic (ex-elem.plogic)
#name1 {
  elem: $user{'name'};
}
#name2 {
  Elem: $user{'name'};
}
#name3 {
  ELEM: $user{'name'};
}
compile
$ 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

presentation data (ex-cont.pdata)
<p id="mark:name1">aaa</p>
<p id="mark:name2">bbb</p>
<p id="mark:name3">ccc</p>
presentation logic (ex-cont.plogic)
#name1 {
  cont: user[:name];
}
#name2 {
  Cont: user[:name];
}
#name3 {
  CONT: user[:name];
}
compile
$ kwartz -l eruby -p ex-cont.plogic ex-cont.pdata
<p><%= user[:name] %></p>
<p><%=h user[:name] %></p>
<p><%= user[:name] %></p>

PHP

presentation data (ex-cont.pdata)
<p id="mark:name1">aaa</p>
<p id="mark:name2">bbb</p>
<p id="mark:name3">ccc</p>
presentation logic (ex-cont.plogic)
#name1 {
  cont: $user['name'];
}
#name2 {
  Cont: $user['name'];
}
#name3 {
  CONT: $user['name'];
}
compile
$ 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

presentation data (ex-cont.pdata)
<p id="mark:name1">aaa</p>
<p id="mark:name2">bbb</p>
<p id="mark:name3">ccc</p>
presentation logic (ex-cont.plogic)
#name1 {
  cont: user.name;
}
#name2 {
  Cont: user.name;
}
#name3 {
  CONT: user.name;
}
compile
$ 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

presentation data (ex-cont.pdata)
<p id="mark:name1">aaa</p>
<p id="mark:name2">bbb</p>
<p id="mark:name3">ccc</p>
presentation logic (ex-cont.plogic)
#name1 {
  cont: $user{'name'};
}
#name2 {
  Cont: $user{'name'};
}
#name3 {
  CONT: $user{'name'};
}
compile
$ 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

presentation data (ex-value.pdata)
<p id="mark:name1">aaa</p>
<p id="mark:name2">bbb</p>
<p id="mark:name3">ccc</p>
presentation logic (ex-value.plogic)
#name1 {
  value: user[:name];
}
#name2 {
  Value: user[:name];
}
#name3 {
  VALUE: user[:name];
}
compile
$ kwartz -l eruby -p ex-value.plogic ex-value.pdata
<p><%= user[:name] %></p>
<p><%=h user[:name] %></p>
<p><%= user[:name] %></p>

PHP

presentation data (ex-value.pdata)
<p id="mark:name1">aaa</p>
<p id="mark:name2">bbb</p>
<p id="mark:name3">ccc</p>
presentation logic (ex-value.plogic)
#name1 {
  value: $user['name'];
}
#name2 {
  Value: $user['name'];
}
#name3 {
  VALUE: $user['name'];
}
compile
$ 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

presentation data (ex-value.pdata)
<p id="mark:name1">aaa</p>
<p id="mark:name2">bbb</p>
<p id="mark:name3">ccc</p>
presentation logic (ex-value.plogic)
#name1 {
  value: user.name;
}
#name2 {
  Value: user.name;
}
#name3 {
  VALUE: user.name;
}
compile
$ 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

presentation data (ex-value.pdata)
<p id="mark:name1">aaa</p>
<p id="mark:name2">bbb</p>
<p id="mark:name3">ccc</p>
presentation logic (ex-value.plogic)
#name1 {
  value: $user{'name'};
}
#name2 {
  Value: $user{'name'};
}
#name3 {
  VALUE: $user{'name'};
}
compile
$ 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

presentation data (ex-stag.pdata)
<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>
presentation logic (ex-stag.plogic)
#link1 {
  stag: start_link_tag :action=>'list';
}
#link2 {
  Stag: start_link_tag :action=>'list';
}
#link3 {
  STAG: start_link_tag :action=>'list';
}
compile
$ 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

presentation data (ex-stag.pdata)
<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>
presentation logic (ex-stag.plogic)
#link1 {
  stag: start_link_tag('member/list');
}
#link2 {
  Stag: start_link_tag('member/list');
}
#link3 {
  STAG: start_link_tag('member/list');
}
compile
$ 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

presentation data (ex-stag.pdata)
<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>
presentation logic (ex-stag.plogic)
#link1 {
  stag: fn:start_link_tag('member', 'list');
}
#link2 {
  Stag: fn:start_link_tag('member', 'list');
}
#link3 {
  STAG: fn:start_link_tag('member', 'list');
}
compile
$ 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

presentation data (ex-stag.pdata)
<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>
presentation logic (ex-stag.plogic)
#link1 {
  stag: start_link_tag('member/list');
}
#link2 {
  Stag: start_link_tag('member/list');
}
#link3 {
  STAG: start_link_tag('member/list');
}
compile
$ 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

presentation data (ex-etag.pdata)
<li id="mark:item1">foo</li>
<li id="mark:item2">bar</li>
<li id="mark:item3">baz</li>
presentation logic (ex-etag.plogic)
#item1 {
  etag: is_xml ? '</li>' : '';
}
#item2 {
  Etag: is_xml ? '</li>' : '';
}
#item3 {
  ETAG: is_xml ? '</li>' : '';
}
compile
$ 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

presentation data (ex-etag.pdata)
<li id="mark:item1">foo</li>
<li id="mark:item2">bar</li>
<li id="mark:item3">baz</li>
presentation logic (ex-etag.plogic)
#item1 {
  etag: $is_xml ? '</li>' : '';
}
#item2 {
  Etag: $is_xml ? '</li>' : '';
}
#item3 {
  ETAG: $is_xml ? '</li>' : '';
}
compile
$ 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

presentation data (ex-etag.pdata)
<li id="mark:item1">foo</li>
<li id="mark:item2">bar</li>
<li id="mark:item3">baz</li>
presentation logic (ex-etag.plogic)
#item1 {
  etag: is_xml ? '</li>' : '';
}
#item2 {
  Etag: is_xml ? '</li>' : '';
}
#item3 {
  ETAG: is_xml ? '</li>' : '';
}
compile
$ 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

presentation data (ex-etag.pdata)
<li id="mark:item1">foo</li>
<li id="mark:item2">bar</li>
<li id="mark:item3">baz</li>
presentation logic (ex-etag.plogic)
#item1 {
  etag: $is_xml ? '</li>' : '';
}
#item2 {
  Etag: $is_xml ? '</li>' : '';
}
#item3 {
  ETAG: $is_xml ? '</li>' : '';
}
compile
$ 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

presentation data (ex-attrs.pdata)
<p id="mark:item" class="para">
  AAA
</p>
presentation logic (ex-attrs.plogic)
#item {
  attrs: 'class' klass,
         'style' style;
}
compile
$ kwartz -l eruby -p ex-attrs.plogic ex-attrs.pdata
<p class="<%= klass %>" style="<%= style %>">
  AAA
</p>

PHP

presentation data (ex-attrs.pdata)
<p id="mark:item" class="para">
  AAA
</p>
presentation logic (ex-attrs.plogic)
#item {
  attrs: 'class' $class,
         'style' $style;
}
compile
$ kwartz -l php -p ex-attrs.plogic ex-attrs.pdata
<p class="<?php echo $class; ?>" style="<?php echo $style; ?>">
  AAA
</p>

JSP

presentation data (ex-attrs.pdata)
<p id="mark:item" class="para">
  AAA
</p>
presentation logic (ex-attrs.plogic)
#item {
  attrs: 'class' klass,
         'style' style;
}
compile
$ 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

presentation data (ex-attrs.pdata)
<p id="mark:item" class="para">
  AAA
</p>
presentation logic (ex-attrs.plogic)
#item {
  attrs: 'class' $class,
         'style' $style;
}
compile
$ 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

presentation data (ex-append.pdata)
<input type="checkboxk" id="mark:remember" value="y">Remeber me
presentation logic (ex-append.plogic)
#remember {
  append: flag ? ' checked' : '';
}
compile
$ kwartz -l eruby -p ex-append.plogic ex-append.pdata
<input type="checkboxk" value="y"<%= flag ? ' checked' : '' %>>Remeber me

PHP

presentation data (ex-append.pdata)
<input type="checkboxk" id="mark:remember" value="y">Remeber me
presentation logic (ex-append.plogic)
#remember {
  append: $flag ? ' checked' : '';
}
compile
$ kwartz -l php -p ex-append.plogic ex-append.pdata
<input type="checkboxk" value="y"<?php echo $flag ? ' checked' : ''; ?>>Remeber me

JSP

presentation data (ex-append.pdata)
<input type="checkboxk" id="mark:remember" value="y">Remeber me
presentation logic (ex-append.plogic)
#remember {
  append: flag ? ' checked' : '';
}
compile
$ 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

presentation data (ex-append.pdata)
<input type="checkboxk" id="mark:remember" value="y">Remeber me
presentation logic (ex-append.plogic)
#remember {
  append: $flag ? ' checked' : '';
}
compile
$ 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

presentation data (ex-remove.pdata)
<p id="foo" class="paragraph" style="color: red">
 AAA
</p>
presentation logic (ex-remove.plogic)
#foo {
  remove: 'id', 'style';
}
compile
$ kwartz -l eruby -p ex-remove.plogic ex-remove.pdata
<p class="paragraph">
 AAA
</p>

PHP

presentation data (ex-remove.pdata)
<p id="foo" class="paragraph" style="color: red">
 AAA
</p>
presentation logic (ex-remove.plogic)
#foo {
  remove: 'id', 'style';
}
compile
$ kwartz -l php -p ex-remove.plogic ex-remove.pdata
<p class="paragraph">
 AAA
</p>

JSP

presentation data (ex-remove.pdata)
<p id="foo" class="paragraph" style="color: red">
 AAA
</p>
presentation logic (ex-remove.plogic)
#foo {
  remove: 'id', 'style';
}
compile
$ 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

presentation data (ex-remove.pdata)
<p id="foo" class="paragraph" style="color: red">
 AAA
</p>
presentation logic (ex-remove.plogic)
#foo {
  remove: 'id', 'style';
}
compile
$ 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

presentation data (ex-logic.pdata)
<ul>
  <li id="mark:items">AAA</li>
</ul>
presentation logic (ex-logic.plogic)
#items {
  value: item;
  logic: {
    @list.each do |item|
      _stag
      _cont
      _etag
    end
  }
}
compile
$ kwartz -l eruby -p ex-logic.plogic ex-logic.pdata
<ul>
<%     @list.each do |item| %>
  <li><%= item %></li>
<%     end %>
</ul>

PHP

presentation data (ex-logic.pdata)
<ul>
  <li id="mark:items">AAA</li>
</ul>
presentation logic (ex-logic.plogic)
#items {
  value: $item;
  logic: {
    foreach ($list as $item) {
      _stag();
      _cont();
      _etag();
    }
  }
}
compile
$ kwartz -l php -p ex-logic.plogic ex-logic.pdata
<ul>
<?php     foreach ($list as $item) { ?>
  <li><?php echo $item; ?></li>
<?php     } ?>
</ul>

JSP

presentation data (ex-logic.pdata)
<ul>
  <li id="mark:items">AAA</li>
</ul>
presentation logic (ex-logic.plogic)
#items {
  value: item;
  logic: {
    <c:forEach var="item" items="${list}">
      _stag();
      _cont();
      _etag();
    </c:forEach>
  }
}
compile
$ 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

presentation data (ex-logic.pdata)
<ul>
  <li id="mark:items">AAA</li>
</ul>
presentation logic (ex-logic.plogic)
#items {
  value: $item;
  logic: {
    foreach ($item in @list) {
      _stag();
      _cont();
      _etag();
    }
  }
}
compile
$ kwartz -l eperl -p ex-logic.plogic ex-logic.pdata
<ul>
<?     foreach ($item in @list) { !>
  <li><?= $item !></li>
<?     } !>
</ul>


before, after

before: and after: property represents the prework and postwork of each element's presentation logics. These properties enables to share or reuse presentation logics.

Ruby

presentation data (ex-before.pdata)
<!-- Groups -->
<ul id="mark:groups">
  <li class="item"></li>
</ul>

<!-- Members -->
<ol id="mark:members">
  <li class="item"></li>
</ol>
presentation logic (ex-before.plogic)
#groups {
  before: {
    list = @groups
  }
  after: {
    group_count = count
  }
}
#members {
  before: {
    list = @members
  }
  after: {
    member_count = count
  }
}

/* common 'logic:' part */
#groups, #members {
  logic: {
    count = 0
    _stag
    for item in list
      unless item.obsolete?
        count += 1
        _cont
      end
    end
    _etag
  }
}

.item {
  value: item.name;
}
compile
$ kwartz -l eruby -p ex-before.plogic ex-before.pdata
<!-- Groups -->
<%     list = @groups %>
<%     count = 0 %>
<ul>
<%     for item in list %>
<%       unless item.obsolete? %>
<%         count += 1 %>
  <li class="item"><%= item.name %></li>
<%       end %>
<%     end %>
</ul>
<%     group_count = count %>

<!-- Members -->
<%     list = @members %>
<%     count = 0 %>
<ol>
<%     for item in list %>
<%       unless item.obsolete? %>
<%         count += 1 %>
  <li class="item"><%= item.name %></li>
<%       end %>
<%     end %>
</ol>
<%     member_count = count %>

PHP

presentation data (ex-before.pdata)
<!-- Groups -->
<ul id="mark:groups">
  <li class="item"></li>
</ul>

<!-- Members -->
<ol id="mark:members">
  <li class="item"></li>
</ol>
presentation logic (ex-before.plogic)
#groups {
  before: {
    $list = $groups;
  }
  after: {
    $group_count = $count;
  }
}
#members {
  before: {
    $list = $members;
  }
  after: {
    $member_count = $count;
  }
}

/* common 'logic:' part */
#groups, #members {
  logic: {
    $count = 0;
    _stag();
    foreach ($list as $item) {
      if (! $item->obsolete) {
        $count++;
        _cont();
      }
    }
    _etag();
  }
}

.item {
  value: $item->name;
}
compile
$ kwartz -l php -p ex-before.plogic ex-before.pdata
<!-- Groups -->
<?php     $list = $groups; ?>
<?php     $count = 0; ?>
<ul>
<?php     foreach ($list as $item) { ?>
<?php       if (! $item->obsolete) { ?>
<?php         $count++; ?>
  <li class="item"><?php echo $item->name; ?></li>
<?php       } ?>
<?php     } ?>
</ul>
<?php     $group_count = $count; ?>

<!-- Members -->
<?php     $list = $members; ?>
<?php     $count = 0; ?>
<ol>
<?php     foreach ($list as $item) { ?>
<?php       if (! $item->obsolete) { ?>
<?php         $count++; ?>
  <li class="item"><?php echo $item->name; ?></li>
<?php       } ?>
<?php     } ?>
</ol>
<?php     $member_count = $count; ?>

JSP

presentation data (ex-before.pdata)
<!-- Groups -->
<ul id="mark:groups">
  <li class="item"></li>
</ul>

<!-- Members -->
<ol id="mark:members">
  <li class="item"></li>
</ol>
presentation logic (ex-before.plogic)
#groups {
  before: {
    <c:set var="list" value="${groups}" />
  }
  after: {
    <c:set var="group_count" value="${count}" />
  }
}
#members {
  before: {
    <c:set var="list" value="${members}" />
  }
  after: {
    <c:set var="members_count" value="${count}" />
  }
}

/* common 'logic:' part */
#groups, #members {
  logic: {
    <c:set var="count" value="${0}" />
    _stag()
    <c:forEach var="item" items="${list}" />
      <c:if test="${not item.obsolete}" />
        <c:set var="count" value="${count+1}" />
        _cont()
      </c:if>
    </c:forEach>
    _etag()
  }
}

.item {
  value: item.name;
}
compile
$ kwartz -l jstl -p ex-before.plogic ex-before.pdata
<%@ taglib prefix="c"  uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<!-- Groups -->
    <c:set var="list" value="${groups}" />
    <c:set var="count" value="${0}" />
<ul>
    <c:forEach var="item" items="${list}" />
      <c:if test="${not item.obsolete}" />
        <c:set var="count" value="${count+1}" />
  <li class="item">${item.name}</li>
      </c:if>
    </c:forEach>
</ul>
    <c:set var="group_count" value="${count}" />

<!-- Members -->
    <c:set var="list" value="${members}" />
    <c:set var="count" value="${0}" />
<ol>
    <c:forEach var="item" items="${list}" />
      <c:if test="${not item.obsolete}" />
        <c:set var="count" value="${count+1}" />
  <li class="item">${item.name}</li>
      </c:if>
    </c:forEach>
</ol>
    <c:set var="members_count" value="${count}" />

Perl

presentation data (ex-before.pdata)
<!-- Groups -->
<ul id="mark:groups">
  <li class="item"></li>
</ul>

<!-- Members -->
<ol id="mark:members">
  <li class="item"></li>
</ol>
presentation logic (ex-before.plogic)
#groups {
  before: {
    @list = @groups;
  }
  after: {
    $group_count = $count;
  }
}
#members {
  before: {
    @list = @members;
  }
  after: {
    $member_count = $count;
  }
}

/* common 'logic:' part */
#groups, #members {
  logic: {
    $count = 0;
    _stag();
    foreach $item (@list) {
      if (! $item['obsolete']) {
        $count++;
        _cont();
      }
    }
    _etag();
  }
}

.item {
  value: $item['name'];
}
compile
$ kwartz -l eperl -p ex-before.plogic ex-before.pdata
<!-- Groups -->
<?     @list = @groups; !>
<?     $count = 0; !>
<ul>
<?     foreach $item (@list) { !>
<?       if (! $item['obsolete']) { !>
<?         $count++; !>
  <li class="item"><?= $item['name'] !></li>
<?       } !>
<?     } !>
</ul>
<?     $group_count = $count; !>

<!-- Members -->
<?     @list = @members; !>
<?     $count = 0; !>
<ol>
<?     foreach $item (@list) { !>
<?       if (! $item['obsolete']) { !>
<?         $count++; !>
  <li class="item"><?= $item['name'] !></li>
<?       } !>
<?     } !>
</ol>
<?     $member_count = $count; !>


begin, end

begin: and end: properties are equal to before: and after:. These are obsolete and leaved for compatibility.

begin: and end: were aimed to add prework and postwork of document, and restricted to be available only with '#DOCUMENT' selector. Currently before: and after: are available with '#DOCUMENT' selector, so you should use these properties instead of begin: and end:.

Ruby

presentation data (ex-begin.pdata)
<p>Hello <span id="mark:username">world</span>!</p>
<ul>
 <li id="mark:menu">menu item</li>
</ul>
presentation logic (ex-begin.plogic)
#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
  }
}
compile
$ 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

presentation data (ex-begin.pdata)
<p>Hello <span id="mark:username">world</span>!</p>
<ul>
 <li id="mark:menu">menu item</li>
</ul>
presentation logic (ex-begin.plogic)
#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();
    }
  }
}
compile
$ 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

presentation data (ex-begin.pdata)
<p>Hello <span id="mark:username">world</span>!</p>
<ul>
 <li id="mark:menu">menu item</li>
</ul>
presentation logic (ex-begin.plogic)
#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>
  }
}
compile
$ 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

presentation data (ex-begin.pdata)
<p>Hello <span id="mark:username">world</span>!</p>
<ul>
 <li id="mark:menu">menu item</li>
</ul>
presentation logic (ex-begin.plogic)
#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();
    }
  }
}
compile
$ 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" !>


Attribute Variable

Attribute variable is a notation such as '$(attrname)' which represents attribute value. Attribute variable allows presentation logic to refer attribute value in presentation data.

Ruby

presentation data (ex-attrvar.pdata)
<form action="create" method="post">
  Username: <input type="text" id="comment_username" size="30"><br>
  Comment: <textarea id="comment_text" rows="3" cols="50"></textarea><br>
  <input id="mark:submit" type="submit" value="Send comment">
</form>
presentation logic (ex-attrvar.plogic)
form {
  stag:  start_form_tag :action=>'$(action)';
}
#comment_username {
  elem:  text_field 'comment', 'username', :size=>$(size);
}
#comment_text {
  elem:  text_area 'comment', 'text', :rows=>$(rows), :cols=>$(cols);
}
#submit {
  elem:  submit_tag '$(value)';
}
compile
$ kwartz -l eruby -p ex-attrvar.plogic ex-attrvar.pdata
<%= start_form_tag :action=>'create' %>
  Username: <%= text_field 'comment', 'username', :size=>30 %><br>
  Comment: <%= text_area 'comment', 'text', :rows=>3, :cols=>50 %><br>
  <%= submit_tag 'Send comment' %>
</form>

PHP

presentation data (ex-attrvar.pdata)
<form action="create" method="post">
  Username: <input type="text" id="comment_username" size="30"><br>
  Comment: <textarea id="comment_text" rows="3" cols="50"></textarea><br>
  <input id="mark:submit" type="submit" value="Send comment">
</form>
presentation logic (ex-attrvar.plogic)
form {
  stag:  form_tag('comment/$(action)');
}
#comment_username {
  elem:  text_field('comment', 'username', array('size'=>$(size)));
}
#comment_text {
  elem:  text_area('comment', 'text', array('rows'=>$(rows), 'cols'=>$(cols)));
}
#submit {
  elem:  submit_tag('$(value)');
}
compile
$ kwartz -l php -p ex-attrvar.plogic ex-attrvar.pdata
<?php echo form_tag('comment/create'); ?>
  Username: <?php echo text_field('comment', 'username', array('size'=>30)); ?><br>
  Comment: <?php echo text_area('comment', 'text', array('rows'=>3, 'cols'=>50)); ?><br>
  <?php echo submit_tag('Send comment'); ?>
</form>

JSP

presentation data (ex-attrvar.pdata)
<form action="create" method="post">
  Username: <input type="text" id="comment_username" size="30"><br>
  Comment: <textarea id="comment_text" rows="3" cols="50"></textarea><br>
  <input id="mark:submit" type="submit" value="Send comment">
</form>
presentation logic (ex-attrvar.plogic)
form {
  logic: {
    <form:form action="$(action).do">
    _cont
    </form:form>
  }
}
#comment_username {
  logic: {
    <form:textfield name="username" size="$(size)"/>
  }
}
#comment_text {
  logic: {
    <form:textarea name="text", rows="$(rows)" cols="$(cols)"/>
  }
}
#submit {
  logic: {
    <form:submit value="$(value)"/>
  }
}
compile
$ kwartz -l jstl -p ex-attrvar.plogic ex-attrvar.pdata
<%@ taglib prefix="c"  uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
    <form:form action="create.do">
  Username:     <form:textfield name="username" size="30"/>
<br>
  Comment:     <form:textarea name="text", rows="3" cols="50"/>
<br>
    <form:submit value="Send comment"/>
    </form:form>

Perl

presentation data (ex-attrvar.pdata)
<form action="create" method="post">
  Username: <input type="text" id="comment_username" size="30"><br>
  Comment: <textarea id="comment_text" rows="3" cols="50"></textarea><br>
  <input id="mark:submit" type="submit" value="Send comment">
</form>
presentation logic (ex-attrvar.plogic)
form {
  stag:  &form_tag({'action'=>'$(action)'});
}
#comment_username {
  elem:  &text_field('comment', 'username', {'size'=>$(size)});
}
#comment_text {
  elem:  &text_area('comment', 'text', {'rows'=>$(rows), 'cols'=>$(cols)});
}
#submit {
  elem:  &submit_tag('$(value)');
}
compile
$ kwartz -l eperl -p ex-attrvar.plogic ex-attrvar.pdata
<?= &form_tag({'action'=>'create'}) !>
  Username: <?= &text_field('comment', 'username', {'size'=>30}) !><br>
  Comment: <?= &text_area('comment', 'text', {'rows'=>3, 'cols'=>50}) !><br>
  <?= &submit_tag('Send comment') !>
</form>



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.

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

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 %>

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; ?>

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"/>

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 !>


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

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>

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>

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>

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>


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

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 %>

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; ?>

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"/>

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 !>


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

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>

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>

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>

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>


value, Value, VALUE

'value', 'Value', and 'VALUE' directives are equivalent to 'cont', 'Cont', and 'CONT' directives respectively.

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>

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>

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>

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>


foreach

'foreach' directive interates element, while 'loop' directive iterates content.

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 %>

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 } ?>

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>

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>
<? } !>


list

'list' directive interates content, while 'foreach' directive iterates element.

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>

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>

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>

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>


Foreach, List

'Foreach' and 'List' directives iterate element or content with loop counter (starting with 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>

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>

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>

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>


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

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>

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>

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>

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>


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

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>

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>

JSP

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

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>


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

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 %>

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 } ?>

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>

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>
<? } !>


set

'set' directive executes any expression.

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>

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>

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>

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>


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

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>

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>

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>

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>


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

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 %>

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 } ?>

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>

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>
<? } !>


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

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\'' : '' %>>

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\'' : ''; ?>>

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\'' : ''}>

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\'' : '' !>>


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

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>

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>

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>

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>


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

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>

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>

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>

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>


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

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>


Language-independent Directive

Some directives can be language-independent.

Language-independent directives are always described with id attribute.

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>

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>

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>

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>



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).