Montag, 16. August 2010

Joomla template development using Ant

My personal 3 Problems developing Joomla templates

First it is necessary to maintain a file called templateDetails.xml. In this file you have to define all the files used by the template. Adding a picture means adding this picture to the list of files. If you forget to do so, the file is not installed which results in template bugs.
Second building the template package means creating a zip file. This is like creating a jar file - who would want to do it using a file manager and a zip tool?
Last but not least it is not possible to reinstall a template. Once installed, you have to uninstall it prior to installing the new version of the template. Who would like to do this every time a css file changed? So most people are using a ftp client like FileZilla which supports "online file edit" or directory synchronization. In my case this means opening files with FileZilla, not with eclipse. DO NOT forget to sync them back!

Ant to the rescue

I spent some time and created a custom ant task and a build script using the ftp sync feature built into ant. The custom ant task is responsible for maintaining the file list of the templateDetails.xml. It scans the template directory recursively and replaces the files section with the results. You can download it here. You can find the source code included in the jar file. I don't want to include those ugly lines doing their dirty job in this article.
The ant build script is quite simple:

<?xml version="1.0" encoding="UTF-8"?>
<project name="MyKewlTemplate" default="myKewlTemplate">
 <target name="refreshFileList">
  <taskdef name="TemplateDetailsGenerator" classname="de.rhauswald.ant.joomla.TemplateDetailsGenerator" classpath="ant/TemplateDetailsGenerator.jar" />
  <TemplateDetailsGenerator templatedirectory="myKewlTemplate" />

 <target name="clean">
  <delete file="build/" />

 <target name="myKewlTemplate" depends="clean">
  <antcall target="refreshFileList" />
  <zip destfile="build/" basedir="myKewlTemplate" />

 <!-- include apache commons-net into  ant lib directory-->
 <target name="sync">
  <antcall target="refreshFileList" />
  <ftp password="XXX" server="XXX" userid="XXX" passive="true" newer="true" remotedir="templates/myKewlTemplate" verbose="true" binary="true">
   <fileset dir="myKewlTemplate">
Now my three problems are solved: The file list is auto generated before every build(ftp sync or zip). I can build the installation zip file with just one click. The ftp sync works like a charm. Change something, click the build button and ant uploads the changes only. In case I add a background picture and the proper lines to the css file a click at the build button does the following:
  1. Add the new picture to the file list
  2. Upload the templateDetails.xml file
  3. Upload the picture
  4. Upload the css file
I can concentrate on writing div boxes and css now...

Keine Kommentare:

  © Blogger template 'Morning Drink' by 2008

Back to TOP