CppCMS Blog :: Templates http://blog.cppcms.com/ A blog on CppCMS - C++ Web Development Framework New templates in trunk http://blog.cppcms.com/post/30 http://blog.cppcms.com/post/30 <div style="direction:ltr"> <p>New templates branch finally merged to trunk.</p> <p>This blog is now running on new templates system. Please, inform me in case of any problems.</p> <p>Thanks.</p> </div> Preparing to Beta 2... http://blog.cppcms.com/post/29 http://blog.cppcms.com/post/29 <div style="direction:ltr"> <p>What expected in the next beta version:</p> <ol> <li><p>Now CppCMS is really ready for serving high load sides, thanks to new distributed cache module based on Boost.Asio.</p> <p> Several CppCMS processes running on different computers can share same cache distributed over several TCP/IP cache servers.</p></li> <li>Staticly typed template system that fully integrated with the framework that allows: <ul> <li>"Django style" template inheritance.</li> <li>Powerful extendsions abilities using C++ code directly.</li> <li>Static compilation with generated templates code or loading templates as external shared objects.</li> <li>Creates a potential for future "forms/widgets" integration.</li> </ul> </li> <li>Various bugfixes and code cleanup.</li> </ol> <p>Possibly included: form validation and generation modules.</p> <p>to be Continued...</p> </div> Thoughts about template system http://blog.cppcms.com/post/26 http://blog.cppcms.com/post/26 <div style="direction:ltr"> <p>After looking how ASP.Net and J2EE work I thought a lot about current template system.</p> <p>Today, CppCMS template system is dynamic typed. For example in order to render template:</p> <pre><code>&lt;% template mycontent %&gt; &lt;p&gt;You have &lt;% number %&gt; of &lt;% something %&gt;&lt;/p&gt; &lt;% end %&gt; </code></pre> <p>I write something like that (not correct code but idea):</p> <pre><code>map&lt;boost::any&gt; content; content["something"]=string("orange");‎ content["number"]=10; template.render(content,output); </code></pre> <p>The template is compiled to bytecode and than interpreted in rendering engine. If variable <code>title</code> required it checks its type and renders its content.</p> <p>Another possible approach it to make is statically typed :</p> <p>So, I create a view interface for template:</p> <pre><code>struct mycontent: public content { string something; int number; }; </code></pre> <p>And then the above template is compiled to following C++ code:</p> <pre><code>void mycontent::render() { cout&lt;&lt;"&lt;p&gt;You have "&lt;&lt;number&lt;&lt;" of "&lt;&lt;escape(something)&lt;&lt;"&lt;/p&gt;\n"; } </code></pre> <p>That is compiled to shared object that I can load dynamically. And render template as following:</p> <pre><code>auto_ptr&lt;my_content&gt; content(template.get("my_content")); content-&gt;number=10; content-&gt;something="orange"; content-&gt;render(output); </code></pre> <p> <a href="/post/26">more...</a> </p> </div> Thread Safe Implementation of GNU gettext http://blog.cppcms.com/post/16 http://blog.cppcms.com/post/16 <div style="direction:ltr"> <p>There is widely available software internationalization tool called <a href="http://www.gnu.org/software/gettext/">GNU gettext</a>. Is is used as base for almost all FOSS software tools. It has binding to almost every language and supports many platforms including Win32.</p> <p>How does it works? In any place you need to display a string that may potentially show in other language then English you just write:</p> <pre><code>printf(gettext("Hello World\n")); </code></pre> <p>And you get the required translation for this string (if available).</p> <p>In 99% of cases this is good enough. However, as you can see, there is no parameter "target language". It is defined for entry application.</p> <p>What happends if you need to display this string in different languages? You need to switch locale, and this operation is not thread safe. In most of cases you <em>do not</em> need to do this, because almost all applications will "talk" in single language that user had asked. However this is not the case of web based applications.</p> <p>Certain web application allow you to display content in several languages: think of government site that should display information in three languages: Hebrew, Arabic and English. So you may need to define the translation per each session you open or use.</p> <p>So, if you write a multithreaded FastCGI application that supports different languages is <em>signle</em> instance you can't use gettext.</p> <p> <a href="/post/16">more...</a> </p> </div> The Roadmap to The First Beta Version of CppCMS http://blog.cppcms.com/post/15 http://blog.cppcms.com/post/15 <div style="direction:ltr"> <p>After quite a long period of development I had decided to get prepared to first public beta release of CppCMS.</p> <p>The major components of this blog and the framework I want to introduce in first beta are following:</p> <ul> <li>Implementation of Django style templates inheritance, filters (done 70%)</li> <li>Introduce powerful cache system (done 100%)</li> <li>Replace <a href="http://soci.sourceforge.net">SOCI</a> by <a href="http://libdbi.sourceforge.net">LibDBI</a> (done 100%)</li> <li>Improve blog: true markdown, LaTeX equations, categories etc. (done 100%)</li> <li>Write Documentation (done 20%)</li> <li>Migrate my Hebrew blog from Word Press to CppCMS (done 100%)</li> </ul> <p>There are lots of work to do, but CppCMS now looks much mature then before.</p> <p> <a href="/post/15">more...</a> </p> </div> New Templates System http://blog.cppcms.com/post/14 http://blog.cppcms.com/post/14 <div style="direction:ltr"> <p>New templates system was introduces to the CppCMS framework. It is based on ideas of dynamic typed languages inside static typed C++.</p> <p>The original template system had several problems:</p> <ol> <li>The each template variable was referenced by and integer key that was generated during compilation of templates.</li> <li>The rendering process required from the developer some kind of activity -- update content values according to requests from rendering engine.</li> <li>The values of the entries where limited to string, integer and boolean values.</li> </ol> <p>In any case, the design of the first template system was just unacceptable, thus new template system was build.</p> <p>It introduced following features:</p> <ul> <li>Dynamic typed variable values using boost::any. They allow assigning of any kind of objects to the variables and rendering them to the templates using custom engines.</li> <li>All the variables are references by their names.</li> <li>Content now has hierarchical structure when each variable can include list of items or callbacks that allow one step template rendering.</li> <li>The design of the engine is now much more modular.</li> </ul> <p>Additional features I'm still working on them are:</p> <ul> <li>Support of different filters like "html escaping", "urlizing" etc.</li> <li>Support of custom filters, including filter chains.</li> <li>Support of localization and translation.</li> </ul> <p> <a href="/post/14">more...</a> </p> </div> Next Step - Caching http://blog.cppcms.com/post/7 http://blog.cppcms.com/post/7 <div style="direction:ltr"> <p>As we had seen in previous article, the <a href="http://art-blog.no-ip.info/cppcms/blog/post/4">benchmarks</a> had shown an ability of CppCMS to produce about 630 compressed pages per second and an output of about 20Mbit/s. Is this enough?</p> <p>For most of cases it is... But as we had seen I want to use every cycle of the CPU as smart as I can. Even, if the model I had suggested, was able to show "a prove of concept" there is an important point that was missed: "Why should I create same page so many times?"</p> <h2>Caching</h2> <p>This is the next logical step in the development of high performance web development framework.</p> <p>First of all we should understand a requirements of the caching system:</p> <ol> <li>Efficiency</li> <li>Support of "dropping cache on update"</li> <li>Support of drop the cache by timeout</li> <li>Work using three models: single process cache, shared cache between processes, shared over the network.</li> <li>Support of caching on entry page level and single view level as well</li> <li>Transparent storage of compressed content</li> </ol> <p>Lets describe each one of them:</p> <p> <a href="/post/7">more...</a> </p> </div> Components of CppCMS http://blog.cppcms.com/post/3 http://blog.cppcms.com/post/3 <div style="direction:ltr"> <p>There are several important components that CppCMS implements:</p> <ol> <li>FastCGI Application Framework</li> <li>Easy Berkeley DB -- Simple API to BDB</li> <li>Templates System</li> <li>Text Tools -- text to html conversion tools</li> <li>Nice URLs support</li> </ol> <p>I'll describe there all these in details there</p> <p> <a href="/post/3">more...</a> </p> </div>