CSSpress /16 May 2008 @ 8pm
So today I launched a little command line application for compressing CSS files.
My main motivations for this were that I wanted a little tool to strip out comments and whitespace as well as crunch down some of the style values into more optimized versions. As well as this I wanted to write a program in Ruby that someone else might actually find usefull as well as help me learn a little more about the language.
Currently it can do a pretty good job of removing the comments and the white space and I am working on the rest. You can find out more about it at csspress.net.
A long road
What follows is a little account of how I got this far with it. If you don’t care about implementation stuff you probably don’t want to read on.
In order to distribute the tool I found that by packaging my application as a RubyGem and hosting it on RubyForge anyone can download it simply by typing sudo gem install csspress (anyone on a mac that is) and they can use it right away. No difficult messing with source code.
In terms of writing it in Ruby, that was not crucial to the programs operation. From the users point of view they don’t care what its implemented in, only that it works. The advantage of using Ruby from my point of view is that I like programming with it and with the gem system it makes it child’s play to deploy it.
Gems
In order to package your code as a gem you have to use a specific directory structure. I already had a rudimentary working version of my application so I had to fit it in around this structure. It was a little trial and error at first and then I found New Gem Generator, this provides a command that generates the directory structure and as well as a load of useful files and rake tasks. You might find it a bit over the top (is so try Hoe), but after spending a bit of time and a little more trial and error I have come to really like it.
Tips
If you use a version control system like Subversion or Git you should ignore the doc/ and pkg/ directories as well as the index.html file, as these contain files that will change a lot and cause you a lot of problems.
I also found it useful to have a dig about in some of the gems I already had installed on my system. Its really good to see how other people have done it before you.
What’s coming
If I am honest it took me longer to set up the gem, SVN repository and rubyforge account than it did to write the program. Now its all in place though I can now get cracking on improving the tool and adding functionality.
Download it and give it a go; you might find it useful.
No Comments Yet