<?xml version="1.0" encoding="utf-8"?><?xml-stylesheet title="XSL formatting" type="text/xsl" href="http://blog.invenzzia.org/en/feed/rss2/xslt" ?><rss version="2.0"
  xmlns:dc="http://purl.org/dc/elements/1.1/"
  xmlns:wfw="http://wellformedweb.org/CommentAPI/"
  xmlns:content="http://purl.org/rss/1.0/modules/content/"
  xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
  <title>Invenzzia... in English - Open Power Template</title>
  <link>http://blog.invenzzia.org/en/</link>
  <atom:link href="http://blog.invenzzia.org/en/feed/category/Open-Power-Template/rss2" rel="self" type="application/rss+xml"/>
  <description></description>
  <language>en</language>
  <pubDate>Fri, 09 Jul 2010 05:49:14 +0100</pubDate>
  <copyright>Copyright &amp;copy; Invenzzia</copyright>
  <docs>http://blogs.law.harvard.edu/tech/rss</docs>
  <generator>Dotclear</generator>
  
    
  <item>
    <title>New expression parser for OPT 2.1</title>
    <link>http://blog.invenzzia.org/en/post/New-expression-parser-for-OPT-2.1</link>
    <guid isPermaLink="false">urn:md5:2fc0e976d9a2378f1cb10656c3c10341</guid>
    <pubDate>Sat, 23 Jan 2010 13:00:00 +0100</pubDate>
    <dc:creator>Zyx</dc:creator>
        <category>Open Power Template</category>
        <category>development</category><category>OPT2</category>    
    <description>&lt;p&gt;The incoming Open Power Template 2.1 will have a new, more powerful expression parser. Basically speaking, expressions are those pieces of language that evaluate something, producing a value, i.e. variables and operators. Both OPT 1.1 and 2.0 use a nice, manually-written parser that compiles them to a PHP code, validating their syntax and performing some extra transformations. While it works well, I think I reached the end of possible ways to extend it. It would be simply too complicated to implement new features to it, so I decided I must rewrite it into a formal grammar. Today, the main works on it are finished.&lt;/p&gt;    &lt;h2&gt;Formal grammars&lt;/h2&gt;


&lt;p&gt;The new expression parser is defined using a formal grammar. It is a set of rules describing, how the tokens, the smallest units of the language, can be connected to produce something useful. In the example below, we have produced a simple grammar that allows adding and multiplying numbers:&lt;/p&gt;

&lt;pre&gt;
expr -&amp;gt; expr PLUS expr
expr -&amp;gt; expr MUL expr
expr -&amp;gt; LEFT_PARENTHESIS expr RIGHT_PARENTHESIS
expr -&amp;gt; NUMBER
&lt;/pre&gt;


&lt;p&gt;Of course we have to define the operator precedence to make it fully correct, but the basic idea is simple. We write a set of rules (called 'productions') saying, how to produce the more and more complex parts of the expressions from the smallest units. For a number of grammar classes, there are computer algorithms that are able to produce a complete parser code for them, and the most popular one for programming languages is called LALR(1). Now all we have to do is to write the grammar in the format accepted by the parser generator and simply run it to produce a ready-to-use code.&lt;/p&gt;


&lt;p&gt;For Open Power Template, I chose &lt;em&gt;PHP Parser Generator&lt;/em&gt;, a clone of Lemon parser generator rewritten from C to PHP. The same stuff is used by the guys that develop Smarty 3, but they have applied it to parse the whole template. In case of OPT it is not necessary, as it uses an ordinary XML parser. Below, you can see a part of the grammar file that defines function calls:&lt;/p&gt;

&lt;pre&gt;
calculated(res)		::= function_call(fc).		{	res = fc;	}
calculated(res)		::= method_call(oc).	{	res = oc;	}

function_call(res)	::= functional(fun).		{	res = $this-&amp;gt;_expr-&amp;gt;_makeFunction(fun);	}

functional(f)	::= IDENTIFIER(s) L_BRACKET argument_list(a) R_BRACKET.	{	f = $this-&amp;gt;_expr-&amp;gt;_makeFunctional(s, a); }
functional(f)	::= IDENTIFIER(s) L_BRACKET container_def(a) R_BRACKET.	{	f = $this-&amp;gt;_expr-&amp;gt;_makeFunctional(s, array($this-&amp;gt;_expr-&amp;gt;_containerValue(a, Opt_Expression_Standard::CONTAINER_WEIGHT)));	}
functional(f)	::= IDENTIFIER(s) L_BRACKET R_BRACKET.	{	f = $this-&amp;gt;_expr-&amp;gt;_makeFunctional(s, array()); }
&lt;/pre&gt;


&lt;p&gt;As you can see, for each production we can define a PHP code snippet that may perform some action, if the specified sequence of symbols is found. This eases the process of defining a language very much.&lt;/p&gt;


&lt;h2&gt;New features of the OPT expression language&lt;/h2&gt;


&lt;p&gt;The new parser allowed me to implement lots of new and useful stuff. The most lacking feature in OPT 2.0 was the inability to create a container in a template, like arrays in PHP. We could not write:&lt;/p&gt;

&lt;pre&gt;
{url(container('controller' =&amp;gt; 'foo', 'action' =&amp;gt; 'bar'))}
&lt;/pre&gt;


&lt;p&gt;The routing path must have been defined either in a script or saved as a string. In OPT 2.1 this limitation is finally removed. We can create new containers dynamically, using a convenient syntax designed for using within XML documents:&lt;/p&gt;

&lt;pre&gt;xml
{url( [ 'controller': 'foo', 'action': 'bar'] )}
{url('controller': 'foo', 'action': 'bar')}
&lt;/pre&gt;


&lt;p&gt;The shortened version (syntactic sugar) for functions is also possible, as we can see. The two lines above do exactly the same thing. The container call syntax was also extended. Now it is possible to select the container index dynamically:&lt;/p&gt;

&lt;pre&gt;
$container.($index).foo
&lt;/pre&gt;


&lt;p&gt;However, you should be aware that some data formats may not support it and it will not always work.&lt;/p&gt;


&lt;p&gt;A lot of effort has been made to develop new operators which you should find very comfortable and convenient, especially with the longer expressions:&lt;/p&gt;

&lt;pre&gt;
$number is between 5 and 10
$number is not between 5 and 10
$number is either 5 or 10
$number is neither 5 nor 10

$container contains 'foo'
$container contains either 'foo' or 'bar'
$container contains neither 'foo' nor 'bar'
$container contains both 'foo' and 'bar'

'foo' is in $container
'foo' is not in $container
'foo' is either in $foo or $bar
'foo' is neither in $foo nor $bar
'foo' is both in $foo and $bar
&lt;/pre&gt;


&lt;p&gt;The first group of operators is a shortened form for expressions like &lt;code&gt;$number &amp;gt; 5 and $number &amp;lt; 10&lt;/code&gt;. The second grup tests the contents of containers, allowing to check if they contain one or more specified values. In the last group, the situation is reversed: we check if the element exists in one or more containers. The advantage of the new operators is that they will be able to be reprogrammed with data formats, hiding even more implementation details from the template designer and improving the template portability.&lt;/p&gt;


&lt;p&gt;There is only one feature removed. In OPT 2.0 it is possible to write &lt;code&gt;eq eq eq&lt;/code&gt; and the parser correctly recognizes, which &quot;eq&quot; is an operator and which is a string. Unfortunately, such trick is not possible with ordinary LALR(1) grammars so I was forced not to implement it in order not to produce a mess.&lt;/p&gt;


&lt;p&gt;The last change concerning the expressions is that the direct access to PHP arrays and objects is disabled by default: &lt;code&gt;$foo&lt;a href=&quot;http://blog.invenzzia.org/en/post/&amp;#039;bar&amp;#039;&quot; title=&quot;&amp;#039;bar&amp;#039;&quot;&gt;'bar'&lt;/a&gt;&lt;/code&gt;, &lt;code&gt;$foo::field&lt;/code&gt;. Using them instead of containers and data formats is considered as a bad programming practice in OPT, and reduces the template portability. The idea is to encourage the programmers to learn what containers are and why they are better in templates than PHP objects and arrays.&lt;/p&gt;


&lt;h2&gt;Conclusion&lt;/h2&gt;


&lt;p&gt;There is still a lot of work to do in Open Power Template 2.1. I hope that after the exams at university I will find more time to finish it. Anyway, I'll do my best to make OPT 2.1 the best template engine ever.&lt;/p&gt;</description>
    
    
    
          <comments>http://blog.invenzzia.org/en/post/New-expression-parser-for-OPT-2.1#comment-form</comments>
      <wfw:comment>http://blog.invenzzia.org/en/post/New-expression-parser-for-OPT-2.1#comment-form</wfw:comment>
      <wfw:commentRss>http://blog.invenzzia.org/en/feed/atom/comments/68</wfw:commentRss>
      </item>
    
  <item>
    <title>Open Power Template 2.1 - a closer look</title>
    <link>http://blog.invenzzia.org/en/post/Open-Power-Template-2.1-a-closer-look</link>
    <guid isPermaLink="false">urn:md5:8cfef02a12162ffb7f184b0fa071f383</guid>
    <pubDate>Sat, 28 Nov 2009 11:35:00 +0100</pubDate>
    <dc:creator>Zyx</dc:creator>
        <category>Open Power Template</category>
        <category>development</category><category>OPL</category><category>OPT2</category>    
    <description>&lt;p&gt;In this note, I would like to show some new features of the incoming Open Power Template 2.1. The new branch, which is currently under development, will bring many new tools and improvements to the template language syntax and the library API. Some of them are already implemented, but there is still a lot of work to do. It is hard to say when it is going to be released, but I'll do my best, so that you would not have to wait another year for it.&lt;/p&gt;    &lt;h2&gt;Reasons for the changes&lt;/h2&gt;


&lt;p&gt;From the technical point of view, OPT is a pioneer project. Many features were never implemented in any existing template engine and at the first time it was sometimes hard to say what potential they actually offer. We were learning the library during the development process. Unfortunately, the improvements could not be invented and applied forever. One day we had to stop and say: `OK, now it is the time to make it stable'. The result is quite satisfactory, but the list of the things that could be done better was getting longer and longer. Some of the features were suggested by the users, the rest comes from us. OPT 2.1 is going to be the next step in the template engine evolution.&lt;/p&gt;


&lt;h2&gt;Compiler changes&lt;/h2&gt;


&lt;p&gt;In OPT 2.1, the compiler becomes a universal framework for implementing template languages, primarily based on XML. It provides the compilation process structure, interfaces and ports for many features, such as data formats. However, the details of the syntax processing are moved to external parts:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Custom parsers - their task is to parse the template source code and construct an Abstract Syntax Tree (AST).&lt;/li&gt;
&lt;li&gt;Custom AST nodes - currently, the AST nodes match the specific OPT-XML needs and it is impossible to write new ones without changing the compiler code. In OPT 2.1 it becomes possible.&lt;/li&gt;
&lt;li&gt;Custom expression parsers - they parse expressions such as &lt;code&gt;$a+$b&lt;/code&gt;. Since OPT 2.1 it will be possible to write new ones.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In other words, OPT is going to bring the compilation structure, whereas the programmer matches it to his or her needs. Personally, I hope that someone will use it and port &lt;em&gt;Template Attribute Language&lt;/em&gt; to OPT. However, most programmers will not be interested in the details of compilation process, but rather the default language it offers. Here, OPT 2.1 language will be very similar to the current language. It will be just ported to the new API.&lt;/p&gt;


&lt;h2&gt;New parsers&lt;/h2&gt;


&lt;p&gt;By default, OPT 2.1 will offer three parsers that could be used by the programmers. They will replace the current `compiler modes':&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;XML&lt;/strong&gt; - completely new parser based on the XMLReader extension. Its primary feature is 100% sure full compatibility with XML standards, including such details, as &lt;code&gt;xmlns&lt;/code&gt; attribute. However, the parser cannot be scaled to ignore some syntax requirements.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;HTML&lt;/strong&gt; - the current parser, customizable with many options.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Quirks&lt;/strong&gt; - the quirks mode parser.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;New dynamic attribute value syntax&lt;/h2&gt;

&lt;p&gt;As OPT is based on XML, there occurs a problem, how to put an expression value into an attribute. In the early development stage, we decided to make use of namespaces to indicate the attributes which have dynamic values. The life shown that it was not the best idea. It is not scalable and causes problems, if the attribute already contains a namespace. Redesigning this feature from scratch was one of our priorities. In OPT 2.1, the value type will be encoded in the attribute value, not in the name. It is illustrated by the following examples:&lt;/p&gt;

&lt;pre&gt;
&amp;lt;p class=&amp;quot;text&amp;quot;&amp;gt;Static attribute value: text&amp;lt;/p&amp;gt;
&amp;lt;p class=&amp;quot;parse:$text&amp;quot;&amp;gt;Dynamic attribute value read from a variable&amp;lt;/p&amp;gt;
&amp;lt;p class=&amp;quot;null:parse:tekst&amp;quot;&amp;gt;Static attribute value: parse:text&amp;lt;/p&amp;gt;
&lt;/pre&gt;


&lt;p&gt;It can be also used to select the custom expression syntax:&lt;/p&gt;

&lt;pre&gt;
&amp;lt;p class=&amp;quot;foo:##mysteriousSyntax&amp;quot;&amp;gt;text&amp;lt;/p&amp;gt;
&lt;/pre&gt;


&lt;p&gt;And in curly brackets, too:&lt;/p&gt;

