Matt's Blog

Wrapping content in containers

Sun Nov 19 11:24:44 EST 2006

Everyone is pretty familiar with the concept of wrapping content in tags describing how to display that content by now. A basic example is wrapping section heading in a <h1>Section name</h1> environment in HTML.

What I want to do is wrap an entire output format around my content. Consider my website as the example. As I write this my website consists of a hierarchical collection of linked pages. The pages at the top level of the hierarchy ("Home", "Me", "Links", etc) are used to construct a top level navigation bar that is placed on the side of each page. The lower level pages have a smaller navigation bar at the top of the page that links to children of that page and the parent node (as long as the parent is not one of the top level pages).

At the moment my website generation program is quite low level in that it treats the pages as strings rather than abstract datatypes for example (this is due to my lack of understanding of the module system when I wrote the program). To fix this, represent the website layout of a tree of wrapper functions. Each wrapper function takes a HTML document as input and wraps it in the appropriate main and sub navigation bars, HTML headers etc.

  • Sidenote: At the moment I am using Markdown to write the content for my website. This is a plain text format with some simple syntax rules that allow conversion of the plain text document into HTML (without the header and footer tags). A slight drawback is that most of my website generation software is written in Ocaml, while the Markdown script is in Perl. Converting the Perl script to Ocaml is on my to-do list, but at the moment the separate phases are tied together with shell scripts.

Here is the idea: in a functional language the thing that I wrap around the content may not be just a data layer. It can be a machine. By wrapping my htmltree program around a data file specifying the layout of pages in a website I construct a machine that wraps an input page with the appropriate navigation bars.

This is nothing more than using lexical closures to encompass abstract datatypes and so in a sense is pretty obvious. It still feels to me that I am on the brink of some conceptual breakthrough that will bring together functional programming and abstraction.

[code] [ideas]


code (24)

erlang (5)
ideas (19)
lisp (1)
me (11)
notes (4)
ocaml (1)
physics (45)
qo (7)
unix (6)
vim (3)