Ages ago I registered urbanpaganism.info, and set up a basic wiki for a community I’d set up for people who practice Paganism in urban environments and were fed up the usual hippy clap-trap advice like ‘grow plants in a window box’ and ‘visit the countryside’ when it came to experiencing Paganism in the city.
It never really took off, and I’ve decided to scrap it and revisit an idea I had when I originally registered it, but didn’t pursue. That application’s not ready yet, although I think I understand everything I need for it, and plan to work on it a bit tomorrow.

Random image generated from the word 'Sinatra'
In the meantime, I wanted to play around with RMagick and decided to make an actual usable application using some different tools than I’ve been using up until now.
While the random image divination tool is actually quite basic, I’m really pleased with what I’ve done. It’s written using Sinatra, which I’ve never used in anger before. For such a simple application, it’s an obvious choice, and it fitted into how this application was developed, too.
The initial Ruby code I wrote for this was a command-line tool that produced the image file and printed out the filename. This was never intended to be a final version, but it let me quickly test and refine the code. To use it with Sinatra, I wrapped the script in a class, specified an interface and required it from my very simple main Sinatra app file. If your web interface isn’t much more than a wrapper around a class, Sinatra’s a much better choice than something like Rails.
Writing the code like this was a good experience at writing just Ruby rather than “Ruby on Rails”. I did have to require ‘activesupport’, because you get too used to the nice extras that gives you, but it’s nice to write something simpler and leaner.
The templating was also a departure, as I wrote them in HAML. I’m pretty sure I’ve missed something, since HAML doesn’t seem like more than a pretty way to write HTML. If there’s any helpers, they weren’t helping me. I suppose it’s neater than just raw HTML, but I won’t be switching from ERB in my Rails projects.
As the actual ‘business logic’ (if it can be called that!) was pre-developed in the command-line tool, only a little bit of development using Sinatra was required. Thankfully, Phusion Passenger cheerfully supports Rack applications, so this was easy to set up in both my development and production environments.
What wasn’t so easy to set up was RMagick itself – I suspect that there’s no painless way to get it working on Mac OS X with the Apple-supplied Ruby. I’ve had to switch using the MacPorts Ruby, and spent some time figuring out which gems I needed to reinstall. Pretty frustrating, and led to much swearing on Twitter.
The end result of all this is a simple tool that draws lines, arcs, squiggles (technically polylines), and rectangles in a semi-random way. When fed the same starting phrase it’ll always draw the same thing (I’m using String#hash on the phrase to seed Ruby’s random number generator, using srand()), but there’s also the option to not enter anything and get a non-repeatable pseudorandom image. I’m hoping that these random/semi-random images will be useful for focussing on when contemplating what to do or where things are going – a form of iconomancy, I suppose.
I’m not convinced that they’re entirely fit for purpose, but if nothing else I do find them largely aesthetically pleasing.
This kind of goes against my earlier post about not keeping learning projects around for too long, since a play-around with RMagick turned into something that’s living on my deployment VM, but I’m fine with this. It’s a small simple app that does one simple thing, and it’s nicer to tidy it up enough to deploy (ie, give it a tolerable interface) than to just chuck it away. And it’s nice to know that even if I’ve not got the replacement for urbanpaganism.info done yet, at least I’ve got some new content out there in the world.
Post a Comment