&lt;pre&gt;
&amp;lt;p&amp;gt;Mysterious syntax: {foo:##mysteriousSyntax}&amp;lt;/p&amp;gt;
&amp;lt;p&amp;gt;A bit nonsense example (&amp;quot;parse&amp;quot; is the default): {parse:$variable}&amp;lt;/p&amp;gt;
&amp;lt;p&amp;gt;Even more nonsense example, but still possible: {str:$variable}&amp;lt;/p&amp;gt;
&lt;/pre&gt;


&lt;p&gt;And in instruction attributes:&lt;/p&gt;

&lt;pre&gt;
&amp;lt;opt:include file=&amp;quot;parse:$file&amp;quot; /&amp;gt;
&amp;lt;opt:attribute name=&amp;quot;str:theName&amp;quot; value=&amp;quot;str:value&amp;quot; /&amp;gt;
&lt;/pre&gt;


&lt;h2&gt;Extended expression modifiers&lt;/h2&gt;


&lt;p&gt;In OPT 2.0, there were two hardcoded modifiers used for the HTML escaping control: &lt;strong&gt;e:&lt;/strong&gt; and &lt;strong&gt;u:&lt;/strong&gt; used as follows: &lt;code&gt;{e:$expression}&lt;/code&gt;. Since OPT 2.1, it will be possible to create custom modifiers and use them in the attributes. Furthermore, there will be three predefined modifiers that could be overwritten:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;To enable the escaping (by default &lt;strong&gt;e:&lt;/strong&gt;)&lt;/li&gt;
&lt;li&gt;To disable the escaping (by default &lt;strong&gt;u:&lt;/strong&gt;)&lt;/li&gt;
&lt;li&gt;To enable the escaping in attributes (by default &lt;strong&gt;a:&lt;/strong&gt; - the new default modifier)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The reason to introduce the new default modifier were the needs of HTML escaping and XSS protection for attribute values that must be a bit more complex than for normal tag body. You will be allowed to use the more complex escaping function for attributes, and the simpler, but faster - for ordinary texts.&lt;/p&gt;


&lt;p&gt;Some of you may have noticed that the modifiers use the same syntax, as the expression type chooser. Nothing more further from the truth! Thanks to some simple conventions everything is unambiguous. First of all, to specify both the expression type and the modifier, we specify the parser, and later the modifier: &lt;code&gt;{parse:e:$variable}&lt;/code&gt;. Secondly, the modifier name is always one character long. At at last, in the code like this: &lt;code&gt;{e:$variable}&lt;/code&gt;, the compiler matches the modifier first and then the expression parser.&lt;/p&gt;


&lt;h2&gt;Extended data format support&lt;/h2&gt;


&lt;p&gt;Data formats are probably the most brilliant feature of OPT and in the next branch this element will be greatly improved. Let's take a look at instructions first:&lt;/p&gt;

&lt;pre&gt;
&amp;lt;opt:section name=&amp;quot;foo&amp;quot;&amp;gt;
 ...
&amp;lt;/opt:section&amp;gt;
&lt;/pre&gt;


&lt;p&gt;To specify the data format for thi section, we have to link it with a variable (in this case: &lt;code&gt;$foo&lt;/code&gt;), but it is not always possible. For example, the variable may be specified by the &lt;code&gt;datasource&lt;/code&gt; attribute or the section could have nothing to do with variables. Such situation occured while developing Open Power Forms. Some sections must be connected to the form and have no equivalent in template variables. And what if we would like to write a new implementation of &lt;code&gt;opt:include&lt;/code&gt;? In OPT 2.0 it is impossible to pass the information about the data format to it.&lt;/p&gt;


&lt;p&gt;The problem will be solved by introducing a special, optional attribute called &lt;code&gt;id&lt;/code&gt;. Obviously, it will allow to define an unique identifier for the instruction which can be used to find the data format definition or modify any other aspect of the behaviour. It leads to the extension of the list of the available data formats. Some of the new ones are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Include&lt;/strong&gt; - the default data format for &lt;code&gt;opt:include&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;System&lt;/strong&gt; - the &lt;code&gt;$system&lt;/code&gt; special variable handling, moved from the compiler code to the data format.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Scalar&lt;/strong&gt; - the scalar data (text, numbers, logical values) that does not allow the container, array and object access. It will be impossible to use them as section data sources which will improve the template code security and error resistance.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;RuntimeIterator&lt;/strong&gt; - if you do not want to write a custom data format and &lt;strong&gt;Objective&lt;/strong&gt; does not meet your requirements, but you still want to use sections with your own objects and their own logic, this format will allow this. It will work with a special interface that needs to be implemented in your class that provides the whole section functionality.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;Snippet arguments&lt;/h2&gt;


&lt;p&gt;Snippets resemble macros from such languages, as C. A new interesting addition in OPT 2.1 will be the possibility of giving a snippet the arguments. I have not invented a syntax for this element yet, so please treat the following code as the illustration of an idea:&lt;/p&gt;

&lt;pre&gt;
&amp;lt;opt:snippet name=&amp;quot;snippet&amp;quot;&amp;gt;
 &amp;lt;p&amp;gt;{$info.foo}&amp;lt;/p&amp;gt;
 &amp;lt;p&amp;gt;{$info.bar}&amp;lt;/p&amp;gt;
&amp;lt;/opt:snippet&amp;gt;
 
&amp;lt;opt:section name=&amp;quot;foo&amp;quot;&amp;gt;
&amp;lt;div&amp;gt;
 &amp;lt;p&amp;gt;Some content&amp;lt;/p&amp;gt;
 &amp;lt;opt:insert snippet=&amp;quot;snippet&amp;quot; info=&amp;quot;$foo&amp;quot; /&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/pre&gt;


&lt;p&gt;Now the snippet variable &lt;code&gt;$info&lt;/code&gt; will be treated as &lt;code&gt;$foo&lt;/code&gt;, keeping its data format and features. It will make the snippets much more portable.&lt;/p&gt;


&lt;h2&gt;Snippet loading&lt;/h2&gt;


&lt;p&gt;Currently, the shared snippets can be included in our template in two ways:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Template inheritance&lt;/li&gt;
&lt;li&gt;&lt;code&gt;opt:root&lt;/code&gt; attribute &lt;code&gt;include&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The last way will be extended by a special tag &lt;code&gt;opt:load&lt;/code&gt; which will allow to load multiple templates with snippets:&lt;/p&gt;

&lt;pre&gt;
&amp;lt;opt:root&amp;gt;
  &amp;lt;opt:load template=&amp;quot;snippets_1.tpl&amp;quot; /&amp;gt;
  &amp;lt;opt:load template=&amp;quot;snippets_2.tpl&amp;quot; /&amp;gt;

  &amp;lt;!-- the code here --&amp;gt;
&amp;lt;/opt:root&amp;gt;
&lt;/pre&gt;


&lt;h2&gt;Template functions&lt;/h2&gt;


&lt;p&gt;Snippets have one important disadvantage: they are static and exist only during the compilation. It is impossible to select the snippet name from a variable or something like that. Many people ask for such a feature, and the problem became known as &quot;dynamic snippets&quot;. I did a long research looking for the possible ways of adding this feature, but due to the PHP language construction and the snippet features, it seems to be impossible. The snippets cannot be implemented as functions or class methods, because:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The access to the template variables &lt;code&gt;{@variable}&lt;/code&gt; will be lost.&lt;/li&gt;
&lt;li&gt;The access to some internal compilation code variables will be lost, which could lead to serious problems with data formats.&lt;/li&gt;
&lt;li&gt;The snippets would be strictly connected with one, particular data format, whereas they should match the current data format in the place of insertion.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This is why I decided to introduce a new language element which does not have an official name yet, and during the development process we call it &quot;template functions&quot;. Why? Because it is a reimplementation of the classic PHP function features. They are created once and physically called, intead of being copy-pasted during the compilation, like in snippets. What is more, they will support a dynamic selection of the called function.&lt;/p&gt;


&lt;p&gt;My plan is to implement them so that they could be used in many places, where the snippets can be currently applied:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Section bodies&lt;/li&gt;
&lt;li&gt;Components&lt;/li&gt;
&lt;li&gt;Blocks&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Of course some of the locations will be unavailable for them and moreover, they will be strictly connected to a single data format. An interesting feature is that they could be injected into the component objects, like (please remember that the syntax is not invented yet):&lt;/p&gt;

&lt;pre&gt;
&amp;lt;!-- define a layout of the checkbox list for the checkbox component --&amp;gt;
&amp;lt;opt:function name=&amp;quot;checkboxListLayout&amp;quot; list=&amp;quot;required&amp;quot;&amp;gt;
  &amp;lt;ul&amp;gt;
  &amp;lt;opt:section name=&amp;quot;list&amp;quot; datasource=&amp;quot;$list&amp;quot;&amp;gt;
    &amp;lt;li&amp;gt;{u:$list.checkboxCode}&amp;lt;/li&amp;gt;
  &amp;lt;/opt:section&amp;gt;
  &amp;lt;/ul&amp;gt;
&amp;lt;/opt:function&amp;gt;

&amp;lt;form:checkbox-list name=&amp;quot;list&amp;quot;&amp;gt;
  &amp;lt;label for=&amp;quot;parse:$system.component.id&amp;quot;&amp;gt;Select something:&amp;lt;/label&amp;gt;

  &amp;lt;!-- dynamically select the layout to inject --&amp;gt;
  &amp;lt;opt:display inject=&amp;quot;$system.component.layout&amp;quot; /&amp;gt;
&amp;lt;/form&amp;gt;
&lt;/pre&gt;


&lt;h2&gt;Improved section syntax&lt;/h2&gt;


&lt;p&gt;Together with the current syntax with opt:show and the empty section tag, in OPT 2.1 it will be possible to use the new style presented by the example below:&lt;/p&gt;

&lt;pre&gt;
&amp;lt;opt:section name=&amp;quot;foo&amp;quot;&amp;gt;
	&amp;lt;opt:body&amp;gt;
		&amp;lt;ol&amp;gt;
			&amp;lt;opt:item&amp;gt;
			&amp;lt;li&amp;gt;Dodood&amp;lt;/li&amp;gt;
			&amp;lt;/opt:item&amp;gt;
		&amp;lt;/ol&amp;gt;
	&amp;lt;/opt:body&amp;gt;
	&amp;lt;opt:else&amp;gt;
		&amp;lt;p&amp;gt;Hi universe!&amp;lt;/p&amp;gt;
	&amp;lt;/opt:else&amp;gt;
&amp;lt;/opt:section&amp;gt;
&lt;/pre&gt;


&lt;p&gt;As we can see, in place of &lt;code&gt;opt:show&lt;/code&gt; we write the section tag, and in the body we use &lt;code&gt;opt:body&lt;/code&gt; to indicate the section body and &lt;code&gt;opt:item&lt;/code&gt; to specify a place which will be iterated. The current syntax &lt;strong&gt;will not&lt;/strong&gt; be removed, as they are complementary to each other, mostly when it comes to the cooperation with snippets. I was also asked for the possibility of having the section body enclosed in an extra tag which is quite useful if we have an extra &lt;code&gt;opt:else&lt;/code&gt; at the same place, and want the body to be loaded from a snippet.&lt;/p&gt;


&lt;p&gt;Moreover, the small changes will be applied to the &lt;code&gt;opt:selector&lt;/code&gt; instruction:&lt;/p&gt;

&lt;pre&gt;
&amp;lt;opt:selector name=&amp;quot;foo&amp;quot;&amp;gt;
	&amp;lt;opt:select item=&amp;quot;fff&amp;quot;&amp;gt;ssdf&amp;lt;/opt:select&amp;gt;
	&amp;lt;opt:select item=&amp;quot;ssddf&amp;quot;&amp;gt;ssdf&amp;lt;/opt:select&amp;gt;
	&amp;lt;opt:select item=&amp;quot;abc&amp;quot;&amp;gt;ssdf&amp;lt;/opt:select&amp;gt;
&amp;lt;/opt:selector&amp;gt;
&lt;/pre&gt;


&lt;p&gt;In other words, it will be no longer necessary to create thousands of new tags for our choices.&lt;/p&gt;


&lt;h2&gt;Switch instruction&lt;/h2&gt;


&lt;p&gt;OPT 2.1 will introduce the new instruction: &lt;code&gt;opt:switch&lt;/code&gt;. Contrary to the &lt;strong&gt;switch&lt;/strong&gt; statements from the classic programming languages, it will be a real swiss knife. Take a look:&lt;/p&gt;

&lt;pre&gt;
&amp;lt;!-- classic switch --&amp;gt;
&amp;lt;opt:switch test=&amp;quot;$condition&amp;quot;&amp;gt;
 &amp;lt;opt:equals value=&amp;quot;value1&amp;quot;&amp;gt;Body...&amp;lt;/opt:equals&amp;gt;
 &amp;lt;opt:equals value=&amp;quot;value2&amp;quot;&amp;gt;Body...&amp;lt;/opt:equals&amp;gt;
 &amp;lt;opt:equals value=&amp;quot;value3&amp;quot;&amp;gt;Body...&amp;lt;/opt:equals&amp;gt;
 
 &amp;lt;!-- an equivalent of playing with &amp;quot;break&amp;quot; --&amp;gt;
 &amp;lt;opt:equals value=&amp;quot;value4&amp;quot;&amp;gt;
   Some content...
   &amp;lt;opt:equals value=&amp;quot;value5&amp;quot;&amp;gt;
     Some content...
   &amp;lt;/opt:equals&amp;gt;
 &amp;lt;/opt:equals&amp;gt;
 &amp;lt;opt:default&amp;gt;...&amp;lt;/opt:default&amp;gt;
&amp;lt;/opt:switch&amp;gt;
&lt;/pre&gt;


&lt;p&gt;If you like the power of &lt;code&gt;case... break&lt;/code&gt; construct in PHP, you will surely enjoy this stuff:&lt;/p&gt;

&lt;pre&gt;
 &amp;lt;opt:equals value=&amp;quot;value4&amp;quot;&amp;gt;
   Some content...
   &amp;lt;opt:equals value=&amp;quot;value5&amp;quot;&amp;gt;
     Some content...
   &amp;lt;/opt:equals&amp;gt;
   Some content...
   &amp;lt;opt:equals value=&amp;quot;value6&amp;quot;&amp;gt;
     More optional content
   &amp;lt;/opt:equals&amp;gt;
   The ending
 &amp;lt;/opt:equals&amp;gt;
&lt;/pre&gt;


&lt;p&gt;If the tested condition equals &lt;code&gt;value5&lt;/code&gt;, we will see just the contents of the &lt;code&gt;value5&lt;/code&gt; tag. But if it equals &lt;code&gt;value4&lt;/code&gt;, we will see its contents, together with &lt;code&gt;value5&lt;/code&gt; and &lt;code&gt;value6&lt;/code&gt;. But this is not the end. OPT switch will work with... containers:&lt;/p&gt;

&lt;pre&gt;
&amp;lt;opt:switch test=&amp;quot;$container&amp;quot;&amp;gt;
  &amp;lt;opt:contains value=&amp;quot;foo&amp;quot;&amp;gt;body...&amp;lt;/opt:contans&amp;gt;
  &amp;lt;opt:contains value=&amp;quot;bar&amp;quot;&amp;gt;body...&amp;lt;/opt:contans&amp;gt;
  &amp;lt;opt:contains value=&amp;quot;joe&amp;quot;&amp;gt;body...&amp;lt;/opt:contans&amp;gt;
&amp;lt;/opt:switch&amp;gt;
&lt;/pre&gt;


&lt;p&gt;In this case, OPT will be able to display the values of more than one choice. &lt;code&gt;opt:contains&lt;/code&gt; could also be nested, similarly to &lt;code&gt;opt:equals&lt;/code&gt;. And what would you say, if you see that they can be mixed?&lt;/p&gt;

&lt;pre&gt;
&amp;lt;opt:switch test=&amp;quot;$condition&amp;quot;&amp;gt;
  &amp;lt;opt:contains value=&amp;quot;foo&amp;quot;&amp;gt;body...&amp;lt;/opt:contans&amp;gt;
  &amp;lt;opt:contains value=&amp;quot;bar&amp;quot;&amp;gt;body...&amp;lt;/opt:contans&amp;gt;
  &amp;lt;opt:contains value=&amp;quot;joe&amp;quot;&amp;gt;body...&amp;lt;/opt:contans&amp;gt;
  &amp;lt;opt:equals value=&amp;quot;value1&amp;quot;&amp;gt;Body...&amp;lt;/opt:equals&amp;gt;
  &amp;lt;opt:equals value=&amp;quot;value2&amp;quot;&amp;gt;Body...&amp;lt;/opt:equals&amp;gt;
&amp;lt;/opt:switch&amp;gt;
&lt;/pre&gt;


&lt;p&gt;In this case, OPT simply checks the expression type. If it is a container, it matches the &lt;code&gt;opt:contains&lt;/code&gt; tags, otherwise - &lt;code&gt;opt:equals&lt;/code&gt;. Nested cross-mixing of &lt;code&gt;opt:equals&lt;/code&gt; and &lt;code&gt;opt:contains&lt;/code&gt; is also possible.&lt;/p&gt;


&lt;p&gt;We get even better functionality, if we use the attribute form of &lt;code&gt;opt:switch&lt;/code&gt;:&lt;/p&gt;

&lt;pre&gt;
&amp;lt;ul opt:switch=&amp;quot;$row&amp;quot;&amp;gt;
 &amp;lt;li&amp;gt;Name {$row.name}&amp;lt;/li&amp;gt;
 &amp;lt;li&amp;gt;Age: {$row.age}&amp;lt;/li&amp;gt;
 &amp;lt;li opt:contains=&amp;quot;city&amp;quot;&amp;gt;City: {$row.city}&amp;lt;/li&amp;gt;
 &amp;lt;li opt:contains=&amp;quot;email&amp;quot;&amp;gt;E-mail: {$row.email}&amp;lt;/li&amp;gt;
 &amp;lt;li&amp;gt;Date: {$row.date}&amp;lt;/li&amp;gt;
 &amp;lt;li opt:contains=&amp;quot;other&amp;quot;&amp;gt;Other: {$row.other}&amp;lt;/li&amp;gt;
&amp;lt;/ul&amp;gt;
&lt;/pre&gt;


&lt;p&gt;And the finale that will help in the last example. Suppose that we would like to add the &lt;code&gt;class=&quot;last&quot;&lt;/code&gt; attribute to the last &lt;strong&gt;displayed&lt;/strong&gt; list element. This could be done by the following code:&lt;/p&gt;

&lt;pre&gt;
&amp;lt;ul opt:switch=&amp;quot;$row&amp;quot;&amp;gt;
 &amp;lt;li&amp;gt;Name {$row.name}&amp;lt;/li&amp;gt;
 &amp;lt;li&amp;gt;Age: {$row.age}&amp;lt;/li&amp;gt;
 &amp;lt;li opt:contains=&amp;quot;city&amp;quot;&amp;gt;City: {$row.city}&amp;lt;/li&amp;gt;
 &amp;lt;li opt:contains=&amp;quot;email&amp;quot;&amp;gt;E-mail: {$row.email}&amp;lt;/li&amp;gt;
 &amp;lt;li&amp;gt;Date: {$row.date}&amp;lt;/li&amp;gt;
 &amp;lt;li opt:contains=&amp;quot;other&amp;quot;&amp;gt;Other: {$row.other}&amp;lt;/li&amp;gt;
 &amp;lt;opt:append to=&amp;quot;last&amp;quot;&amp;gt;
   &amp;lt;opt:attribute name=&amp;quot;str:class&amp;quot; value=&amp;quot;str:last&amp;quot; /&amp;gt;
 &amp;lt;/opt:append&amp;gt;
&amp;lt;/ul&amp;gt;
&lt;/pre&gt;


&lt;p&gt;For everyone who claim that &quot;PHP is the best template language&quot;: enjoy implementing similar functionality manually.&lt;/p&gt;


&lt;h2&gt;Futher changes in syntax&lt;/h2&gt;


&lt;p&gt;During the development process, there have occured some inconsistences in the naming style of the instructions. OPT 2.1 will attempt to fix them. Basically, all the tags named &lt;code&gt;opt:someTag&lt;/code&gt; will be renamed to the form &lt;code&gt;opt:some-tag&lt;/code&gt;. In sections, monsters like &lt;code&gt;opt:sectionelse&lt;/code&gt; will be shortened to &lt;code&gt;opt:else&lt;/code&gt;. &lt;code&gt;opt:use&lt;/code&gt; will be renamed to &lt;code&gt;opt:insert&lt;/code&gt;, and &lt;code&gt;opt:on&lt;/code&gt; into &lt;code&gt;opt:omit-tag&lt;/code&gt;.&lt;/p&gt;


&lt;h2&gt;Inflectors&lt;/h2&gt;


&lt;p&gt;This feature concerns the public library API and is related to finding the templates in the filesystem. I was talking to some programmers and the developers of CMS-es etc. They were often complaining about the current, hard-coded algorithm of mapping the template names to the files based on the streams. They said that it is very impractical, when it comes to the modular applications - it is very hard to manage the registration of dozens of quasi-streams, and operating them on the script- and template side. They would enjoy a system that would give them more flexibility. This is how the idea of inflectors was born. An inflector is a simple class that gets the &quot;public template name&quot;, such as `db:user/edit.tpl` and returns the real filesystem path to it. The default OPT inflector is basically the reimplementation of the current template locating algorithm. It is just extended by an extra API for managing the streams. However, if the programmer needs some specific rules, he can write a custom inflector and deal with it on his own.&lt;/p&gt;


&lt;h2&gt;Backward compatibility&lt;/h2&gt;


&lt;p&gt;OPT 2.1 is intended to be used in new projects, however - if you stared writing something with OPT 2.0, you do not have to worry. Although the syntax changes can bother many programmers, there is no need to worry. OPT 2.1 will have a backward compatibility mode. Basically it activates the whole old and replaced syntax, with keeping the new features at the same time. You can use this mode to make use of the new features and give yourself some time to make a migration. What is more, many changes are just syntactic, not semantic. I plan to write a special tool that would convert the existing templates to the new syntax with one click.&lt;/p&gt;


&lt;p&gt;Note that if you actually want to be up-to-date, the migration at some level will be necessary. The OPT 2.2 branch will be basically OPT 2.1 with the backward compatibility code removed.&lt;/p&gt;


&lt;h2&gt;Support&lt;/h2&gt;


&lt;p&gt;If you want to stay with OPT 2.0 in your current projects, the support for this branch will be continued long after the OPT 2.1 will be released. We will fix the encountered bugs and continue improving the stability of this branch. Actually, OPT 2.1 is going to be a transition branch to the next evolution level. The plans are as follows:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;OPT 2.0 - works on PHP 5.2, the support is continued for at least one year after releasing OPT 2.1&lt;/li&gt;
&lt;li&gt;OPT 2.1 - the new branch with new features and the full backward compatibility mode. The minimum requirement is PHP 5.3&lt;/li&gt;
&lt;li&gt;OPT 2.2 - backward compatible with OPT 2.1, but without the 2.0 compatibility mode. Also, the very long support is planned.&lt;/li&gt;
&lt;li&gt;OPT 3.0 - basically the same as OPT 2.2, but with the entire code migrated to PHP 6 and namespaces.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Note that OPT 2.0, 2.1 and 2.2 are also supposed to work on PHP 6 as soon as it will become more stable, because nowadays I even have serious problem with compiling the development snapshots.&lt;/p&gt;


&lt;h2&gt;Changes to the OPL core&lt;/h2&gt;


&lt;p&gt;As you can see, the new branches will require the improvements of the OPL core. The planned features are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;OPL 2.1 - new features: namespace support, command line interface tools, new debug console implementaton, improved error handling.&lt;/li&gt;
&lt;li&gt;OPL 2.2 - removing legacy code for compatibility with OPL 2.0&lt;/li&gt;
&lt;li&gt;OPL 3.0 - migration to PHP 6 and namespaces&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;Conclusion&lt;/h2&gt;


&lt;p&gt;OPL project is getting more and more mature. The new features will make it more suitable to deal with new problems and situations, where the template engine support is needed. At the same time, I think about how to introduce the new users in the project and teach them, how to use the offered tools. You can expect new tutorials, and personally, I think it would be nice to write a book after releasing OPF and OPT 2.2...&lt;/p&gt;</description>
    
    
    
          <comments>http://blog.invenzzia.org/en/post/Open-Power-Template-2.1-a-closer-look#comment-form</comments>
      <wfw:comment>http://blog.invenzzia.org/en/post/Open-Power-Template-2.1-a-closer-look#comment-form</wfw:comment>
      <wfw:commentRss>http://blog.invenzzia.org/en/feed/atom/comments/65</wfw:commentRss>
      </item>
    
  <item>
    <title>Open Power Template 2.0.0 is ready!</title>
    <link>http://blog.invenzzia.org/en/post/Open-Power-Template-2.0.0-is-ready%21</link>
    <guid isPermaLink="false">urn:md5:289d171afca92f335d23613184a0be22</guid>
    <pubDate>Tue, 14 Jul 2009 09:14:00 +0200</pubDate>
    <dc:creator>Zyx</dc:creator>
        <category>Open Power Template</category>
        <category>history</category><category>OPT2</category><category>releases</category>    
    <description>&lt;p&gt;Finally, after a 1.5 years of the development process, we managed to release the first stable version of Open Power Template. The road was very long but I hope that it was worth it. In this short entry, I'd like to make a small introduction to the project history for you, as it is quite interesting and could give some clue, how this all began.&lt;/p&gt;    &lt;p&gt;Open Power Template is a quite old project, lasting for almost five years now. The development started in November 2004, as a small template engine for the open-source discussion board project called Open Power Board. The library was a creative variation of the Smarty engine, and I was the right person in the team to write it, as I was writing small template engines much earlier and had some experience in this area. Fortunately or not, the OpenPB project failed and my library was the only which survived the crash. After some huge code revisions, I released the first stable version, 1.0.0 in July 2006, three years ago. At the first sight, the template engine was quite similar to Smarty, especially because it used curly brackets, too. However, we could find there some ideas that were later improved and featured in the 2.0 branch. OPT 1.0.0 contained:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Sections&lt;/li&gt;
&lt;li&gt;Components&lt;/li&gt;
&lt;li&gt;Snippets (under different name)&lt;/li&gt;
&lt;li&gt;I18n support&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The 1.1 branch brought the pagination support and tree rendering instruction. The template engine did not understand the document structure, but the parser used some ideas taken from XML parsers. For example, it constructed a node tree for the content similar to DOM, and the nodes were instruction tags and the text content. Furthermore, there was a feature called &lt;em&gt;XML Compatibility Mode&lt;/em&gt; which replaced the curly brackets with XML-like instruction delimiters. However, this was only a visual change.&lt;/p&gt;


&lt;p&gt;Early in 2007, after some talks with the users, I started thinking about using a real XML parser in Open Power Template. On my blog, I published a note dated to April 19, where I suggested that a compiler with an XML parser could be written, as an extra compiler for the project. It did not mean that the works began then, as I was beginning my studies on AGH University in Cracow and had little time to deal with it, too. The first lines of code were written about seven months later, in November. On November 23, I wrote on my blog that the parser loaded the first XML document into memory, and a couple of days later it compiled its first (very simple) template.&lt;/p&gt;


&lt;p&gt;OPT was a really productive project. Soon, I realized, that the old infrastructure from OpenPB used so far is crappy and unreliable which led to the formation of Invenzzia Group in January. You may ask where the name came from. We were thinking about it very long, and the further, the more stupid ideas were coming into our minds. As I was fascinated with linguistics and artifical (constructed) languages, we opened the dictionary of one of my languages, Ferrinti with the word: &lt;code&gt;invenzzia - invention&lt;/code&gt;. By the way, it has nothing to do with Polish language, where the word for &lt;em&gt;invention&lt;/em&gt; is &lt;em&gt;wynalazek&lt;/em&gt; and &lt;em&gt;inwencja&lt;/em&gt; means something completely different.&lt;/p&gt;


&lt;p&gt;A couple of months later, I was becoming more and more annoyed with DocBook, especially because of the lack of any simple-in-use framework for generating user manuals and documentations from them. Because I did not want to deal with various XML parsers, incompatibility issues between Windows, Linux and everything else, I decided to write a completely new tool in PHP. This was the second project inspired by Open Power Template and it is known now as TypeFriendly. At the same time, we closed the 1.1 branch of OPT, to focus on the other projects. In July, the branch was actually rewritten from scratch, introducing a completely new API that had nothing to do with the earlier versions, as it was using many new features, such as autoloading, or better use of exceptions. Furthermore, I removed the explicit recursion from the compiler that produced very serious trouble due to the PHP stack limitations. Precisely after a year, on November 23, 2008, Invenzzia Group released the last &lt;em&gt;2.0-DEV&lt;/em&gt; version with actually all the planned features finished and began the beta-tests and the debugging process. After deep analysis, some parts of the code were rewritten once more (notably sections and data formats), providing a more stable and flexible source code, and many other features were widely tested both with unit tests and the real projects.&lt;/p&gt;


&lt;p&gt;In March, I published the first revision of the Zend Framework port on our SVN. The community created a port for Kohana framework a couple of months earlier. I started also thinking about the tutorials. In the last few days, we managed to finish the user manual and the huge tutorial &lt;em&gt;A photo gallery with Doctrine and Open Power Template&lt;/em&gt;, and we decided that we are ready to release the first stable version. And here we are!&lt;/p&gt;</description>
    
    
    
          <comments>http://blog.invenzzia.org/en/post/Open-Power-Template-2.0.0-is-ready%21#comment-form</comments>
      <wfw:comment>http://blog.invenzzia.org/en/post/Open-Power-Template-2.0.0-is-ready%21#comment-form</wfw:comment>
      <wfw:commentRss>http://blog.invenzzia.org/en/feed/atom/comments/62</wfw:commentRss>
      </item>
    
  <item>
    <title>Open Power Template 2.0-RC1</title>
    <link>http://blog.invenzzia.org/en/post/Open-Power-Template-2.0-RC1</link>
    <guid isPermaLink="false">urn:md5:f4febc94a94955293cab40218faab3b7</guid>
    <pubDate>Tue, 12 May 2009 13:06:00 +0200</pubDate>
    <dc:creator>Zyx</dc:creator>
        <category>Open Power Template</category>
        <category>OPT2</category><category>releases</category>    
    <description>&lt;p&gt;Finally, the first Release Candidate of Open Power Template is available to download, after 4 months of testing and implementing the remaining features. The library seems to be completed and stable enough for both development and production environments. Of course, there is still a small possibility that a fatal bug will be found, but I do not think this will happen, as there are lots of unit tests present and the code has been checked with two real-world web applications.&lt;/p&gt;    &lt;h2&gt;Where to download?&lt;/h2&gt;


&lt;p&gt;Of course, from our website: &lt;a href=&quot;http://www.invenzzia.org/en/download&quot; hreflang=&quot;en&quot;&gt;Invenzzia&lt;/a&gt;. There are available the ordinary packages, and moreover, for the first time we publish the PHAR-s. PHAR means &lt;em&gt;PHP ARchive&lt;/em&gt; - it is a package of executable PHP code that works much like JAR-s in Java. It is going to become a part of the official PHP release since 5.3.0 version. Unfortunately, our web system is not prepared to publish so many different files in one branch, so I publish the links right here till the problem will be solved:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href=&quot;http://static.invenzzia.org/files/opt-phar-2.0-rc1.tar.bz2&quot; hreflang=&quot;en&quot;&gt;PHAR-s in TAR.BZ2 format&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://static.invenzzia.org/files/opt-phar-2.0-rc1.tar.gz&quot; hreflang=&quot;en&quot;&gt;PHAR-s in TAR.GZ format&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://static.invenzzia.org/files/opt-phar-2.0-rc1.zip&quot; hreflang=&quot;en&quot;&gt;PHAR-s in ZIP format&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The packages contain two PHAR-s: for OPL and OPT, license texts and the README. They do not include the documentation.&lt;/p&gt;


&lt;h2&gt;What now?&lt;/h2&gt;


&lt;p&gt;Well, Release Candidate does not mean the end. There is also the stable release, and lots of plans for the 2.1 branch. However, for some time the development process of OPT will slow down, as there are some other projects that need our urgent attention. First of all, we have all the resources for the programmers: tutorials, tips, case studies etc. Open Power Template brings a completely new philosophy of creating the presentation layer and there must be good articles available in order to show, how to make a good use of it. Moreover, there are next libraries on the way: Open Power Classes, Open Power Forms and the Zend Framework port.&lt;/p&gt;


&lt;h2&gt;Conclusion&lt;/h2&gt;


&lt;p&gt;At the end, we would like to thank all the current users of the library, especially those ones who have helped us with the development process. These projects are created for you.&lt;/p&gt;</description>
    
    
    
          <comments>http://blog.invenzzia.org/en/post/Open-Power-Template-2.0-RC1#comment-form</comments>
      <wfw:comment>http://blog.invenzzia.org/en/post/Open-Power-Template-2.0-RC1#comment-form</wfw:comment>
      <wfw:commentRss>http://blog.invenzzia.org/en/feed/atom/comments/58</wfw:commentRss>
      </item>
    
  <item>
    <title>OPT 2.0-beta2</title>
    <link>http://blog.invenzzia.org/en/post/OPT-2.0-beta2</link>
    <guid isPermaLink="false">urn:md5:018c3371d26b97bf3ba4c641e8af2aad</guid>
    <pubDate>Sat, 21 Feb 2009 09:22:00 +0100</pubDate>
    <dc:creator>Zyx</dc:creator>
        <category>Open Power Template</category>
        <category>development</category><category>OPT2</category><category>releases</category>    
    <description>&lt;p&gt;It's true, the new beta version of Open Power Template is available to download. It was planned to be released a week ago, but because of problems with SVN I didn't manage to do that (again, but hopefully for the last time). This is mostly a bugfix release, but there are some small improvements and changes in the component API, which was not documented then. The changes are not too big and were quite necessary to be introduced.&lt;/p&gt;    &lt;p&gt;The changes in the component and block API:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;code&gt;setOptInstance()&lt;/code&gt; became &lt;code&gt;setView&lt;/code&gt; and takes the current &lt;code&gt;Opt_View&lt;/code&gt; object as an argument. Now the components and blocks can refer to the template variables.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;createAttributes()&lt;/code&gt; became &lt;code&gt;manageAttributes()&lt;/code&gt;, and moreover, the semantics has been changed. The new method takes an array of tag attribute values and returns the modified version. OPT translates it to the valid XML attribute list.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The tutorials can be found in the documentation. Another improvement are the &lt;code&gt;get()&lt;/code&gt; and &lt;code&gt;getGlobal()&lt;/code&gt; methods in &lt;code&gt;Opt_View&lt;/code&gt; that allow to read the template variable values from the view object.&lt;/p&gt;


&lt;p&gt;The things that need to be done now are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;To check the caching port interface.&lt;/li&gt;
&lt;li&gt;To test several rarely-used compiler API features.&lt;/li&gt;
&lt;li&gt;To check, whether all the features mentioned in the documentation are implemented and vice versa.&lt;/li&gt;
&lt;li&gt;To fix more bugs :).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;By the way, it is possible that in a few next days, there will be PHAR files with the beta2 available to download for use with PHP 5.3.&lt;/p&gt;


