So maybe not totally useless certainly fun. Normally, ruby scripts are finished when you reach the end of a file; however, this is not always the case. You can end your script sooner by using the __END__ keyword in your script. Once added, everything you type after that will not be parsed by ruby.
So what?
Well, you can use the global variable DATA to get the contents of what you wrote after the __END__ block. DATA is actually a File object to just that piece of text in your script.
Read the rest of this entry »
I’m playing around with merb so I’m using merb-gen to create some basic scaffolding; however, I’m not using ERB, the default rendering engine, I want to use haml
Haml comes with a script, html2haml, which can take HTML with ERB and convert it nicely to haml. Seeing as I would have to run that command more than once, I have a little command snippet that I like to use to aid with the conversion.
$ find . -name '*erb' | \
xargs ruby -e 'ARGV.each { |i| puts "html2haml -r #{i} #{i.sub(/erb$/,"haml")}"}'
That will print out what the html2haml commands would be, it does *not* run the command. I do that step such that I can review what will be converted. If I like what’s going to be done, then I just run that command and pipe it into bash…like so
$ find . -name '*erb' | \
xargs ruby -e 'ARGV.each { |i| puts "html2haml -r #{i} #{i.sub(/erb$/,"haml")}"}' | \
bash
If you like it, it probably wouldn’t hurt storing that as a shell script somewhere :)
Maybe someone may have told you to use ruby and CGI together, but I think that person has a screw loose. I mean, come on. Everyone knows that what you really need to use is Rack
Read the rest of this entry »
Rails is great and all, but sometimes it can be just a little too much and you just need to set up a few pages, not the next big app. Fear not, there is still tool in the ruby tool box at your disposal: the CGI library CGI is fast and lean and still can be used will all of your favorite friends, like HAML
Read the rest of this entry »