$$

</h1> <contents/> </div> </slide> <contents> <sep_/> <slide title="What I wanted"> <ul> <li>a static site: easy to deploy, less security problems,</li> <li>handling of blog posts, with dates, topics, keywords and associated RSS feeds,</li> <li>dynamic comments for blog posts (⇒ using Disqus),</li> <li>no new syntax,</li> <li>using custom tags (e.g. <icode>section</icode>) to provide semantics in code,</li> <li>avoid code duplication,</li> <li>ability to use all HTML5 or any XML,</li> <li>check internal references,</li> <li>displaying evaluated OCaml code,</li> <li>support for multiple languages (fr, en, ..),</li> <li>ability to add specific features with plugins.</li> </ul> </slide> <slide title="How it works"> <p> Three steps: </p> <ol> <li>Read configuration file <icode>.stog/config</icode> and directory tree: <hcode lang="ocaml" defer_="1"><include raw="true" file="../.stog/config"/></hcode> </li> <li>Handle "elements",</li> <li>Copy other files, i.e. files not ignored and not elements. </li> </ol> </slide> <slide title="Step 2: handling "elements""> <div class="center"> <object data="how_it_works.svg" type="image/svg+xml" width="90%" title="Handling element files"> <img src="how_it_works.png" width="90%" alt="Handling element files" /> </object> </div> </slide> <slide title="Step 3: copying other files"> <div class="center"> <object data="how_it_works2.svg" type="image/svg+xml" width="90%" title="Handling other files"> <img src="how_it_works2.png" width="90%" alt="Handling other files" /> </object> </div> </slide> <slide title="Example of element"> <p>Example: file <icode>doc.html</icode> from Stog's web site: </p> <hcode lang="xml" defer_="1"> <include raw="true" file="../doc.html"/> </hcode> </slide> <slide title="Another example of element"> <p>Example: file <icode>posts/release-0.7.0.html</icode> from Stog's web site: </p> <hcode lang="xml" defer_="1"> <include raw="true" file="../posts/release-0.7.0.html"/> </hcode> </slide> <slide title="Templates (1)"> <p> Templates are regular XML documents, with some XML nodes which will be rewritten. </p> <p>Templates are in the <icode>.stog/templates/</icode> directory.</p> <p>A template can be used in three ways:</p> <ul> <li>according to an element type, this type being the root node tag of the element: <hxml><page title="...">...</page></hxml> <hxml><post title="...">...</post></hxml> <icode>page</icode> will result in using the <icode>.stog/template/page.tmpl</icode> file has template for the element (and <icode>post.tmpl</icode> for <icode>post</icode> element). </li> <li>referenced in the <ixml>file</ixml> attribute of a <ixml><![CDATA[<include file="..."/>]]></ixml> node,</li> <li>used by other rewrite rules.</li> </ul> </slide> <slide title="Templates (2): Example"> <p> The template file <icode>.stog/templates/page.tmpl</icode>: </p> <hxml><include file="page.tmpl" raw="true"/></hxml> </slide> <slide title="Templates (3): Example (2)"> <p> The template file <icode>.stog/templates/elt-in-list.tmpl</icode>: </p> <hxml><include file="elt-in-list.tmpl" raw="true"/></hxml> </slide> <slide title="Rewrite rules"> <p> An environment is a map associating tag names to rules. We note <lx>\Gamma(t) = f</lx> to say that a function <lx>f</lx> is associated to the tag <lx>t</lx> in the environment <lx>\Gamma</lx>. If no function is associated to <lx>t</lx>, then <lx>\Gamma(t) = \bot</lx>. </p> <p> A rule is a function <lx>$f$</lx> taking in parameters: an environment <lx>$\Gamma$</lx>, a list of XML node attributes <lx>$l_a$</lx>, a list of XML (sub)nodes <lx>$l_{xml}$</lx>. A rule, when applied, returns a list of XML nodes. </p> <p> Let <lx>\mathcal{R}(\Gamma, n)</lx> be the function applying an environment <lx>\Gamma</lx> to an XML node <lx>n = (t, l_a, l_{xml})</lx>. <lx>\mathcal{R}_l(\Gamma, l)</lx> applies <lx>\mathcal{R}(\Gamma, x)</lx> on each element <lx>x</lx> of the list <lx>l</lx>. The algorithm of <lx>\mathcal{R}</lx> is the following: </p> <ol> <li>Apply <lx>\mathcal{R}</lx> on each attribute value, parsed as valid XML, to get a new list of rewritten attributes <lx>l_a'</lx>, </li> <li> If <lx>\Gamma(t) = \bot</lx>, then return [<lx>(t, l_a', \mathcal{R}_l(Gamma, l_{xml}))</lx>].<br/> Else, with <lx>\Gamma(t) = f</lx>, return <lx>f(\Gamma, l_a', l_{xml})</lx>. </li> </ol> <p><lx>\mathcal{R}</lx> is called until a fixpoint is reached.</p> <p> This rewrite engine is implemented in the <ext-a href="http://zoggy.github.com/xtmpl/">Xtmpl</ext-a> library. </p> </slide> <slide title="Rewrite rules (2)"> <p> When we define an element, we're defining an environment <lx>\Gamma</lx>. </p> <p>Example: consider the following element:</p> <hxml><page title="Example page" author="Maxence Guesdon"> This is the body of my page </page></hxml> <p> Here we defined an environment <lx>\Gamma</lx> with the following rules: </p> <ul> <li><lx>\Gamma("elt-title") = f_1</lx> with <lx>f_1(\_,\_,\_) =</lx> [ "Example page" ]</li> <li><lx>\Gamma("author") = f_2</lx> with <lx>f_2(\_,\_,\_) =</lx> [ "Maxence Guesdon" ]</li> <li><lx>\Gamma("elt-body") = f_3</lx> with <lx>f_3(\_,\_,\_) =</lx> [ "This is the body of the page" ]</li> </ul> <p> To <strong>compute</strong> the element's final XML, we apply this environment to the template associated to the page type. </p> <p>Remarks:</p> <ul> <li>Of source, the initial environment is not empty. So defining an element adds rules to this initial environment. </li> <li> Predefined rules and user-defined rules can be more complex. </li> </ul> </slide> <slide title="The main element"> <p> One of the element must be marked has "main", with a <ixml>main="true"</ixml> attribute. This is usually the top <icode>index.html</icode> file but this is not mandatory. </p> <p> The main element is the place to define rules for the initial environment. These rules are defined using the <icode>stog:</icode> prefix (like an XML namespace). Defining <icode>stog:foo="bar"</icode> will make this rule appear in the initial environment with the name "foo". </p> <hxml><![CDATA[<page main="true" title="Stog" stog:site-description="Static blog and web site generator" stog:site-email="zoggy 'AT' bat8 'DOT' org" stog:site-url="http://zoggy.github.com/stog" stog:rss-length="10" navbar-home="active" > .... </page>]]></hxml> </slide> <slide title="A powerful rule: <icode>&lt;eval-ocaml&gt;</icode>"> </slide> <slide title="Templates + rewrite rules = not enough!"> </slide> <slide title="Levels of rewrite rules"> </slide> <slide title="Functions"> </slide> <slide title="Plugins"> </slide> <slide title="Existing plugins"> </slide> <slide title="Modules"> </slide> </contents> </slideshow>