&lt;p&gt;The library can be downloaded from &lt;a href=&quot;http://libs.invenzzia.org/en/download&quot; hreflang=&quot;en&quot;&gt;our file repositories&lt;/a&gt; and the English documentation can be found &lt;a href=&quot;http://www.invenzzia.org/docs/opt2-en/&quot; hreflang=&quot;en&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;</description>
    
    
    
          <comments>http://blog.invenzzia.org/en/post/OPT-2.0-beta2#comment-form</comments>
      <wfw:comment>http://blog.invenzzia.org/en/post/OPT-2.0-beta2#comment-form</wfw:comment>
      <wfw:commentRss>http://blog.invenzzia.org/en/feed/atom/comments/47</wfw:commentRss>
      </item>
    
  <item>
    <title>OPT 2.0.0-beta1 released</title>
    <link>http://blog.invenzzia.org/en/post/OPT-2.0.0-beta1-released</link>
    <guid isPermaLink="false">urn:md5:cbb9f97b7390941653039d1e10994582</guid>
    <pubDate>Tue, 06 Jan 2009 22:45:00 +0100</pubDate>
    <dc:creator>Zyx</dc:creator>
        <category>Open Power Template</category>
        <category>OPT2</category><category>releases</category>    
    <description>&lt;p&gt;Well, after many adventures with SVN and recently discovered problems with XML prologs and DTD I finally managed to release the first beta version of Open Power Template. From now, we are going to focus on removing as many bugs and problems as possible and we need here your help. Furthermore, we also need to complete the English manual, which is quite big now, but still does not explain some issues.&lt;/p&gt;    &lt;p&gt;I hope the library will mature soon, because I want to start works on next libraries: Open Power Forms and Open Power Classes. Thankfully, our quite small community is quite active. Recently, Nowaker informed me he prepared a port for Kohana framework and he is going to release it, soon. As eXtreme will complete the new Invenzzia website, we will be able to put such add-ons in one place, as well as tutorials and sample projects.&lt;/p&gt;


