Migrating my extremely hacky Smarty-based Avarthrel website to clean, nicely working Forrest site is... progressing... weirdly.
I kind of regret the choice already. However, I'm not backing down, because Forrest appears to have a sane approach: Use whatever XML formats you want and transform them to fully skinned site. Besides, I've determined that the root cause of me not being able to write anything is that something bugs me, and in this case it's the old super-hacky Smarty site. Argh.
I only have major problems on the front end. Specifically, the skins aren't very customisable, and I can't really generate HTML from my custom XML sources - I need to generate this very limited subset of HTML. I can't say "When generating the story web pages, they need to have custom Creative Commons metadata, include comments with SSI, and add a comment form at the bottom. All of them need custom parameters."
So what did I do?
Hpricots from hell!
I call my "fix up the broken Forrest HTML" script "ccinjector", because it's main job is to inject Creative Commons metadata. I almost called it cardiacarrest.rb, as in "what you get if you eat a metric heckton of chocolate", to keep up with the Forrest Gump theme.
And what does the injector do? It requires both hpricot and xml/libxml libraries. Two libraries that basically deal with XML data. Yay. And, of course, it grabs yaml. Nope, this app doesn't store its configuration in an XML file. (I'm a pacifist and "XML is like violence: if it doesn't work, use more" doesn't seem too thrilling.)
Conclusion: Storing stuff in text files is surprisingly difficult.
Now, this file then uses libxml to fix up my Creative Commons metadata. It gets inserted in the HTML. then, the script ponders what sort of fixes I've specified in the configuration. It can insert static HTML templates, with or without variable/magic-word substitution, or mess up HTML along the lines of "replace //div[@class=lastmodified] with the contents of lastmod template". hpricot is really nice for this sort of stuff.
And it runs HTML Tidy. Twice. At the beginning and end.
All in all, this stuff is really painless - but still overly complicated considering what I really need here...