My second groovy script

While I'm still hacking around on the first one (besides some other small projects I started with Grails), which is about getting rid of doublettes in my ical calendars I have, I wrote a little script to generate my (haha, currently only single paged) webpage from a contents file and a general template - more or less just for fun, on the other hand, even with a single page it's nice to have the contents, the css and the general page frame differed.

My script looks like this:

import groovy.text.SimpleTemplateEngine

def engine = new SimpleTemplateEngine()

// read the content file into a string (name: first argument)
def contentFilename = args [0]
println "reading file $contentFilename"
def contentFile = new File(contentFilename)
def content = contentFile.text

// read the template file
// TODO: maybe read args[1] for template name and 2 for out name?!
//def templateFileName = args[1]
def templateText = new File("template.html").text

def binding = ["BODY":content]

// replace the $BODY variable with the content stuff
template = engine.createTemplate(templateText).make(binding)

//save as index.html

def outFile = new File("index.html")
outFile << template.toString()

It's run as "groovy ", and requires a file template.html to exist, which has a variable $BODY there, where the body should appear, and will write the file index.html(which, attention, will be deleted if existing!).

There's sure a lot to improve - but maybe in the meantime I will also decide for a real CMS - I don't want to reinvent the wheel (on the other hand, sometimes it's interesting as well as easier to make a custom solution).
I plan to have the content html generated from wiki input, as I'm too lazy to write HTML for such simple things as lists, headlines, etc. Let's see how it will go - I'll have to checkout java wiki engines to get that going - or is there some already in groovy, even?