&lt;p&gt;The library can be found in our &lt;a href=&quot;http://libs.invenzzia.org/en/download&quot; hreflang=&quot;en&quot;&gt;download&lt;/a&gt; sites. The packages contain English manual, which is also available &lt;a href=&quot;http://www.invenzzia.org/docs/opt2-en/&quot; hreflang=&quot;en&quot;&gt;on-line&lt;/a&gt;.&lt;/p&gt;</description>
    
    
    
          <comments>http://blog.invenzzia.org/en/post/OPT-2.0.0-beta1-released#comment-form</comments>
      <wfw:comment>http://blog.invenzzia.org/en/post/OPT-2.0.0-beta1-released#comment-form</wfw:comment>
      <wfw:commentRss>http://blog.invenzzia.org/en/feed/atom/comments/43</wfw:commentRss>
      </item>
    
  <item>
    <title>One year of hard work</title>
    <link>http://blog.invenzzia.org/en/post/One-year-of-hard-work</link>
    <guid isPermaLink="false">urn:md5:75e09a4f6268c6b49709df680bacc1c8</guid>
    <pubDate>Thu, 20 Nov 2008 18:59:00 +0100</pubDate>
    <dc:creator>Zyx</dc:creator>
        <category>Open Power Template</category>
        <category>development</category><category>OPT2</category><category>releases</category>    
    <description>&lt;p&gt;Somewhere in the middle of November 2007, I wrote the first (working!) lines of the Open Power Template 2.0.0 source code. After a year of hard work, I've already uploaded a revision that finally gives you all the invented features implemented. For that time, OPTv2 grew and changed its shape. The first development releases resembled OPT 1.1.x when it comes to API and some features. They were just ported to the new XML compiler. Nowadays, OPT is a totally different library. It is much more modularized and designed to make the integration with frameworks easier. There is still a lot to do. The incoming release will be the last one with the &quot;-dev&quot; prefix, and in the next few weeks, the beta versions will appear, then Release Candidates and at last, the first stable release.&lt;/p&gt;    &lt;p&gt;I still get questions, why the hell I'm writing &quot;yet another template engine if PHP is a template language itself&quot;. In my opinion, it is not PHP which is so good. The template engines are simply too bad, and unsually offer some control structures taken from PHP, variables, put them into different syntax and that's all. Why the hell someone would like to use such stuff if PHP gives him the same things plus object oriented programming to make the code more reusable. But take a look at another issue. Do you think that imperative languages, like PHP, are comfortable enough to be good languages to write, in fact, simple templates? In my opinion, the language that required to be taught, how to display a nested list and escape script data every time we want it is a mistake in this place. Such languages are created to express fast and advanced algorithms, where we need the full control over the process, not to take some data from the script and put them in a string. Yes, we can modularize them with loads of classes, interfaces etc. but is it still a comfortable way and a good use of OOP? In my opinion - no.&lt;/p&gt;


&lt;h2&gt;What give us new languages&lt;/h2&gt;

&lt;p&gt;When people noticed that writing in assembler is too complicated, they invented Fortran and Lisp, the first two high-level programming languages. They allowed to express the same algorithms and calculations in more human-readable form. Later, they invented C and C++, two general-purpose imperative languages. As the WWW appeared on the Internet, another group of people noticed that existing programming languages are too complicated to make dynamic websites. Would you like to deal with memory allocation while writing a CMS? The computers are nowadays faster and faster, and people noticed that sometimes it is much better to use simpler language designed for certain tasks at a cost of performance. In the template engines, the rule is similar. PHP in its current shape was never a good template language, so we try to create something different that simplify this process. And how to achieve this? We have to change the programming paradigm. As we design the new programming language, we can do almost everything with it and add features that are impossible in another language.&lt;/p&gt;


&lt;h2&gt;OPT template language&lt;/h2&gt;


&lt;p&gt;The basis of OPT template language is XML. Unlike PHP, OPT understands entire structure of the XHTML code in the templates and checks its syntax before we see something in the browser. All the language constructs are allowed to manipulate the code in the way that is impossible in PHP, using an interface similar to DOM. They can add new attributes, create tags, and the compiler prevents them from generating invalid output. Moreover, I wanted to get rid of programming in the templates, so I designed the control structures in a declarative style. An example of such declarative language is SQL, where you describe, what data you want to have and the database engine decides, how to find them. Here, you simply inform, what you want to see, and the template compiler provides you the implementation. Below, we have an example of displaying a hierarchical list of categories (a category tree):&lt;/p&gt;

