Quantcast
Channel: WhizCreed
Viewing all articles
Browse latest Browse all 14

HTML ERB to HAML conversion

$
0
0

If you have been using Rails and have tasted HAML then you know the mess HTML creates.

While using several generators that come with gems, we might forget to use haml generators or one might not even be available.

I stumbled upon this awesome piece of bash command that you can use to convert your html erb views to haml views.

Remember to:

  1. Create a new branch or create a backup copy first
  2. Install haml gem
  3. Test html2haml command on an erb file to see the output is as expected and there are no errors

Use the code below to create HAML converted files with haml extension:


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

 

To view a list of html.erb files that you might want to remove run:
find . -name '*erb'

And to remove the html.erb files run:

find . -name '*erb' -delete

 

Original article here.


Viewing all articles
Browse latest Browse all 14

Trending Articles