Kwartz-ruby 3.0 Reference Guide
1 Pesentation Logic
Presentation logic format in Kwartz is similar to Cascading Style Sheet (CSS).
- Presentation logic file is a set of ruleset.
- Ruleset is a pair of selector and declarations.
- Declaration is a pair of property and value.
plogic ::= ruleset*
ruleset ::= selector '{' [ declaration ';' ]* '}'
selector ::= '#' name
declaration ::= property ':' value
property ::= 'elem' | 'Elem' | 'ELEM'
| 'stag' | 'Stag' | 'STAG'
| 'etag' | 'Etag' | 'ETAG'
| 'cont' | 'Cont' | 'CONT'
| 'value' | 'Value' | 'VALUE'
| 'attrs' | 'Attrs' | 'ATTRS'
| 'append' | 'Append' | 'APPEND'
| 'remove'
| 'logic'
Notice that the tail semicolon of declaration is not omittable.
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
<p id="mark:name1">aaa</p> <p id="mark:name2">bbb</p> <p id="mark:name3">ccc</p>
#name1 {
elem: user[:name];
}
#name2 {
Elem: user[:name];
}
#name3 {
ELEM: user[:name];
}
$ kwartz -l eruby -p ex-elem.plogic ex-elem.pdata <%= user[:name] %> <%=h user[:name] %> <%= user[:name] %>
1-1-2 PHP
<p id="mark:name1">aaa</p> <p id="mark:name2">bbb</p> <p id="mark:name3">ccc</p>
#name1 {
elem: $user['name'];
}
#name2 {
Elem: $user['name'];
}
#name3 {
ELEM: $user['name'];
}
$ kwartz -l php -p ex-elem.plogic ex-elem.pdata <?php echo $user['name']; ?> <?php echo htmlspecialchars($user['name']); ?> <?php echo $user['name']; ?>
1-1-3 JSP
<p id="mark:name1">aaa</p> <p id="mark:name2">bbb</p> <p id="mark:name3">ccc</p>
#name1 {
elem: user.name;
}
#name2 {
Elem: user.name;
}
#name3 {
ELEM: user.name;
}
$ kwartz -l jstl -p ex-elem.plogic ex-elem.pdata
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
${user.name}
${user.name}
<c:out value="${user.name}" escapeXml="false"/>
1-1-4 Perl
<p id="mark:name1">aaa</p> <p id="mark:name2">bbb</p> <p id="mark:name3">ccc</p>
#name1 {
elem: $user{'name'};
}
#name2 {
Elem: $user{'name'};
}
#name3 {
ELEM: $user{'name'};
}
$ kwartz -l eperl -p ex-elem.plogic ex-elem.pdata
<?= $user{'name'} !>
<?= encode_entities($user{'name'}) !>
<?= $user{'name'} !>
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
<p id="mark:name1">aaa</p> <p id="mark:name2">bbb</p> <p id="mark:name3">ccc</p>
#name1 {
cont: user[:name];
}
#name2 {
Cont: user[:name];
}
#name3 {
CONT: user[:name];
}
$ kwartz -l eruby -p ex-cont.plogic ex-cont.pdata <p><%= user[:name] %></p> <p><%=h user[:name] %></p> <p><%= user[:name] %></p>
1-2-2 PHP
<p id="mark:name1">aaa</p> <p id="mark:name2">bbb</p> <p id="mark:name3">ccc</p>
#name1 {
cont: $user['name'];
}
#name2 {
Cont: $user['name'];
}
#name3 {
CONT: $user['name'];
}
$ kwartz -l php -p ex-cont.plogic ex-cont.pdata <p><?php echo $user['name']; ?></p> <p><?php echo htmlspecialchars($user['name']); ?></p> <p><?php echo $user['name']; ?></p>
1-2-3 JSP
<p id="mark:name1">aaa</p> <p id="mark:name2">bbb</p> <p id="mark:name3">ccc</p>
#name1 {
cont: user.name;
}
#name2 {
Cont: user.name;
}
#name3 {
CONT: user.name;
}
$ kwartz -l jstl -p ex-cont.plogic ex-cont.pdata
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<p>${user.name}</p>
<p>${user.name}</p>
<p><c:out value="${user.name}" escapeXml="false"/></p>
1-2-4 Perl
<p id="mark:name1">aaa</p> <p id="mark:name2">bbb</p> <p id="mark:name3">ccc</p>
#name1 {
cont: $user{'name'};
}
#name2 {
Cont: $user{'name'};
}
#name3 {
CONT: $user{'name'};
}
$ kwartz -l eperl -p ex-cont.plogic ex-cont.pdata
<p><?= $user{'name'} !></p>
<p><?= encode_entities($user{'name'}) !></p>
<p><?= $user{'name'} !></p>
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
<p id="mark:name1">aaa</p> <p id="mark:name2">bbb</p> <p id="mark:name3">ccc</p>
#name1 {
value: user[:name];
}
#name2 {
Value: user[:name];
}
#name3 {
VALUE: user[:name];
}
$ kwartz -l eruby -p ex-value.plogic ex-value.pdata <p><%= user[:name] %></p> <p><%=h user[:name] %></p> <p><%= user[:name] %></p>
1-3-2 PHP
<p id="mark:name1">aaa</p> <p id="mark:name2">bbb</p> <p id="mark:name3">ccc</p>
#name1 {
value: $user['name'];
}
#name2 {
Value: $user['name'];
}
#name3 {
VALUE: $user['name'];
}
$ kwartz -l php -p ex-value.plogic ex-value.pdata <p><?php echo $user['name']; ?></p> <p><?php echo htmlspecialchars($user['name']); ?></p> <p><?php echo $user['name']; ?></p>
1-3-3 JSP
<p id="mark:name1">aaa</p> <p id="mark:name2">bbb</p> <p id="mark:name3">ccc</p>
#name1 {
value: user.name;
}
#name2 {
Value: user.name;
}
#name3 {
VALUE: user.name;
}
$ kwartz -l jstl -p ex-value.plogic ex-value.pdata
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<p>${user.name}</p>
<p>${user.name}</p>
<p><c:out value="${user.name}" escapeXml="false"/></p>
1-3-4 Perl
<p id="mark:name1">aaa</p> <p id="mark:name2">bbb</p> <p id="mark:name3">ccc</p>
#name1 {
value: $user{'name'};
}
#name2 {
Value: $user{'name'};
}
#name3 {
VALUE: $user{'name'};
}
$ kwartz -l eperl -p ex-value.plogic ex-value.pdata
<p><?= $user{'name'} !></p>
<p><?= encode_entities($user{'name'}) !></p>
<p><?= $user{'name'} !></p>
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
<a href="#" id="mark:link1"><img src="button1.png"></a> <a href="#" id="mark:link2"><img src="button2.png"></a> <a href="#" id="mark:link3"><img src="button3.png"></a>
#link1 {
stag: start_link_tag :action=>'list';
}
#link2 {
Stag: start_link_tag :action=>'list';
}
#link3 {
STAG: start_link_tag :action=>'list';
}
$ kwartz -l eruby -p ex-stag.plogic ex-stag.pdata <%= start_link_tag :action=>'list' %><img src="button1.png"></a> <%=h start_link_tag :action=>'list' %><img src="button2.png"></a> <%= start_link_tag :action=>'list' %><img src="button3.png"></a>
1-4-2 PHP
<a href="#" id="mark:link1"><img src="button1.png"></a> <a href="#" id="mark:link2"><img src="button2.png"></a> <a href="#" id="mark:link3"><img src="button3.png"></a>
#link1 {
stag: start_link_tag('member/list');
}
#link2 {
Stag: start_link_tag('member/list');
}
#link3 {
STAG: start_link_tag('member/list');
}
$ kwartz -l php -p ex-stag.plogic ex-stag.pdata
<?php echo start_link_tag('member/list'); ?><img src="button1.png"></a>
<?php echo htmlspecialchars(start_link_tag('member/list')); ?><img src="button2.png"></a>
<?php echo start_link_tag('member/list'); ?><img src="button3.png"></a>
1-4-3 JSP
<a href="#" id="mark:link1"><img src="button1.png"></a> <a href="#" id="mark:link2"><img src="button2.png"></a> <a href="#" id="mark:link3"><img src="button3.png"></a>
#link1 {
stag: fn:start_link_tag('member', 'list');
}
#link2 {
Stag: fn:start_link_tag('member', 'list');
}
#link3 {
STAG: fn:start_link_tag('member', 'list');
}
$ kwartz -l jstl -p ex-stag.plogic ex-stag.pdata
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
${fn:start_link_tag('member', 'list')}<img src="button1.png"></a>
${fn:start_link_tag('member', 'list')}<img src="button2.png"></a>
<c:out value="${fn:start_link_tag('member', 'list')}" escapeXml="false"/><img src="button3.png"></a>
1-4-4 Perl
<a href="#" id="mark:link1"><img src="button1.png"></a> <a href="#" id="mark:link2"><img src="button2.png"></a> <a href="#" id="mark:link3"><img src="button3.png"></a>
#link1 {
stag: start_link_tag('member/list');
}
#link2 {
Stag: start_link_tag('member/list');
}
#link3 {
STAG: start_link_tag('member/list');
}
$ kwartz -l eperl -p ex-stag.plogic ex-stag.pdata
<?= start_link_tag('member/list') !><img src="button1.png"></a>
<?= encode_entities(start_link_tag('member/list')) !><img src="button2.png"></a>
<?= start_link_tag('member/list') !><img src="button3.png"></a>
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
<li id="mark:item1">foo</li> <li id="mark:item2">bar</li> <li id="mark:item3">baz</li>
#item1 {
etag: is_xml ? '</li>' : '';
}
#item2 {
Etag: is_xml ? '</li>' : '';
}
#item3 {
ETAG: is_xml ? '</li>' : '';
}
$ kwartz -l eruby -p ex-etag.plogic ex-etag.pdata <li>foo<%= is_xml ? '</li>' : '' %> <li>bar<%=h is_xml ? '</li>' : '' %> <li>baz<%= is_xml ? '</li>' : '' %>
1-5-2 PHP
<li id="mark:item1">foo</li> <li id="mark:item2">bar</li> <li id="mark:item3">baz</li>
#item1 {
etag: $is_xml ? '</li>' : '';
}
#item2 {
Etag: $is_xml ? '</li>' : '';
}
#item3 {
ETAG: $is_xml ? '</li>' : '';
}
$ kwartz -l php -p ex-etag.plogic ex-etag.pdata <li>foo<?php echo $is_xml ? '</li>' : ''; ?> <li>bar<?php echo htmlspecialchars($is_xml ? '</li>' : ''); ?> <li>baz<?php echo $is_xml ? '</li>' : ''; ?>
1-5-3 JSP
<li id="mark:item1">foo</li> <li id="mark:item2">bar</li> <li id="mark:item3">baz</li>
#item1 {
etag: is_xml ? '</li>' : '';
}
#item2 {
Etag: is_xml ? '</li>' : '';
}
#item3 {
ETAG: is_xml ? '</li>' : '';
}
$ kwartz -l jstl -p ex-etag.plogic ex-etag.pdata
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<li>foo${is_xml ? '</li>' : ''}
<li>bar${is_xml ? '</li>' : ''}
<li>baz<c:out value="${is_xml ? '</li>' : ''}" escapeXml="false"/>
1-5-4 Perl
<li id="mark:item1">foo</li> <li id="mark:item2">bar</li> <li id="mark:item3">baz</li>
#item1 {
etag: $is_xml ? '</li>' : '';
}
#item2 {
Etag: $is_xml ? '</li>' : '';
}
#item3 {
ETAG: $is_xml ? '</li>' : '';
}
$ kwartz -l eperl -p ex-etag.plogic ex-etag.pdata <li>foo<?= $is_xml ? '</li>' : '' !> <li>bar<?= encode_entities($is_xml ? '</li>' : '') !> <li>baz<?= $is_xml ? '</li>' : '' !>
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
<p id="mark:item" class="para"> AAA </p>
#item {
attrs: 'class' klass,
'style' style;
}
$ kwartz -l eruby -p ex-attrs.plogic ex-attrs.pdata <p class="<%= klass %>" style="<%= style %>"> AAA </p>
1-6-2 PHP
<p id="mark:item" class="para"> AAA </p>
#item {
attrs: 'class' $class,
'style' $style;
}
$ kwartz -l php -p ex-attrs.plogic ex-attrs.pdata <p class="<?php echo $class; ?>" style="<?php echo $style; ?>"> AAA </p>
1-6-3 JSP
<p id="mark:item" class="para"> AAA </p>
#item {
attrs: 'class' klass,
'style' style;
}
$ kwartz -l jstl -p ex-attrs.plogic ex-attrs.pdata
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<p class="${klass}" style="${style}">
AAA
</p>
1-6-4 Perl
<p id="mark:item" class="para"> AAA </p>
#item {
attrs: 'class' $class,
'style' $style;
}
$ kwartz -l eperl -p ex-attrs.plogic ex-attrs.pdata <p class="<?= $class !>" style="<?= $style !>"> AAA </p>
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
<input type="checkboxk" id="mark:remember" value="y">Remeber me
#remember {
append: flag ? ' checked' : '';
}
$ kwartz -l eruby -p ex-append.plogic ex-append.pdata <input type="checkboxk" value="y"<%= flag ? ' checked' : '' %>>Remeber me
1-7-2 PHP
<input type="checkboxk" id="mark:remember" value="y">Remeber me
#remember {
append: $flag ? ' checked' : '';
}
$ kwartz -l php -p ex-append.plogic ex-append.pdata <input type="checkboxk" value="y"<?php echo $flag ? ' checked' : ''; ?>>Remeber me
1-7-3 JSP
<input type="checkboxk" id="mark:remember" value="y">Remeber me
#remember {
append: flag ? ' checked' : '';
}
$ kwartz -l jstl -p ex-append.plogic ex-append.pdata
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<input type="checkboxk" value="y"${flag ? ' checked' : ''}>Remeber me
1-7-4 Perl
<input type="checkboxk" id="mark:remember" value="y">Remeber me
#remember {
append: $flag ? ' checked' : '';
}
$ kwartz -l eperl -p ex-append.plogic ex-append.pdata <input type="checkboxk" value="y"<?= $flag ? ' checked' : '' !>>Remeber me
1-8 remove
remove: property removes attributes.
1-8-1 Ruby
<p id="foo" class="paragraph" style="color: red"> AAA </p>
#foo {
remove: 'id', 'style';
}
$ kwartz -l eruby -p ex-remove.plogic ex-remove.pdata <p class="paragraph"> AAA </p>
1-8-2 PHP
<p id="foo" class="paragraph" style="color: red"> AAA </p>
#foo {
remove: 'id', 'style';
}
$ kwartz -l php -p ex-remove.plogic ex-remove.pdata <p class="paragraph"> AAA </p>
1-8-3 JSP
<p id="foo" class="paragraph" style="color: red"> AAA </p>
#foo {
remove: 'id', 'style';
}
$ kwartz -l jstl -p ex-remove.plogic ex-remove.pdata <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> <p class="paragraph"> AAA </p>
1-8-4 Perl
<p id="foo" class="paragraph" style="color: red"> AAA </p>
#foo {
remove: 'id', 'style';
}
$ kwartz -l eperl -p ex-remove.plogic ex-remove.pdata <p class="paragraph"> AAA </p>
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
<ul> <li id="mark:items">AAA</li> </ul>
#items {
value: item;
logic: {
@list.each do |item|
_stag
_cont
_etag
end
}
}
$ kwartz -l eruby -p ex-logic.plogic ex-logic.pdata <ul> <% @list.each do |item| %> <li><%= item %></li> <% end %> </ul>
1-9-2 PHP
<ul> <li id="mark:items">AAA</li> </ul>
#items {
value: $item;
logic: {
foreach ($list as $item) {
_stag();
_cont();
_etag();
}
}
}
$ kwartz -l php -p ex-logic.plogic ex-logic.pdata
<ul>
<?php foreach ($list as $item) { ?>
<li><?php echo $item; ?></li>
<?php } ?>
</ul>
1-9-3 JSP
<ul> <li id="mark:items">AAA</li> </ul>
#items {
value: item;
logic: {
<c:forEach var="item" items="${list}">
_stag();
_cont();
_etag();
</c:forEach>
}
}
$ kwartz -l jstl -p ex-logic.plogic ex-logic.pdata
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<ul>
<c:forEach var="item" items="${list}">
<li>${item}</li>
</c:forEach>
</ul>
1-9-4 Perl
<ul> <li id="mark:items">AAA</li> </ul>
#items {
value: $item;
logic: {
foreach ($item in @list) {
_stag();
_cont();
_etag();
}
}
}
$ kwartz -l eperl -p ex-logic.plogic ex-logic.pdata
<ul>
<? foreach ($item in @list) { !>
<li><?= $item !></li>
<? } !>
</ul>
1-10 begin, end
begin: and end: property represents the prework and postwork
of document respectively.
These properties takes target code block and are available only with
'#DOCUMENT' selector.
1-10-1 Ruby
<p>Hello <span id="mark:username">world</span>!</p> <ul> <li id="mark:menu">menu item</li> </ul>
#DOCUMENT {
begin: {
username = @context[:username]
menulist = @context[:menulist]
}
end: {
print "<!-- document end -->\n"
}
}
#username {
value: username;
}
#menu {
value: menu;
logic: {
for menu in menulist
_elem
end
}
}
$ kwartz -l eruby -p ex-begin.plogic ex-begin.pdata <% username = @context[:username] %> <% menulist = @context[:menulist] %> <p>Hello <span><%= username %></span>!</p> <ul> <% for menu in menulist %> <li><%= menu %></li> <% end %> </ul> <%= "<!-- document end -->\n" %>
1-10-2 PHP
<p>Hello <span id="mark:username">world</span>!</p> <ul> <li id="mark:menu">menu item</li> </ul>
#DOCUMENT {
begin: {
$username = $context['username'];
$menulist = $context['menulist'];
}
end: {
print("<!-- document end -->\n");
}
}
#username {
value: $username;
}
#menu {
value: $menu;
logic: {
foreach ($menulist as $menu) {
_elem();
}
}
}
$ kwartz -l php -p ex-begin.plogic ex-begin.pdata
<?php $username = $context['username']; ?>
<?php $menulist = $context['menulist']; ?>
<p>Hello <span><?php echo $username; ?></span>!</p>
<ul>
<?php foreach ($menulist as $menu) { ?>
<li><?php echo $menu; ?></li>
<?php } ?>
</ul>
<?php echo "<!-- document end -->\n"; ?>
1-10-3 JSP
<p>Hello <span id="mark:username">world</span>!</p> <ul> <li id="mark:menu">menu item</li> </ul>
#DOCUMENT {
begin: {
<c:set var="username" value="${context.username}"/>
<c:set var="menulist" value="${context.menulist}"/>
}
end: {
<c:out value="<!-- document end -->\n"/>
}
}
#username {
value: username;
}
#menu {
value: menu;
logic: {
<c:forEach var="menu" items="${menulist}">
_elem();
</c:forEach>
}
}
$ kwartz -l jstl -p ex-begin.plogic ex-begin.pdata
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<c:set var="username" value="${context.username}"/>
<c:set var="menulist" value="${context.menulist}"/>
<p>Hello <span>${username}</span>!</p>
<ul>
<c:forEach var="menu" items="${menulist}">
<li>${menu}</li>
</c:forEach>
</ul>
<c:out value="<!-- document end -->\n"/>
1-10-4 Perl
<p>Hello <span id="mark:username">world</span>!</p> <ul> <li id="mark:menu">menu item</li> </ul>
#DOCUMENT {
begin: {
$username = $context{'username'};
@menulist = $context{'menulist'};
}
end: {
print("<!-- document end -->\n");
}
}
#username {
value: $username;
}
#menu {
value: $menu;
logic: {
foreach ($menu in @menulist) {
_elem();
}
}
}
$ kwartz -l eperl -p ex-begin.plogic ex-begin.pdata
<? $username = $context{'username'}; !>
<? @menulist = $context{'menulist'}; !>
<p>Hello <span><?= $username !></span>!</p>
<ul>
<? foreach ($menu in @menulist) { !>
<li><?= $menu !></li>
<? } !>
</ul>
<?= "<!-- document end -->\n" !>