&lt;pre&gt;xml
&amp;lt;opt:tree name=&amp;quot;categories&amp;quot;&amp;gt;
 	&amp;lt;opt:list&amp;gt;&amp;lt;ul&amp;gt;&amp;lt;opt:content /&amp;gt;&amp;lt;/ul&amp;gt;&amp;lt;/opt:list&amp;gt; &amp;lt;!-- 1 --&amp;gt;
  	&amp;lt;opt:node&amp;gt;&amp;lt;li&amp;gt;{$categories.title} &amp;lt;opt:content /&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;/opt:node&amp;gt; &amp;lt;!-- 2 --&amp;gt;
  	&amp;lt;opt:treeelse&amp;gt;&amp;lt;p&amp;gt;Sorry, there are no categories in the system.&amp;lt;/p&amp;gt;&amp;lt;/opt:treeelse&amp;gt; &amp;lt;!-- 3 --&amp;gt;
&amp;lt;/opt:tree&amp;gt;
&lt;/pre&gt;


&lt;p&gt;Do you see here any tree rendering algorithm? We have only elegant definitions, how a flat list looks like (1), how a node looks like (2) what what to show if there are no categories. We even know nothing about the data format. The template would not tell us whether the category tree must be provided as a big object or an array, and what are the details of its structure. As OPT provides a complete declarative programming model, similar solutions can be found almost everywhere in OPT. It really works. A couple of days ago I started writing a small website for my friend. Thanks to OPT, I managed to write all the presentation layer in 15 minutes. The fact that I did not have a working script yet did not concern me. I knew that OPT would do everything for me once I finally decide, where the script would return arrays, where objects, and what they would really be. I do not worry about code refactoring, because the templates remain untouched. Once I make a critical change, I simply recompile the templates and that's all. Try to achieve this in pure PHP or Smarty!&lt;/p&gt;


&lt;p&gt;OPT language features:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;True XML parser with configurable level of standard-compliance (from strict mode to quirks mode, where everything that is not directly parsed by OPT is a static text).&lt;/li&gt;
&lt;li&gt;Variables are data format independent - the data structures are chosen during the compilation thanks to information from the PHP script.&lt;/li&gt;
&lt;li&gt;Two complete models of handling modular templates: by including and by template inheritance (also dynamic).&lt;/li&gt;
&lt;li&gt;Intuitive support for nested lists&lt;/li&gt;
&lt;li&gt;Smart and semi-automatic data escaping.&lt;/li&gt;
&lt;li&gt;Additional useful instructions to create cyclically changed values or to add separators between elements.&lt;/li&gt;
&lt;li&gt;XML manipulation instructions.&lt;/li&gt;
&lt;li&gt;Support for runtime instructions: blocks and components that are designed especially to deal with HTML forms.&lt;/li&gt;
&lt;li&gt;Code reusability: write once, use everywhere.&lt;/li&gt;
&lt;li&gt;Set of data manipulation and aggregation functions.&lt;/li&gt;
&lt;li&gt;Support for i18n.&lt;/li&gt;
&lt;li&gt;A complete expression language designed especially for use with XML. It includes the complete PHP object access support.&lt;/li&gt;
&lt;li&gt;A basic set of programming structures: conditions and loops, if they are really necessary.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;What about the API?&lt;/h2&gt;


&lt;p&gt;OPT source code design resembles Zend Framework conventions, when it comes to the class/method naming and file structure. It is fully objective - the templates are represented in the script as view objects, where we can assign the script results to and set the data format. Once the view is fed with the data, we create an output object and order to render the view. OPT provides two default views: HTTP and Return. The first one sends the results to the browser and maintains the HTTP headers. The second one returns the generated code back to the script. Of couse everything is extendable: you can write new outputs, define new data formats, write new functions, components and even instructions with the powerful compiler API. The management of all this stuff is also simple, because there is a plugin system.&lt;/p&gt;


&lt;p&gt;The templates can be loaded and stored everywhere thanks to PHP streams. All you have to do is to write a new stream wrapper and register it in PHP. The advantage of this solution is that the wrapper can be used with all the file access functions in your script, even with &lt;strong&gt;require&lt;/strong&gt; and &lt;strong&gt;include&lt;/strong&gt;. The output results can be cached, but this time OPT does not provide its own cache handler, allowing the frameworks to do their job. In order to help the programmers manage the templates, the debug console is provided that shows information about the current configuration, executed and compiled templates and the resources used to perform those tasks. The errors are handled with the exceptions and the default error handler provides extra context information with additional explainations, how to fix the problem and where to find the solutions.&lt;/p&gt;


&lt;p&gt;Below, you can see a sample use of OPT in the scripts:&lt;/p&gt;

&lt;pre&gt;php
try
{
	$view = new Opt_View('template_file.tpl');		
	$view-&amp;gt;foo = value;
		
	$out = new Opt_Output_Http;
	$out-&amp;gt;setContentType(Opt_Output_Http::XHTML, 'utf-8'); // Content negotiation available!
	$out-&amp;gt;render($view);
}
catch(Opt_Exception $e)
{
	Opt_Error_Handler($e);
}
&lt;/pre&gt;


&lt;p&gt;However, OPT is not a standalone script. It is the first library in the Open Power Libs series. They share a common core with the basic core that provides the necessary features, like autoloader, configuration, plugin architecture, debugging issues and PHAR support.&lt;/p&gt;


&lt;h2&gt;Project status&lt;/h2&gt;


&lt;p&gt;As I mentioned in the excerpt, all the planned features are currently completed, but not fully tested yet. The code seems to work in all the common use cases, but lots of deeper interactions between various elements are a big unknown. At this time we are going to start beta tests that will take some time. Meanwhile, the following tasks are waiting:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;To complete the English documentation.&lt;/li&gt;
&lt;li&gt;To write the complete unit tests and support for PHAR-s.&lt;/li&gt;
&lt;li&gt;To write tutorials, FAQ-s and sample codes for OPT.&lt;/li&gt;
&lt;li&gt;To provide the initial add-ons: Unicode function set for the templates, complex port to Zend Framework and probably Kohana. In the near future we are going to provide the support for Symfony, too.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Moreover, the next OPL projects are going to be opened. Currently, we have already started works on Open Power Classes, a set of small PHP classes to deal with various useful stuff. Our next big goal is Open Power Forms - a complete form handling solution for your script that shows the real power of Open Power Template.&lt;/p&gt;


&lt;h2&gt;How to help?&lt;/h2&gt;


&lt;p&gt;In the next few days, OPT 2.0.0-dev8 should appear. The source code for this version is already available in SVN, but I want to finish some API reference translations. Test it and send us you opinions. If you think you found a bug, use the bugtracker and let us know about it. Do not be afraid to ask - our community is still quite small, but the Invenzzia team is very helpful and does its best to help you deal with the coding problems.&lt;/p&gt;


&lt;h2&gt;To sum up&lt;/h2&gt;


&lt;p&gt;I know this post is full of propaganda stuff, but on this blog, it has not been announced so far and I think it is necessary to show, what this project really is and why we are writing it. Open Power Template is something more that just a template engine - it is probably the first presentation layer framework designed as a complex solution, and in addition - fast. I hope you'll enjoy it. Many people managed to enjoy OPT 1.1.x, and incoming 2.0.0 is simply much better.&lt;/p&gt;


&lt;p&gt;Update: OPT 2.0.0-dev8 is available to &lt;a href=&quot;http://www.invenzzia.org/en/files&quot; hreflang=&quot;en&quot;&gt;download&lt;/a&gt;. The English manual can be found &lt;a href=&quot;http://www.invenzzia.org/docs/opt2-en/&quot; hreflang=&quot;en&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;</description>
    
    
    
          <comments>http://blog.invenzzia.org/en/post/One-year-of-hard-work#comment-form</comments>
      <wfw:comment>http://blog.invenzzia.org/en/post/One-year-of-hard-work#comment-form</wfw:comment>
      <wfw:commentRss>http://blog.invenzzia.org/en/feed/atom/comments/41</wfw:commentRss>
      </item>
    
  <item>
    <title>OPT requirements</title>
    <link>http://blog.invenzzia.org/en/post/OPT-requirements</link>
    <guid isPermaLink="false">urn:md5:8a825db4d71c176b511d8fd4cad97d53</guid>
    <pubDate>Sun, 06 Apr 2008 10:28:00 +0200</pubDate>
    <dc:creator>Zyx</dc:creator>
        <category>Open Power Template</category>
        <category>development</category><category>OPT2</category><category>optimization</category>    
    <description>&lt;p&gt;I've found a new entry on the bugtracker recently. The author informed that he gets &quot;Nesting level too deep - recursive dependency&quot; error while running the development examples provided by the newest OPTv2 dev version. I looked at it deeper and found out that he lowered the default nesting level limit 4 times from 64 to just 16. Obviously, this is a quite drastic change and would affect not only OPT, but many other scripts as well. However, I think it is time to take a look at the OPT issues concerning the requirements, because several of them needs a deeper explaination.&lt;/p&gt;    &lt;p&gt;The optimizations implemented in OPT, mostly concern the main parser class and the compiler. The first one is the part that is loaded every time the script wants to use templates, so it must provide huge quality standards. There are no sophisticated algorithms, so the speed improvements are:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;To minimize the size of the code.&lt;/li&gt;
&lt;li&gt;To minimize the amount of points that try to access the hard drive.&lt;/li&gt;
&lt;li&gt;To use the fastest elements of the language.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The point is this class must be as light as possible; I would even say: almost transparent for the script.&lt;/p&gt;


&lt;p&gt;The situation is quite different, when it comes to the compiler. It is loaded from time to time, so it can be big and splitted for more files (of course without exaggeration). The key role is played by the limits set in the PHP configuration, because in the pesimistic situations, the compiler runs out of resources to complete the task. Unfortunately, some of the new features cost a lot, and if the users wanted XML tag parsing, they must face the consequences: every such tag requires its own node object in the document tree and they need some preparation tasks to be done. My role is to minimize the time and memory necessary to do this.&lt;/p&gt;


&lt;p&gt;The elements that can be exhausted during the compilation are:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;The stack&lt;/li&gt;
&lt;li&gt;The memory&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The algorithms used in the compiler operate on a data structure called tree, and the use lots of recursion. It consumes the stack, because the number of currently executed methods and functions grows quite fast. In PHP, the default limit for the stack depth is 64 and if you are going to use OPT, the worst you can do is to lower it to ridiculous values like &quot;16&quot; that would affect not only OPT, but also many other scripts :). However, every recursion has an imperative version, constructed for example by queues. Maybe it does not consume less memory, but at least it does not depend on the limits. Such changes have been applied to many compiler methods so far, but some of them still require my attention, because they are not so trivial:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Processing the tree by the instruction processors&lt;/li&gt;
&lt;li&gt;Expression compilation&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In the first one the situation is clear: we get a node of some instruction and want to process it. We find its processor and redirect the node to it. It generates some PHP code and decides, what to do with its children. By default, it wants to process them, too. Here comes the recursion and the process starts from the beginning. There are some difficulties. The algorithm is split over many classes, and the programmers may create their own. What is more, some instructions need to start the subnode processing immediately, because their next decision depends on the code generated by the children. Obviously, this eliminates queues. An elegant replacement could be made, if we had an access to the low level programming.&lt;/p&gt;


&lt;p&gt;Let's take a look, how it affects the compilation process. We have a huge template, with the tags nested up to the level 30. OPT with the compiler can take another 10 calls, and in the deepest place we have a complicated expression with brackets. To sum up, the library uses approx. 45 calls from 64 available, which is more than 70% of the limit! I know this case is quite pesimistic and in normal life such HTML documents are very rare, but it shows, how demanding the compilation can be.&lt;/p&gt;


&lt;p&gt;If we can't remove the recursion without ugly tricks which would be never accepted by the instruction authors, how we can get around it? The idea is not to remove recursion completely, but we keep it in some places. I use here the fact that the immediate access to the subnode compilation results is necessary only for some instructions, and for example the HTML tags do not need it at all. If we get a random node from the tree, we have a big chance that it would not need a recursion here. So, why don't we provide a dual version of this algorithm? By default, it is executed with a queue, but for more sophisticated needs, some nodes can switch it to recursion. Now it can happen that a tree with a depth 30 is processed in one single loop, with no recursion! I predict that in normal situations, the algorithm will consume only 3, 4 spare &quot;items&quot; in the stack, which is fully acceptable.&lt;/p&gt;


&lt;p&gt;The second issue concerns the memory usage. It's not so tragic here, but we can notice a significant rise when compared to the OPT 1.x compiler, even with using some patents from that version. The most memory is consumed by the tree. I've measured some single nodes recently and the results were from 2 kilobytes for a single node to 3 kilobytes for a node with one attribute. When the instructions start to add the PHP code to the buffers, the things are getting worse, but it happens only in some nodes in the whole template. We can safe some memory here. The objects use various arrays, which are initialized just in the beginning, for example:&lt;/p&gt;

