Wednesday, July 16, 2008

Dear Lazyweb - An Answer

I asked
What I (think I) need, then, is a way for a plain-jane html page to refer to a common source for the header and footer. A single file to change and bam all my complexity goes away.

The answers were

Use frames. Suck it up and use PHP. Use a touch of Ruby [1]. Use make and C to take the source HTML and turn it into 'real' HTML.

The actual answer combined the last two items and lay in the tool I was using to make the web site in the first place. It's called nanoc. Whazzat?
nanoc is a tool that runs on your local computer and compiles Markdown, Textile, Haml, etc. documents into static web pages, ready for uploading to any web server.

It's written in Ruby, natch.

Long story short - see the tutorial for details - tag a page's YAML file with the bits specific to that page. In my case I have a unique title for each page

title: "The About Page"
header: "yes"

call it out as a partial in the layout file

<% unless @page.header.nil? %>
<% end %>

What's going on here is that every page has a title (not shown above) - but not every page may get a header or footer.

Compile and bam - nanoc generates valid html and dumps it into the output directory. gzip, sftp, and you've got a website.

[1] Out of scope but interesting is that the more I dabble with Ruby the more it seems that Ruby can be utilized in the same way PERL is now - a scripting language for doing odd chores in situations where shell is too limiting. This is not a world-shaking insight or even a new thought of course, but it pleases me.
blog comments powered by Disqus