Jabberwocky

This site is work in progress and will change a lot very soon ...

bikeshedding for fun

June 7th 2010

Note: If you don't know the reference to the the color of the bikeshed, you should definitely check it out.

My bikeshed of the month was my blog. A blog is nice and simple, so thinking about its implementation is really, really easy.

I wanted a blog where I could just commit and push a markdown file to a repository, and voila: it is published.

The first and obvious candidates are static sites generators like nanoc and jekyll. But I wasn't really convinced, as I was thinking of adding more dynamic features, like, say, comments, or rack middleware shininess.

I started making my own blog engine with sinatra, like everyone and his neighbour, I even had a nice name for it, but then I stumbled onto toto. Toto is a thin layer of blog icing on top of rack.

So I took toto, played a bit to be able to use haml with it and have a decent error page, and here's my blog, such as it is. I'll probably add a fork and a comment gem to toto at some point (haven't decided how to call it, probably something Oz-related).

The amendments to config.ru for haml:

    require 'haml'
    ...
    set :to_html   do |path, page, ctx|
      Haml::Engine.new(File.read("#{path}/#{page}.haml")).render(ctx)
    end
    

and the error page with haml and layout:

    require 'haml'
    set :error do |code|
      # fake the bindings for the layout haml
      class LayoutCtx
        def title; 'title' end
        def archives; "" end
      end
     
       Haml::Engine.new(File.read("templates/layout.haml")).render(LayoutCtx.new) do |content|
          Haml::Engine.new(File.read("templates/pages/error.haml")).render(Object.new,:code => code)
       end
    end
    

And then, the cherry on the cake: the git hook required to make it work on your web server: here

Note: I still have an issue with markdown and code, as you can notice. Still have to look that up.

So there. git push.

blog comments powered by Disqus