&lt;pre&gt;php
abstract class optScannable extends optNode implements Iterator
{
	protected $subnodes = array();
&lt;/pre&gt;


&lt;p&gt;In most of the nodes, the arrays are empty, so it it no sense for them to exist all the time. I fixed the code so that it creates an array only when it is necessary. From the declarations, the &lt;code&gt;= array()&lt;/code&gt; parts were removed. The effect is quite interesting. On a single array, we safe 400 bytes. The new results are:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Single node with no attributes: 1400 b.&lt;/li&gt;
&lt;li&gt;Single node with one attribute: 2350 b.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The additional memory may be safed by releasing the huge data that will not be used anymore, for example the template content.&lt;/p&gt;


&lt;p&gt;What do we have to remember, while using the new OPT, when it comes to the requirement issues:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;With the terribly low limits, the compiler will always crash. I thing 16 megabytes for the script (the default limit) is big enough both for the compiler and the script.&lt;/li&gt;
&lt;li&gt;The best place to run the template parsing is the end of the script. We can delete some unncessary data earlier to free some memory.&lt;/li&gt;
&lt;li&gt;The templates using the inheritance are more demanding, especially when overwriting snippets, because the compiler must keep also the old versions in the memory.&lt;/li&gt;
&lt;li&gt;The quirks mode will consume less memory (simpler tree - no XML tags), but it is not implemented yet.&lt;/li&gt;
&lt;li&gt;The compilation is run once for a long time. During the normal execution, we can forget about the limit issues etc.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I think this note shows, how difficult the library creation can be. The key is to know, what we can use in current place and that there is also the rest of the script which uses the same memory and has its own requirements.&lt;/p&gt;</description>
    
    
    
          <comments>http://blog.invenzzia.org/en/post/OPT-requirements#comment-form</comments>
      <wfw:comment>http://blog.invenzzia.org/en/post/OPT-requirements#comment-form</wfw:comment>
      <wfw:commentRss>http://blog.invenzzia.org/en/feed/atom/comments/24</wfw:commentRss>
      </item>
    
  <item>
    <title>OPT 2.0.0-dev5</title>
    <link>http://blog.invenzzia.org/en/post/OPT-200-dev5</link>
    <guid isPermaLink="false">urn:md5:33bdfac78deef21d193dfecd8a90f928</guid>
    <pubDate>Fri, 21 Mar 2008 14:38:00 +0100</pubDate>
    <dc:creator>Zyx</dc:creator>
        <category>Open Power Template</category>
        <category>components</category><category>development</category><category>OPT2</category>    
    <description>&lt;p&gt;The new development version became available a bit later that I planned, but on the other hand, I managed to add much more new things. The DTD issue is solved, as well as XML prologs, CDATA support and code escaping. The expression compiler is done and the programmers may use now brand new component implementation. This is a significant step towards the first beta release and the end is closer than further. There are only a few instructions to code, the rest is almost completed and works. The compiler, programmers' API and most of the stuff also works. I think of making the first real tests on my home website and creating the Open Power Forms library compatible with the new OPT.&lt;/p&gt;    &lt;p&gt;In the new OPT, I've redesigned the component design from scratch. It is much more flexible now and allows to make easily many interesting effects. The base rules are still the same, but the rest has changed. This is a sample code showing, how the component-based work with the forms is going to look like:&lt;/p&gt;

&lt;pre&gt;xml
&amp;lt;opt:snippet name=&amp;quot;componentView&amp;quot;&amp;gt;
  &amp;lt;com:div class=&amp;quot;field&amp;quot; invalid=&amp;quot;field error&amp;quot;&amp;gt;
    &amp;lt;p&amp;gt;{$opt.component.title}: &amp;lt;opt:display /&amp;gt;&amp;lt;/p&amp;gt;
    &amp;lt;p class=&amp;quot;desc&amp;quot; opt:if=&amp;quot;$opt.component.description&amp;quot;&amp;gt;{$opt.component.description}&amp;lt;/p&amp;gt;
    &amp;lt;opt:onEvent name=&amp;quot;error&amp;quot; message=&amp;quot;info&amp;quot;&amp;gt;
      &amp;lt;p class=&amp;quot;error&amp;quot;&amp;gt;{@info}&amp;lt;/p&amp;gt;
    &amp;lt;/opt:onEvent&amp;gt;
  &amp;lt;/com:div&amp;gt;
&amp;lt;/opt:snippet&amp;gt;

&amp;lt;div class=&amp;quot;form&amp;quot;&amp;gt;
&amp;lt;form method=&amp;quot;post&amp;quot; action=&amp;quot;skrypt.php&amp;quot;&amp;gt;

&amp;lt;opt:input name=&amp;quot;name&amp;quot; template=&amp;quot;componentView&amp;quot;&amp;gt;
   &amp;lt;opt:set name=&amp;quot;title&amp;quot; str:value=&amp;quot;Enter your name&amp;quot; /&amp;gt;
   &amp;lt;opt:set name=&amp;quot;description&amp;quot; str:value=&amp;quot;At least 3 letters&amp;quot; /&amp;gt;
&amp;lt;/opt:input&amp;gt;

&amp;lt;opt:input name=&amp;quot;surname&amp;quot; template=&amp;quot;componentView&amp;quot;&amp;gt;
   &amp;lt;opt:set name=&amp;quot;title&amp;quot; str:value=&amp;quot;Enter your surname&amp;quot; /&amp;gt;
   &amp;lt;opt:set name=&amp;quot;description&amp;quot; str:value=&amp;quot;At least 3 letters&amp;quot; /&amp;gt;
&amp;lt;/opt:input&amp;gt;

&amp;lt;opt:input name=&amp;quot;age&amp;quot; template=&amp;quot;componentView&amp;quot;&amp;gt;
   &amp;lt;opt:set name=&amp;quot;title&amp;quot; str:value=&amp;quot;Enter your age&amp;quot; /&amp;gt;
   &amp;lt;opt:set name=&amp;quot;description&amp;quot; str:value=&amp;quot;Scope: 10-99 years&amp;quot; /&amp;gt;
&amp;lt;/opt:input&amp;gt;

&amp;lt;div class=&amp;quot;foot&amp;quot;&amp;gt;&amp;lt;input type=&amp;quot;submit&amp;quot; value=&amp;quot;Send&amp;quot; /&amp;gt;&amp;lt;/div&amp;gt;
&amp;lt;/form&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/pre&gt;


&lt;p&gt;The new implementation makes use of the &lt;code&gt;opt:snippet&lt;/code&gt; instruction and template inheritance. If you had enough time, you might code the component objects, so that the field titles and descriptions will be unnecessary in the template. A component can handle events, displaying itself and its neighbourhood, managing parameters and tag attributes (we use the &lt;code&gt;com&lt;/code&gt; namespace for it). OPT contains only the component mechanism, and the components itself must be written by the end user. The reason is very simple. In order to make a useful component, we should integrate it with the input validation classes, language system, error management etc. The demands are much bigger than OPT is able and is supposed to provide. However, there will be a ready-to-use component implementation: Open Power Forms library.&lt;/p&gt;


&lt;p&gt;Unfortunately for the English manual is not started yet. Even the Polish users must use a partially-complete text, without formatting, because the new rendering system is not ready. However, we'll do everything to translate all the text together with some other materials (advices, FAQ, maybe even a tutorial?) into English, before the first final release is done. There is a team, I'll try also to ask some friends and we'll make a serious English support. Just be patient.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href=&quot;http://www.invenzzia.org/download/opt-2.0.0-dev5.tar.gz&quot; hreflang=&quot;en&quot;&gt;Download OPT-2.0.0-dev5&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;</description>
    
    
    
          <comments>http://blog.invenzzia.org/en/post/OPT-200-dev5#comment-form</comments>
      <wfw:comment>http://blog.invenzzia.org/en/post/OPT-200-dev5#comment-form</wfw:comment>
      <wfw:commentRss>http://blog.invenzzia.org/en/feed/atom/comments/21</wfw:commentRss>
      </item>
    
  <item>
    <title>OPT 2.0.0-dev4</title>
    <link>http://blog.invenzzia.org/en/post/OPT-200-dev4</link>
    <guid isPermaLink="false">urn:md5:53f051a3804ea8fd52e637f321aaa683</guid>
    <pubDate>Sun, 02 Mar 2008 11:28:00 +0100</pubDate>
    <dc:creator>Zyx</dc:creator>
        <category>Open Power Template</category>
        <category>OPT2</category>    
    <description>&lt;p&gt;There is a new Open Power Template development version available to download. The project begins to gel, as the main parser class is almost completed. Inspite of the output cache system mentioned earlier, I've implemented new instructions and completed the snippets. It means that all the template inheritance should work now. I hope the library will be usable by the end of this month. The real projects are really necessary to detect possible bugs and various shortcomings.&lt;/p&gt;    &lt;p&gt;In snippets, we have a new possibility to insert the parent content using the &lt;code&gt;opt:parent&lt;/code&gt; tag:&lt;/p&gt;

&lt;pre name=&quot;code&quot; class=&quot;xml&quot;&gt;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot; standalone=&amp;quot;yes&amp;quot; ?&amp;gt;
&amp;lt;opt:extend file=&amp;quot;test_inherited_a.tpl&amp;quot;&amp;gt;
	&amp;lt;opt:snippet name=&amp;quot;header&amp;quot;&amp;gt;
		&amp;lt;h1&amp;gt;Webmaster Of Puppets&amp;lt;/h1&amp;gt;
		&amp;lt;p&amp;gt;Here is the parent content:&amp;lt;/p&amp;gt;
		&amp;lt;opt:parent/&amp;gt;
		&amp;lt;p&amp;gt;End of the parent content&amp;lt;/p&amp;gt;
	&amp;lt;/opt:snippet&amp;gt;
&amp;lt;/opt:extend&amp;gt;
&lt;/pre&gt;


&lt;p&gt;In this case, if the &lt;em&gt;test_inherited_a.tpl&lt;/em&gt; contains another snippet with the same name, its content will be put in the place of &lt;code&gt;opt:parent&lt;/code&gt;. Such nesting works much deeper. For example, let's say that snippet also uses this tag. OPT will try to locate another parent and so on. It is even possible to put the default content of the &lt;code&gt;opt:insert&lt;/code&gt; tag, which is used to place the snippets. The code contains also a simple code to detect the infinite recursion. If the parser finds it, it returns an exception and the programmer sees a nice, red error message :).&lt;/p&gt;


&lt;p&gt;During the using of the new OPT, the new debug console should be also useful. It has been extended, compared to the similar option in OPT 1.1.x. The most significant change is splitting the list of templates to the smaller ones which show different information:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Executed templates&lt;/li&gt;
&lt;li&gt;Currently compiled templates&lt;/li&gt;
&lt;li&gt;Templates read from cache.&lt;/li&gt;
&lt;li&gt;Inherited templates - it shows all the inheritance chains, as well, as the information whether they have been recompiled or not.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Moreover, the console displays all the warnings. They are no longer put onto the screen, but available only with the debug console or error messages, if we set the proper debug level.&lt;/p&gt;


&lt;p&gt;The performance issue also looks very good. The total size of &lt;em&gt;opt.class.php&lt;/em&gt; file is about 25 KB, compared to 32 KB in the OPT 1.1.x. Currently, its size influences the performance much, as PHP must load the parser and compile it to the internal bytecode. Of course, if we parse a lot of templates, it won't be so visible, however I'm quite pleased of the effect.&lt;/p&gt;


&lt;p&gt;The package can be downloaded from &lt;a href=&quot;http://www.invenzzia.org/download/opt-2.0.0-dev4.tar.gz&quot; hreflang=&quot;en&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;</description>
    
    
    
          <comments>http://blog.invenzzia.org/en/post/OPT-200-dev4#comment-form</comments>
      <wfw:comment>http://blog.invenzzia.org/en/post/OPT-200-dev4#comment-form</wfw:comment>
      <wfw:commentRss>http://blog.invenzzia.org/en/feed/atom/comments/18</wfw:commentRss>
      </item>
    
  <item>
    <title>The main class almost finished</title>
    <link>http://blog.invenzzia.org/en/post/The-main-class-almost-finished</link>
    <guid isPermaLink="false">urn:md5:a4135d6c62812ecd599e53cd4933d0d1</guid>
    <pubDate>Fri, 22 Feb 2008 08:59:00 +0100</pubDate>
    <dc:creator>Zyx</dc:creator>
        <category>Open Power Template</category>
        <category>OPT2</category>    
    <description>&lt;p&gt;The result of the latest works on the OPT source code is complete &lt;em&gt;opt.class.php&lt;/em&gt; file which contains (as some of the readers may know) the main parser class. I must admit that this file was more demanding that the compiler. In the second case we can afford with quite a lot. Just an idea for the algorithm and prediction if and how it will influence the rest of the code. In the case of the main class, we must pay attention to the performance. It must contain everything that is run permanently and it must be fast and small. But the number of features is getting bigger and bigger.&lt;/p&gt;    &lt;p&gt;The new development version will not be compatible with the previous ones when it comes to the programming interface. To implement the output cache system, I had to rebuild almost all of the output system. In the 1.x.x series, the concept of the output system did not exist. Either the result will be seen on the screen or put into a variable, it depended on the right method choice. There were some tricky connections which redirected everything to the right place, however it was not well designed and a bit messy. Well, such things simply must happen, if we start with keeping the similarities to Smarty, and I have to remind that in the very early times, it was one of the OPT goals. In OPTv2, there is a well-declared &lt;em&gt;ioptOutput&lt;/em&gt; interface allowing the programmer to code the output processing on his own. It is also used in the implementation of output cache system. How - it is explained below.&lt;/p&gt;


&lt;p&gt;So far, there have been two output systems: &lt;em&gt;optNetOutput&lt;/em&gt; sending everything on the screen and checking, how many templates we are going to send in the XML mode. The second one was &lt;em&gt;optReturnOutput&lt;/em&gt;, which returned the result. I added a possibility to decorate them with something else and I created &lt;em&gt;optCachedOutput&lt;/em&gt;. Its only goal is to process the cache. The features are the same as in the previous versions, but the usage is a bit different and unfortunately, the initialization is more complicated:&lt;/p&gt;

&lt;pre name=&quot;code&quot; class=&quot;php&quot;&gt;$cache = new optCachedOutput('./cache/'); // this is the cache, here we configure it
$tpl -&amp;gt; register(OPT_OUTPUT, 'my_cache', $cache);
$tpl -&amp;gt; decorate(OPT_OUT_SCREEN, 'my_cache');
$tpl -&amp;gt; decorate(OPT_OUT_RETURN, 'my_cache');

if(!$cache -&amp;gt; isCached('template.tpl', 'some_id'))
{
  // data generation
}

$cache -&amp;gt; setCache(5, 'some_id'); // turn the cache on for 5 seconds
$tpl -&amp;gt; parse('template.tpl', 'my_cache');
&lt;/pre&gt;


&lt;p&gt;I'll try to shorten it and make simpler the first lines of the code, because I don't like them, too. Moreover, I must check if I've made the decoration in the right way (according to the logic).&lt;/p&gt;


&lt;p&gt;The support for plugins is not fully completed yet. The only ready part is placed in &lt;em&gt;opt.class.php&lt;/em&gt; file. The rest is moved somewhere else, which should improve the performance. Like in OPT 1.1.3, there will be a possibility to set many plugin directories, but the parser will not require them to be writeable. There were thrown some files describing the content and allowing to include everything without scanning all the directory. As we know, the more includes, the less performance and some people can produce more plugins than all the files in my framework :). The new OPT will try to link all these files into one, mega-file containing everything we need. By the way, I'll have also a new algorithm for the OPT Toolset sequel, which will be used now for all the libraries, not only OPT.&lt;/p&gt;


