Staging Hobix

So, I’m blogging to you using Hobix, a ruby blog system that generates static HTML from simple YAML files (using RedCloth/Textile for fancy markup). I like this approach, because it allows me to write/test blog entries on my local machine (which is a good thing, because I’m not a YAML/Textile expert yet) and then send the static HTML to my server (I still have to figure out a way to support comments, though).

However, I ran into the following issue: In Hobix’s configuration file you have to set a property link to the URL of your blog, so I set this to “http://www.kanthak.net/explorations”. However, this causes the HTML file to include absolute links so that I can’t test stuff locally (and since it does not find the CSS file, it looks ugly, too). I can set link to a relative path to my “htdocs” directory as well and that makes it work locally. However, Hobix converts this to absolute paths a la ”/home/skanthak/...” which don’t work very well on the web.

So I wrote a simple plugin to Hobix that changes the value of the link configuration attribute based on a HOBIX_ENV environment variable. It’s really simple so I’ll show you the full source:


module Hobix
class StagingPlugin < BasePlugin
  def initialize(weblog,production_link)
    if ENV['HOBIX_ENV'] == "production" 
      weblog.link = production_link
    end
  end
end
end

To use it, you have to include the following line into your hobix.yaml to require and configure the plugin.


requires:
- [[plugins/staging, "http://www.kanthak.net/explorations"]]
- hobix/storage/filesys

So, what it does is change the weblog’s link attribute when the environment variable HOBBIX_ENV is set to “production” (in my normal configuration it is set to the absolute path to “htdoc”).

Update: why, the luck stiff, the author of hobix, just pointed out how to properly pass parameters to the plugin:

- plugins/staging: "http://www.kanthak.net/explorations" 

Admittedly, this looks way nicer than my [[ ... ]] construction, although it worked well, too.