I’ve got my Ruby code filtering Markdown and now I want to stuff that filtered content into an HTML page. I could just use maruku#to_html_document, but I need the ability to add details like a title and site-related links.
I could use a format similar to my Python blog files. I won’t really need PageTemplate if I do that, though. Not for the content file, anyways. That’s okay, though. The Maruku filter was more of a proof-of-concept, anyways. PageTemplate will be useful for fitting the generated content into an actual template, though.
That means I’m starting over on my content files.
Given a content file that looks like this:
I want an object that makes the title available in some way (simple Hash style access is fine), and makes the HTML-formatted content available. After a few minutes of fiddling and poking around, I end up with tests and application code.
Article Test Code
The Application Code
It’s a really simple, slow parser, but it works. I won’t try to optimize it before I’ve actually figured out what it’s supposed to be doing.
The Template
The next target is stuffing this content into a template. That’s easy. Here’s the template:
simple.html Template File
I could assemble my page manually if I felt like it. As a matter of fact, let’s do that in one of the tests.
Manual Page Generation Test
Do I really want to manually apply even that little bit of code, though? No, I don’t.
Automatic Page Generation Test
Automatic Page Generation Code
Saving a File
Okay, now I have article files with content and metadata being consumed, formatted, and handed off to PageTemplate for wrapping into a pretty HTML page. The only thing remaining at this stage is to actually write the file.
Test Writes
Code to Make the Writes Happen
Oh heck, just take the whole thing. This is what my SiteTemplate.rb file looks like right now.
Wrapup
This stage is done. We’ve taken some article files that look a lot like my blog files and turned them into fully-fleshed HTML files. They will fit into a PageTemplate that’s been defined by the site maintainer, guaranteeing a standard look for the site.
My next post on this topic will deal with putting an HTML_Page into the context of a larger site.