&lt;p&gt;The last issue concerns the available function set for the templates. Stormfly has recently written on his blog that OPT 1.1.x it was quite senseless and in fact, he was right. I took a look, what Smarty offers and it turned out that it has some nice and useful functions. The first list looks like that:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;em&gt;spacify&lt;/em&gt; - puts a string between every two neighbour characters in the text.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;indent&lt;/em&gt; - makes an indentation in the text.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;truncate&lt;/em&gt; - reduces the text to the specified length (allowing not to splitting the words)&lt;/li&gt;
&lt;li&gt;&lt;em&gt;strip&lt;/em&gt; - reduces all the white character groups to a single character&lt;/li&gt;
&lt;li&gt;&lt;em&gt;capitalize&lt;/em&gt; - equivalent to ucfirst()&lt;/li&gt;
&lt;li&gt;&lt;em&gt;upper&lt;/em&gt; - equivalent to strtoupper()&lt;/li&gt;
&lt;li&gt;&lt;em&gt;lower&lt;/em&gt; - equivalent to strtolower()&lt;/li&gt;
&lt;li&gt;&lt;em&gt;countWords&lt;/em&gt; - equivalent to str_word_count()&lt;/li&gt;
&lt;li&gt;&lt;em&gt;countChars&lt;/em&gt; - equivalent to strlen()&lt;/li&gt;
&lt;li&gt;&lt;em&gt;money&lt;/em&gt; - equivalent to money_format(), but the settings can be written in the OPT configuration.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;number&lt;/em&gt; - equivalent to number_format(), but the settings can be written in the OPT configuration.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;wordWrap&lt;/em&gt; - equivalent to word_wrap()&lt;/li&gt;
&lt;li&gt;&lt;em&gt;replace&lt;/em&gt; - equivalent to str_replace()&lt;/li&gt;
&lt;li&gt;&lt;em&gt;regexReplace&lt;/em&gt; - equivalent to preg_replace(), but the parameter order is changed.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;date&lt;/em&gt; - equivalent to date() :)&lt;/li&gt;
&lt;li&gt;&lt;em&gt;firstof&lt;/em&gt; - returns the first non-empty element from the specified ones.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;nl2br&lt;/em&gt; - equivalent to nl2br() :)&lt;/li&gt;
&lt;li&gt;&lt;em&gt;array&lt;/em&gt; - creating arrays on the template side&lt;/li&gt;
&lt;li&gt;&lt;em&gt;build&lt;/em&gt; - it was called &quot;apply()&quot; in the previous versions, but I still don't know, whether I keep this name or not.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The set contains no escaping functions, because the compiler is able to put them on his own in most of the places. There will be a possibility to escape something manually, but it won't be done through functions. Anyway, the point is the compiler must know, what is escaped. Otherwise it may add additional function call and this would produce a complete mess on the screen.&lt;/p&gt;


&lt;p&gt;To sum up, I've written so much functionality that I haven't tested all of them yet. I don't know if something works, however I don't expect any revelations. Many of the algorithms are reimplementations of the same code from OPT 1.1.x.  The next dev version will be available in the nearest days.&lt;/p&gt;


&lt;p&gt;Some statistics for the end:&lt;/p&gt;


&lt;blockquote&gt;&lt;p&gt;- &lt;em&gt;opt.class.php&lt;/em&gt; - 24 KB and still growing. In OPT 1.1.x, this file was 8 KB bigger, but offered less functionality.&lt;br /&gt;
- &lt;em&gt;opt.compiler.php&lt;/em&gt; - 65 KB and still growing.&lt;br /&gt;
- &lt;em&gt;opt.instructions.php&lt;/em&gt; - 25 KB and still growing.&lt;/p&gt;&lt;/blockquote&gt;</description>
    
    
    
          <comments>http://blog.invenzzia.org/en/post/The-main-class-almost-finished#comment-form</comments>
      <wfw:comment>http://blog.invenzzia.org/en/post/The-main-class-almost-finished#comment-form</wfw:comment>
      <wfw:commentRss>http://blog.invenzzia.org/en/feed/atom/comments/14</wfw:commentRss>
      </item>
    
  <item>
    <title>OPT 2.0.0-dev3</title>
    <link>http://blog.invenzzia.org/en/post/OPT-200-dev3</link>
    <guid isPermaLink="false">urn:md5:9843f60585ccf157ee19a973402b4cd2</guid>
    <pubDate>Fri, 15 Feb 2008 13:26:00 +0100</pubDate>
    <dc:creator>Zyx</dc:creator>
        <category>Open Power Template</category>
        <category>OPT2</category>    
    <description>&lt;p&gt;According to the my announcement from the last week, the development versions are going to appear much faster than before. This is the first of such events. The third dev of OPT 2.0.0 is ready to download. This time, I've paid much attention to the attribute processing. They can do a lot of interesting things with the tags they've been added to. The earl implementation has been ready so far - there were even examples showing the &quot;opt:section&quot; working. But to satisfy both me and probably other programmers, I had to extend it.&lt;/p&gt;    &lt;p&gt;Here are some examples showing, what can be done now. Let's start from something simple. In OPT, we use curly brackets to put expressions into a text, like:&lt;/p&gt;

&lt;pre name=&quot;code&quot; class=&quot;html&quot;&gt;text text text {$block} text text text
&lt;/pre&gt;


&lt;p&gt;There is also &lt;code&gt;opt:put&lt;/code&gt; instruction, which does the same for the first time we see it:&lt;/p&gt;

&lt;pre name=&quot;code&quot; class=&quot;html&quot;&gt;text text text &amp;lt;opt:put value=&amp;quot;$block&amp;quot;/&amp;gt; text text text
&lt;/pre&gt;


&lt;p&gt;However, it is an instruction, not curly brackets. It means we can make some nice things with it using attributes. Let's say we want to display something like &quot;Value 1 / Value 2 / Value 3&quot;. We will use &lt;code&gt;opt:put&lt;/code&gt;, a section and a separator:&lt;/p&gt;

&lt;pre name=&quot;code&quot; class=&quot;html&quot;&gt;&amp;lt;p&amp;gt;&amp;lt;opt:put value=&amp;quot;$section.value&amp;quot; opt:section=&amp;quot;section&amp;quot; str:separator=&amp;quot; / &amp;quot;/&amp;gt;&amp;lt;/p&amp;gt;
&lt;/pre&gt;


&lt;p&gt;As we see, such section affects also the tag which it was linked to and we can put the values of section elements in the attributes. The separator accepts expressions by default, but if we don't like writing &lt;em&gt;separator=&quot;'something'&quot;&lt;/em&gt; (double, and then a single quote), we can just switch the namespace to &quot;str&quot;.&lt;/p&gt;


&lt;p&gt;The implementation of reversed quotes is also ready. Compared to the previous versions, they change their function. Now it is the programmer who can give them a meaning and program them to do what he wants. It can be done by writing a simple function and giving its name to the parser. A sample use is an elegant implementation of language system a'la gettext:&lt;/p&gt;

&lt;pre name=&quot;code&quot; class=&quot;html&quot;&gt;&amp;lt;p&amp;gt;{`Some useful information...`}&amp;lt;/p&amp;gt;
&amp;lt;p&amp;gt;{`Author:`} {$author}&amp;lt;/p&amp;gt;
&lt;/pre&gt;


&lt;p&gt;This is the last of the changes. As we have an XML compiler, we need some special instructions that allow to manage the tree directly, for example by adding an attribute with a variable name. OPT is going to provide two instructions for this task: &lt;code&gt;opt:tag&lt;/code&gt; and &lt;code&gt;opt:attribute&lt;/code&gt;. The second one has been already added to the newest dev. We can use it to read the attribute name from the block:&lt;/p&gt;
&lt;pre name=&quot;code&quot; class=&quot;html&quot;&gt;&amp;lt;div&amp;gt;
  &amp;lt;opt:attribute name=&amp;quot;$some_name&amp;quot; value=&amp;quot;$some_value&amp;quot;/&amp;gt;
  body...
&amp;lt;/div&amp;gt;
&lt;/pre&gt;


&lt;p&gt;This is not the end - connected with sections, we get a powerful tool to add a lot of new attributes:&lt;/p&gt;

&lt;pre name=&quot;code&quot; class=&quot;html&quot;&gt;&amp;lt;div&amp;gt;
  &amp;lt;opt:attribute name=&amp;quot;$attr.name&amp;quot; value=&amp;quot;$attr.value&amp;quot; opt:section=&amp;quot;attr&amp;quot;/&amp;gt;
  body...
&amp;lt;/div&amp;gt;
&lt;/pre&gt;


&lt;p&gt;If we send the following table to this template: &lt;code&gt;array(0 =&amp;gt; array('name' =&amp;gt; 'class', 'value' =&amp;gt; 'dude'), array('name' =&amp;gt; 'id', 'value' =&amp;gt; 'lol'))&lt;/code&gt;, the result will be:&lt;/p&gt;

&lt;pre name=&quot;code&quot; class=&quot;html&quot;&gt;&amp;lt;div class=&amp;quot;dude&amp;quot; id=&amp;quot;lol&amp;quot;&amp;gt;
  body...
&amp;lt;/div&amp;gt;
&lt;/pre&gt;


&lt;p&gt;Unfortunately, the English manual is not started yet, but it will be ready before the first stable release.&lt;/p&gt;


&lt;p&gt;Download: &lt;a href=&quot;http://blog.invenzzia.org/en/post/&quot; hreflang=&quot;en&quot;&gt;http://www.invenzzia.org/download/opt-2.0.0-dev3.tar.gz&lt;/a&gt;&lt;/p&gt;</description>
    
    
    
          <comments>http://blog.invenzzia.org/en/post/OPT-200-dev3#comment-form</comments>
      <wfw:comment>http://blog.invenzzia.org/en/post/OPT-200-dev3#comment-form</wfw:comment>
      <wfw:commentRss>http://blog.invenzzia.org/en/feed/atom/comments/11</wfw:commentRss>
      </item>
    
  <item>
    <title>New dev</title>
    <link>http://blog.invenzzia.org/en/post/New-dev</link>
    <guid isPermaLink="false">urn:md5:a5d8cceafecfd239ba372c9cd993b8be</guid>
    <pubDate>Sat, 09 Feb 2008 11:02:00 +0100</pubDate>
    <dc:creator>Zyx</dc:creator>
        <category>Open Power Template</category>
        <category>OPT2</category>    
    <description>&lt;p&gt;The website now has the &quot;Download&quot; page. In it, you can find a new development version of Open Power Template. It also contains a simple script &quot;docgen&quot; which we use for automated generation of the DocBook manuals. The new development versions should appear now much more often than before. In case of many new features, they might appear even every 2-3 days. The reason why this was impossible in the past was the time. The process was not automated and it takes a while to prepare such archive (for example - it takes a couple of hours to publish new OPT 1.x version on the Internet).&lt;/p&gt;    &lt;p&gt;The pack contains everything I've implemented for last month:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Nearly completed sections.&lt;/li&gt;
&lt;li&gt;Separators.&lt;/li&gt;
&lt;li&gt;&quot;For&quot; and &quot;Foreach&quot; loops.&lt;/li&gt;
&lt;li&gt;Mostly completed template inheritance.&lt;/li&gt;
&lt;li&gt;HTTP header management.&lt;/li&gt;
&lt;li&gt;Partially completed prolog parser.&lt;/li&gt;
&lt;li&gt;Some fixes in the compiler.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The &quot;/dev&quot; directory contains some scripts that are used to test the new features. There are also unit tests: a complete set to test the expression parser and a part of the API test. There will be also a one to process the instructions, however the whitespace characters cause many problems, when it comes to prepare the files. If we try to compare the generated content with the expected result, we have to watch out on every space or line break. Otherwise the test fails, so you must be very patient to write a simple, stupid test. But I think this issue will be solved. To work, the tests require &quot;phpUnit 3&quot; package available in PEAR.&lt;/p&gt;</description>
    
    
    
          <comments>http://blog.invenzzia.org/en/post/New-dev#comment-form</comments>
      <wfw:comment>http://blog.invenzzia.org/en/post/New-dev#comment-form</wfw:comment>
      <wfw:commentRss>http://blog.invenzzia.org/en/feed/atom/comments/10</wfw:commentRss>
      </item>
    
  <item>
    <title>Template inheritance</title>
    <link>http://blog.invenzzia.org/en/post/Template-inheritance</link>
    <guid isPermaLink="false">urn:md5:18f9793a8c4c1405788e24861aa04ef1</guid>
    <pubDate>Sat, 02 Feb 2008 17:03:00 +0100</pubDate>
    <dc:creator>Zyx</dc:creator>
        <category>Open Power Template</category>
        <category>OPT2</category>    
    <description>&lt;p&gt;Unsually, the final HTML code of the website is composed of several smaller templates containing smaller pieces of it. There are many techniques of combining them. In PHP template engines, the most popular are two forms: manual execution of the templates from the script side and the &lt;em&gt;include&lt;/em&gt; directive. Similar solution can be found in OPT 1.x, however in the new version, it should be forgotten - unless we use the quirks mode, the parser does not let us to call the &lt;em&gt;parse()&lt;/em&gt; method more than once. In the beginning, I planned to replace it by extending inclusion with &quot;sequences&quot; - a groups of templates to include with their own variables and cache settings. However, one day I was asked on my blog by Coldpeer, whether OPT will support template inheritance. I googled for a while, I looked at it and thought it might be cool. That's how the implementation began.&lt;/p&gt;    &lt;p&gt;As far as I know, template inheritance appeared for the first time in the Python framework, Django. The idea is taken from the object oriented programming, where we can extend classes by adding new methods, fields and overwriting the existing ones. Here it looks similar. We have a main template where we mark some characteristic places and fill them with a default content. Another template extends the main one and is able to overwrite that places with its own content. There can go the next template, and next...&lt;/p&gt;


