Introduction
In a moment of weakness, I promised a couple of friends to take care of their web site. At first, it was a very small site but it kept on growing, and the time it took me to keep it up to date grew with it. The first thing that took time was to get all the internal links right when pages were moved around within the site. The second thing was updating the meta-data in an ever growing number of pages.
I needed a tool. There are, of course, a number of tools to be found but they where either too limited or too complex. So I decided to write my own. I didn't mind because writing a small piece of software like this is an excellent opportunity to learn new techniques. The first version was written in Java using Tomcat, Struts, and the Freemarker template library. The second version, this one, is written in C#, using the Ader Template Engine and an XML-file with data about the site.
Description
- The program first copies all relevant files from the data directory to the web directory.
- Secondly, it loads the main.template into the Ader TemplateManager.
- It then iterates through the
<page>
-tags in the XML-file, loading code-snippets into the main.template. - The expanded template is copied to the Web directory as an HTML-file.
The XML-file
="1.0"="iso-8859-1"
<fsm>
<init item="DataDir" path="C:/My Documents/mysite"/>
<init item="WebDir" path="C:/Inetpub/wwwroot"/>
<init item="ExcludeExtensions" path=".template;.scc"/>
<pages>
<page path="/demo/pages">
<link text="About my site" path="/demo/pages" page="intro_main.html"/>
<link text="Info" path="/demo/pages" page="info_main.html"/>
<banner text=""/>
<banner text="Links"/>
<link text="More" path="/demo/pages/more" page="intro.html"/>
<link text="Even more" path="/demo/pages/more" page="info.html"/>
</page>
<page path="/demo/pages/more">
<link text="About my site" path="/demo/pages" page="intro_main.html"/>
<link text="Info" path="/demo/pages" page="info_main.html"/>
<banner text=""/>
<banner text="More Links"/>
<link text="More" path="/demo/pages/more" page="intro.html"/>
<link text="Even more" path="/demo/pages/more" page="info.html"/>
</page>
</pages>
</fsm>
Using the Ader TemplateManager
- Create a reference to the class
Constants
. This class has only static methods. - Create a reference to the present node.
- Iterate through the links and banners.
See the Ader TemplateEngine for an explanation of the syntax.
<ad:set name="Constants" value="#createtypereference("Constants")#" />
<ad:set name="node" value="#xml#" />
<ad:if test="#Constants.GetData("Path") is
node.Attributes.GetNamedItem("path").Value #">
<ad:foreach collection="#node.ChildNodes#" var="link">
<ad:set name="attrs" value="#link.Attributes#" />
<ad:if test="#link.Name is "link" #">
<a href="#attrs.GetNamedItem("path").Value#/
#attrs.GetNamedItem("page").Value#"
class="menu">#attrs.GetNamedItem("text").Value#</a><br>
<ad:elseif test="#link.Name is "banner" #">
<b> #attrs.GetNamedItem("text").Value#</b><br>
</ad:if>
</ad:foreach>
</ad:if>
Links of interest
History
- 2006-02-02 - Version 1.0.
I work as a developer in the 'Risk control' department at SEB bank in Stockholm,Sweden and I have been designing software since the early 80's.