Skip to content
This repository has been archived by the owner on May 8, 2021. It is now read-only.

Commit

Permalink
[Opt_2.1] Bugfixing day.
Browse files Browse the repository at this point in the history
[Opt_2.1] Unit tests from 2.0 version added and prepared for testing backward compatibility.
[Opt_2.1] New unit tests for opt:prolog, opt:dtd, opt:content and opt:repeat
[Opt_2.1] Documentation update process started.
  • Loading branch information
zyxist committed May 16, 2010
1 parent ea5a5ad commit 720b9d9
Show file tree
Hide file tree
Showing 245 changed files with 20,753 additions and 83 deletions.
63 changes: 62 additions & 1 deletion docs/input/en/syntax.attributes.content.txt
Expand Up @@ -16,4 +16,65 @@ If the variable `$article.title` is not defined, we see the text *Default title*
Escaping issues
===============

The attribute value may use the escaping modifiers **e:** and **u:**. The escaped content is used only to display the expression value. The emptiness is checked on the original value.
The attribute value may use the escaping modifiers **e:** and **u:**. The escaped content is used only to display the expression value. The emptiness is checked on the original value.

Prepending and appending some data to the content
=================================================

Consider the following situation:

~~~~
[xml]
<tr>
<td class="title">Estimated time:</td>
<td class="value" opt:content="$time"><em>No time specified</em></td>
</tr>
~~~~

If the time is not specified, the user might want to see an appropriate message. However, let's see what happens if the time is set. We get the following output:

~~~~
[xml]
<tr>
<td class="title">Estimated time:</td>
<td class="value">38</td>
</tr>
~~~~

OPT displayed the value correctly, but it missed the unit which we would like to be displayed, too. In OPT 2.0 we had to write a complete condition here, but fortunately OPT 2.1 introduces extra attributes `opt:content-append` and `opt:content-prepend` that co-operate with `opt:content` and allow to append or prepend some extra stuff on demand:

~~~~
[xml]
<tr>
<td class="title">Estimated time:</td>
<td class="value" opt:content="$time" opt:content-append=" s."><em>No time specified</em></td>
</tr>
~~~~

Now OPT will append the unit, if the time is specified.

> [information]
> By default, `opt:content-prepend` and `opt:content-append` expect strings as their values. In order to read their value from an expression, we must select the parser explicitely: `opt:content-append="parse:$variable"`.

Custom displaying routine
=========================

Let's consider another example:

~~~~
[xml]
<tr>
<td class="title">Date checked:</td>
<td class="value" opt:content="$dateChecked"><em>Not checked yet.</em></td>
</tr>
~~~~

Suppose that the date is provided as an UNIX timestamp (number of seconds since 1.1.1970). In this case, OPT would display us the very number, but we want a formatted date. Since OPT 2.1 we may use `opt:content-display` which provides an expression used to display the matched value:

~~~~
[xml]
<tr>
<td class="title">Date checked:</td>
<td class="value" opt:content="$dateChecked" opt:content-display="date($format, $dateChecked)"><em>Not checked yet.</em></td>
</tr>
~~~~
106 changes: 100 additions & 6 deletions docs/input/en/syntax.instructions.if.txt
@@ -1,4 +1,6 @@
Title: opt:if
SeeAlso:
- syntax.instructions.switch

----
> [warning]
Expand All @@ -20,7 +22,7 @@ Suppose we have a community website where the users can publish notes on various
<h1>{$note.title}</h1>
<p>Date: {$note.date}</p>
<opt:if test="$note.www">
<p><a parse:href="$note.www">Website</a></p>
<p><a href="parse:$note.www">Website</a></p>
</opt:if>
<p>{$note.body}
</div>
Expand All @@ -42,19 +44,19 @@ In the first place, we can see, how to use `opt:if` to test if a variable is set

This text will show, if the condition1 is passed.

<opt:elseif test="condition2">
<opt:else-if test="condition2">
This text will show, if the condition1 fails and condition2 is passed.
</opt:elseif>
<opt:elseif test="condition3">
</opt:else-if>
<opt:else-if test="condition3">
This text will show, if the condition1 and condition2 fail, but condition3 is passed.
</opt:elseif>
</opt:else-if>
<opt:else>
This text will show, if neither of the conditions is passed.
</opt:else>
</opt:if>
~~~~

Note that placing `opt:elseif` and `opt:else` in any tag other than `opt:if` causes an error:
Note that placing `opt:else-if` and `opt:else` in any tag other than `opt:if` causes an error:

~~~~
[xml]
Expand All @@ -75,4 +77,96 @@ Now we might get back to our example and modify it to display a message about th
<p>This is an ordinary note.</p>
</opt:else>
</opt:if>
~~~~

Alternative syntax
==================

OPT 2.1 introduced a new syntax variant for `opt:if`. The primary and alternative conditions are not distinguished and provided as a set of `opt:condition` tags:

~~~~
[xml]
<opt:if>
<opt:condition test="$condition1">The condition 1</opt:condition>
<opt:condition test="$condition2">The condition 2</opt:condition>
<opt:condition test="$condition3">The condition 3</opt:condition>
<opt:else>The final alternative</opt:else>
</opt:if>
~~~~

Long ifs
--------

An unique feature of the new syntax variant and OPT 2.1 in general are so-called **long ifs**. Basically speaking, we can separate two conditions with an ordinary template code that would be always displayed, no matter what condition actually passes.

~~~~
[xml]
<opt:if>
<p>First static content.</p>

<opt:condition test="$condition1">The condition 1</opt:condition>
<opt:condition test="$condition2">The condition 2</opt:condition>

<p>Second static content.</p>

<opt:condition test="$condition3">The condition 3</opt:condition>

<p>Third static content.</p>

<opt:else>The final alternative</opt:else>
</opt:if>
~~~~

If either condition 1 or condition 2 passes, we will see the following result:

~~~~
[xml]
<p>First static content.</p>
The condition 1
<p>Second static content.</p>
<p>Third static content.</p>
~~~~

For third condition, we will see:

~~~~
[xml]
<p>First static content.</p>
<p>Second static content.</p>
The condition 3
<p>Third static content.</p>
~~~~

And for the final alternative:

~~~~
[xml]
<p>First static content.</p>
<p>Second static content.</p>
<p>Third static content.</p>
The final alternative
~~~~

This feature is especially useful for customizing the templates depending on some conditions. Suppose we have two types of users: A and B. On their profile pages, there are some fields that are common, but some other are user-specific. The A-specific fields must be displayed first, then a group of common fields comes in, and finally - the fields of B users:

~~~~
[xml]
<opt:if>
<opt:condition test="$user.type eq 0">
<div class="field">
<p class="title">A-specific field:</p>
<p class="value">{$user.specificValue}</p>
</div>
</opt:condition>
<div class="field">
<p class="title">Common field:</p>
<p class="value">{$user.commonValue}</p>
</div>
<opt:else>
<div class="field">
<p class="title">B-specific field:</p>
<p class="value">{$user.specificValue}</p>
</div>
</opt:else>
</opt:if>
~~~~
8 changes: 8 additions & 0 deletions docs/input/en/syntax.instructions.procedure.txt
@@ -0,0 +1,8 @@
Title: opt:procedure
SeeAlso:
- syntax.instructions.use
- syntax.instructions.snippet

----

Not documented yet.
7 changes: 7 additions & 0 deletions docs/input/en/syntax.instructions.switch.txt
@@ -0,0 +1,7 @@
Title: opt:switch
SeeAlso:
- syntax.instructions.if

----

Not documented yet.

0 comments on commit 720b9d9

Please sign in to comment.