&lt;p&gt;I was quite surprised that a lot of required functionality already exists in OPT 1.x - the &lt;em&gt;bind&lt;/em&gt; and &lt;em&gt;insert&lt;/em&gt; instructions allowed to move whole template parts somewhere else (as well as their functionality, not only the result, like in Smarty's &lt;em&gt;capture&lt;/em&gt;), even if the destination was in the other template. Unfortunately, there was no proper detection, whether one of the files was modified, so unsually the parser decided that the main part needs to be compiled, but the template with snippet definitions - does not. As a result, the places remained empty, although they should not. The development of such system for OPT 2.0 was quite complicated. You do not have to check just the template you've called, whether it is modified. You must also look at all the templates it inherits. Yesterday, I decided to solve this problem definietly and a couple of hours ago everything seemed to work properly:&lt;/p&gt;


&lt;p&gt;The base template (&lt;em&gt;test_inherited_a.tpl&lt;/em&gt;):&lt;/p&gt;
&lt;pre name=&quot;code&quot; class=&quot;html&quot;&gt;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot; standalone=&amp;quot;yes&amp;quot; ?&amp;gt;
&amp;lt;!DOCTYPE html PUBLIC &amp;quot;-//W3C//DTD XHTML 1.0 Transitional//EN&amp;quot;
	   &amp;quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&amp;quot;&amp;gt;

&amp;lt;html xmlns=&amp;quot;http://www.w3.org/1999/xhtml&amp;quot; lang=&amp;quot;en_US&amp;quot; xml:lang=&amp;quot;en_US&amp;quot;&amp;gt;
 &amp;lt;head&amp;gt;
  &amp;lt;title&amp;gt;Instruction test: snippet and insert&amp;lt;/title&amp;gt;
 &amp;lt;/head&amp;gt;
 &amp;lt;body&amp;gt;
  &amp;lt;opt:insert snippet=&amp;quot;header&amp;quot;&amp;gt;
   &amp;lt;h1&amp;gt;I'm a standard header&amp;lt;/h1&amp;gt;
   &amp;lt;p&amp;gt;Foo bar joe&amp;lt;/p&amp;gt;  
  &amp;lt;/opt:insert&amp;gt;
  
  &amp;lt;hr/&amp;gt;
  
  &amp;lt;opt:insert snippet=&amp;quot;content&amp;quot;&amp;gt;
  	&amp;lt;p&amp;gt;Well, i'm also a standard content.&amp;lt;/p&amp;gt;
  
  &amp;lt;/opt:insert&amp;gt;
  
  &amp;lt;hr/&amp;gt;
  
  &amp;lt;opt:insert snippet=&amp;quot;footer&amp;quot;&amp;gt;
  	&amp;lt;p&amp;gt;And I'm a footer.&amp;lt;/p&amp;gt;  
  &amp;lt;/opt:insert&amp;gt;
  
  &amp;lt;p&amp;gt;&amp;amp;copy; Pasteright 2008 by LMAO, It seems to work!&amp;lt;/p&amp;gt;
 &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/pre&gt;


&lt;p&gt;The extending template (&lt;em&gt;test_inherit_1.tpl&lt;/em&gt;):&lt;/p&gt;

&lt;pre name=&quot;code&quot; class=&quot;xml&quot;&gt;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot; standalone=&amp;quot;yes&amp;quot; ?&amp;gt;
&amp;lt;opt:extend file=&amp;quot;test_inherited_a.tpl&amp;quot;&amp;gt;
	&amp;lt;opt:snippet name=&amp;quot;header&amp;quot;&amp;gt;
		&amp;lt;h1&amp;gt;Webmaster Of Puppets&amp;lt;/h1&amp;gt;
	&amp;lt;/opt:snippet&amp;gt;

	&amp;lt;opt:snippet name=&amp;quot;content&amp;quot;&amp;gt;
		&amp;lt;p&amp;gt;Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Phasellus ut tellus id nulla adipiscing eleifend. Sed dictum accumsan ante. Nullam at nisl vitae elit aliquet fringilla. Praesent egestas eros eget tellus. Praesent id odio a sapien rhoncus vehicula. Nunc fringilla, diam eget euismod tempor, tortor metus tincidunt sapien, eu cursus magna tellus at risus. Praesent non tellus eget magna facilisis pulvinar. Praesent libero mi, adipiscing a, pharetra eget, condimentum sodales, mi. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos hymenaeos. Donec ac elit. Duis iaculis tortor a metus. Aliquam id purus et eros faucibus fringilla. Praesent quis quam. In lectus urna, fringilla sit amet, iaculis eget, aliquet ac, quam. Donec vulputate dui sit amet lectus. Aenean tempor, orci at pretium ornare, tortor tortor venenatis ligula, eget blandit nisi risus eget dolor. Duis nunc neque, sodales porta, viverra non, tristique eu, sem. Curabitur magna neque, blandit ullamcorper, congue quis, tristique ut, felis.&amp;lt;/p&amp;gt;
	&amp;lt;/opt:snippet&amp;gt;

	&amp;lt;opt:snippet name=&amp;quot;footer&amp;quot;&amp;gt;
		&amp;lt;p&amp;gt;Bye!!!&amp;lt;/p&amp;gt;
	&amp;lt;/opt:snippet&amp;gt;
&amp;lt;/opt:extend&amp;gt;
&lt;/pre&gt;


&lt;p&gt;Some PHP code:&lt;/p&gt;

&lt;pre name=&quot;code&quot; class=&quot;php&quot;&gt;&amp;lt;?php

	define('OPT_DIR', '../lib/');
	require(OPT_DIR.'opt.class.php');

	try
	{
		$tpl = new optClass;
		$tpl -&amp;gt; sourceDir = './templates/';
		$tpl -&amp;gt; compileDir = './templates_c/';
		$tpl -&amp;gt; stripWhitespaces = false;
		$tpl -&amp;gt; printComments = false;
		$tpl -&amp;gt; setup();
		
		$tpl -&amp;gt; parse('test_inherit_1.tpl');
	}
	catch(optException $e)
	{
		optErrorHandler($e);
	}
?&amp;gt;
&lt;/pre&gt;


&lt;p&gt;And the result can be admired below:&lt;/p&gt;


&lt;p&gt;&lt;a href=&quot;http://blog.invenzzia.org/public/images/template_inheritance.png&quot;&gt;&lt;img src=&quot;http://blog.invenzzia.org/public/images/.template_inheritance_m.jpg&quot; alt=&quot;Template inheritance&quot; style=&quot;display:block; margin:0 auto;&quot; /&gt;&lt;/a&gt;&lt;/p&gt;


&lt;p&gt;Some facts:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;If we modify any of the templates in the inheritance chain, the parser will notice it and recompile proper files.&lt;/li&gt;
&lt;li&gt;If we remove any of &quot;opt:snippet&quot; instructions, the default content of &quot;opt:insert&quot; will be displayed.&lt;/li&gt;
&lt;li&gt;There is a possibility to overwrite an existing snippet by the more important template. You will be also able to call the parent content, however it is not implemented yet (some kind of &quot;opt:parent&quot; instruction).&lt;/li&gt;
&lt;li&gt;It can be mixed with &quot;opt:include&quot; and &quot;opt:sequence&quot; (the sequence system briefly mentioned in the introduction).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;What is more, it's quite possible that the template inheritance will work faster than traditional way, although it will consume more disk space. Simply, if we have an inheritance like this: &quot;A extends  B extends C&quot;, the compiler puts all their code in the file belonging to the &quot;A&quot; template. It reduces the amount of disk operations (the execution of one bigger template is faster than the same content in five files). On the other hand, by default OPT still checks the file modification times, but fortunately, the number of tests is also smaller. The exact results will be available, when some benchmarks are done. Before we end, I'll say that two days ago I made a small test (a simple list with 15 items). The result:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;OPT 1.x: 1850 req/s&lt;/li&gt;
&lt;li&gt;OPT 2.0: 2100 req/s&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Well, it looks promising, but we have to remember that the new &lt;em&gt;opt.class.php&lt;/em&gt; file still does not have half of the options, which obviously will increase its size. Moreover, some optimizations are not implemented yet. But in fact, you can assume that the new features should not destroy the performance, and there is a chance that it will be even better.&lt;/p&gt;</description>
    
    
    
          <comments>http://blog.invenzzia.org/en/post/Template-inheritance#comment-form</comments>
      <wfw:comment>http://blog.invenzzia.org/en/post/Template-inheritance#comment-form</wfw:comment>
      <wfw:commentRss>http://blog.invenzzia.org/en/feed/atom/comments/6</wfw:commentRss>
      </item>
    
  <item>
    <title>Deeper processing</title>
    <link>http://blog.invenzzia.org/en/post/Deeper-processing</link>
    <guid isPermaLink="false">urn:md5:d6abe77b1e5105e2840bb0cc54643046</guid>
    <pubDate>Thu, 31 Jan 2008 13:42:00 +0100</pubDate>
    <dc:creator>Zyx</dc:creator>
        <category>Open Power Template</category>
        <category>OPF</category>    
    <description>&lt;p&gt;The last project I've created using Open Power Forms, shown some weaknesses of the current form implementation. There were some forms allowing a mass addition of many records in the following way: a table, in the columns the following fields: Name, Surname, PESEL number, etc. The numer of rows was 30, so the user is able to add 30 people to the database with one form. The adaptation of the &lt;em&gt;map()&lt;/em&gt; method to my problem was not too hard; in fact it seemed that &lt;em&gt;opfArrayContainer&lt;/em&gt; solved everything. But then the form renderer connected with Open Power Template went off.&lt;/p&gt;    &lt;p&gt;My code looked like that:&lt;/p&gt;

&lt;pre&gt;php
$this -&amp;gt; map('names', new opfArrayContainer(
	new opfConstraint(MAP_TYPE, TYPE_STRING),
	new opfConstraint(MAP_LEN_GT, 2)
), OPF_OPTIONAL);
$this -&amp;gt; map('surnames', new opfArrayContainer(
	new opfConstraint(MAP_TYPE, TYPE_STRING),
	new opfConstraint(MAP_LEN_GT, 2)
), OPF_OPTIONAL);
$this -&amp;gt; map('pesels', new opfArrayContainer(
	new sConstraint(MAP_PESEL)
), OPF_OPTIONAL);
&lt;/pre&gt;


&lt;p&gt;In other words, the script must have received for example the &quot;names&quot; field, which was an array of 30 elements with the names. If the user made a mistake while filling in the form, the form renderer did not have a clue, which component to display as invalid (in this case it should be colored red instead of green). Finally, I added a support for the &lt;em&gt;IGNORE_OPF_ERRORS&lt;/em&gt; constant so that shut it up and just display everything without all this color rotation stuff.&lt;/p&gt;


&lt;p&gt;Of course, it is not possible to keep this problem unsolved in the &quot;public&quot; releases and I decided to look for solution. It would be nice, if the improvement easily matched to the code, as well as was intuitive. It's not a problem to add something in 20 minut and a month later self-wishing a rapid death. The best solutions are simple and effective, so I started to think, how to describe a form with some definitions and transformations, so that it would be possible to construct every form and process it with OPF. My idea is to go somewhere deeper and remove distinguishing between forms and form elements. The reasons:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Both have a value (in the form case we define it as a set of subelement values).&lt;/li&gt;
&lt;li&gt;Both have a state.&lt;/li&gt;
&lt;li&gt;Both can be processed.&lt;/li&gt;
&lt;/ol&gt;
&lt;pre&gt;&lt;/pre&gt;

&lt;p&gt;Now we can easily treat a form as an element which is capable of storing other fields. If we try to build our form described above, it will look like this: we create a form for a single person: name, surname, PESEL, etc. Next, we put it into a bigger form and order to loop up to 30 times. We can also achieve an effect of looping a single field, like it was possible with &lt;em&gt;opfArrayContainer()&lt;/em&gt; so far. We just put in such loop not a form, but a single element.&lt;/p&gt;


&lt;p&gt;Well, now the problem is, how to render it :). However, I don't think it will be complicated, especially if I look at the new Open Power Template.&lt;/p&gt;</description>
    
    
    
          <comments>http://blog.invenzzia.org/en/post/Deeper-processing#comment-form</comments>
      <wfw:comment>http://blog.invenzzia.org/en/post/Deeper-processing#comment-form</wfw:comment>
      <wfw:commentRss>http://blog.invenzzia.org/en/feed/atom/comments/3</wfw:commentRss>
      </item>
    
</channel>
</rss>