ShiftEleven

Converting ERB to HAML snippet

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.

1$ find . -name '*erb' | \
2      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

1$ find . -name '*erb' | \
2      xargs ruby -e 'ARGV.each { |i| puts "html2haml -r #{i} #{i.sub(/erb$/,"haml")}"}' | \
3      bash

If you like it, it probably wouldn't hurt storing that as a shell script somewhere :)

Comments

comments powered by Disqus