How to overengineer a simple web site

In several easy steps! (hopefully in some manner this will prove helpful to users of jython and freemarker in the future)

  1. The beginning
  2. Use a template engine to simplify site maintenance
  3. Create a semi-automatic scoring system
  4. Choose a different templating engine
  5. Take stock of what you’ve done

In the beginning, agree to be the “webmaster” of one’s local kickball division – simple an non-timeconsuming task given that the site has a handful of pages with static content, and one must update the standings and scores every week. Decide the site is an excellent opportunity to learn CSS layout. Spend an order of magnitude of time more to get the site up than it would have taken to throw up some 1997-style table layout.

Now the site is up and running – decide that since the same header and footer are on every page, it would make sense to use some kind of templating system (note: the site is static content only) to make it easier to add new sections, should the need arise. Consider various client driven solutions: Dreamweaver (too expensive), Nvu (generates crappy HTML, crashes, slow). Consider rolling your own, since all you need are static includes. Discard that idea.

Look at open source templating engines. Decide that you really want to have an ant script that will magically assemble the site (and who knows, maybe one day even upload it for you too!). Decide to use Velocity. Play with Texen for a while, but decide you really need its big sister vpp. Learn the syntax, get the gazillion jar dependencies downloaded and copy and paste the web pages into easy to manage chunks and get the includes working. Wa-lah! Now the website can be regenerated by a simple ant task – take this opportunity to add a photos section because its suddently really easy to do.

Now you’re in the promised land – no more editing 6 different files to change the menus! You can sit back, crack open a beer, life is good. But no – it irks you that you’re managing the score via a way-too-manual process involving an elaborate Excel spreadsheet and typing at least 2 different places. You’re a software engineer, you can do better than this. (Note: this decision is best made when you have a new full-time job and your Theory of Computation grad-class is taxing your time).
Spend T-rides brainstorming how best to represent the structure of the league, with teams, game schedule, results- of course you’d want it to be validating. Discard that effort when you have a brainwave – just represent the state of the league in jython script – you were going to process the XML in jython anyways after sleeping off the delusional fantasy of using XSLT. Cut out the middleman, mere mortals don’t need to edit this stuff!
Cut to creating a set of objects for your domain objects. You need your teams:
class Team:
def __init__(self,teamName,teamAbbrev,shirtColor):
self.name = teamName;
self.shirtColor = shirtColor;
self.abbrevName = teamAbbrev;

Some games:
class Game:
def __init__(self,time,field,team1,team2,refs):

Get the whole messy code here (note it doesn’t handle forfeits yet).
Throw in some other classes and some logic, now you’ve got a half-assed scoring system! Data entry is totally a breeze, I mean look at this, total user friendliness:
day2 = Day("9/8/2005",ppe,ppe)
week1.addDay(day2)
game = Game("8:00","A",baggers,ppe,freeballers)
game.addResult(Score({baggers:4,ppe:2}))
day2.addGame(game)
game = Game("8:00","B",spanking,ballsdeep,gentree)
game.addResult(Score({spanking:2,ballsdeep:2}))
day2.addGame(game)

Get the season so far here.
Great! Now we just wire that up to our template engine, and then its margerita time!

Not so fast! Now you discover that, at best, the Velocity support for Jython is experimental, and for some reason your download seems to think its 1.31 instead of the 1.4 you’re sure you downloaded, which doesn’t support Jython at all! (Discover this after spending hours the night before debugging, thinking you were doing something wrong) Now you consider moving to straight up Python and using the Cheetah template engine, but you become aware of FreeMarker through the flame-war inspiring intervention of one of its’ developers in the velocity-users mailing list. Syntax is similar enough, and it supports Jython! So you finish building out the scoring system and create some sweet templates for your standings page:
-snip-
< #assign num=1>
< #list standings as s>
<tr <#if ((num %2) = 0)>class="shadedrow" >
<td>${s.team.name}</td>
<td>${s.W}</td>
<td>${s.L}</td>
<td>${s.T}</td>
<td>${s.RD}</td>
<td>${s.GP}</td>
<td>${s.F}</td>
</tr>
< #assign num= num+1>
-snip-

Get the rest of the standings template and the schedule template.

Wrap it all together with a small driver to load the templates, crank up the freemarker engine, and write out the output as I did here. (Note apparently the JythonWrapper is not really needed – i was chasing a bug with java dates that has since been fixed)

Now we’re almost done – one of these days need to convert the templates of the static pages to freemarker (or freemarkerpp) and then we’ll really be done – for now we’re done enough. Now keeping the scores and standings updated is breathakingly easy! It only took an order of magnitude more time to get this all written and working than it would have taken to actually do the manual edits over time. Oh well, that’s just the way we engineers roll I guess.

Thanks to the velocity-users group for their help trying to get Jython to work for me, as well as Jonathon of the FreeMarker project for introducing me to his project and providing a push in the right direction getting my system working, as well as responding quickly to a problem formatting java.util.Date objects embedded in jython objects.

Leave a Reply

Your email address will not be published.