Kwartz-ruby 3.2 Reference Guide

release: $Release$

1   Properties in 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.
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.

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

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

1-1-2   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']; ?>

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

1-1-4   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'} !>

1-2   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.

1-2-1   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>

1-2-2   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>

1-2-3   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>

1-2-4   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>

1-3   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.

1-3-1   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>

1-3-2   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>

1-3-3   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>

1-3-4   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>

1-4   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.

1-4-1   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>

1-4-2   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>

1-4-3   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>

1-4-4   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>

1-5   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.

1-5-1   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>' : '' %>

1-5-2   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>' : ''; ?>

1-5-3   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"/>

1-5-4   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>' : '' !>

1-6   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;
}

1-6-1   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>

1-6-2   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>

1-6-3   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>

1-6-4   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>

1-7   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;
}

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

1-7-2   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

1-7-3   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

1-7-4   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

1-8   remove

remove: property removes attributes.

1-8-1   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>

1-8-2   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>

1-8-3   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>

1-8-4   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>

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

1-9-1   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>

1-9-2   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>

1-9-3   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>

1-9-4   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>

1-10   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.

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

1-10-2   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; ?>

1-10-3   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}" />

1-10-4   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; !>

1-11   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:.

1-11-1   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" %>

1-11-2   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"; ?>

1-11-3   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"/>

1-11-4   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" !>

1-12   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.

1-12-1   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>

1-12-2   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>

1-12-3   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>

1-12-4   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>