Convert existing html.erb to Haml

I have a rails project, views consist only of HTML.ERB files, my client wants to convert ERB to HAML. I have too many view files. It takes a huge amount of time to convert file by file. So any simple way I can convert HTML to haml? I installed the haml plugin in my project.

+46
ruby-on-rails erb haml
Feb 11 '10 at 6:33
source share
9 answers
+26
Feb 11 2018-10-11T00
source share

You can use html2haml from the command line

html2haml your_erb_file new_haml_file 

If you want to convert all your files at once, look at this article: http://shifteleven.com/articles/2008/06/08/converting-erb-to-haml-snippet

+98
Feb 11 2018-10-11
source share

http://www.htmltohaml.com

A more convenient alternative to the selected answer.

+16
Jul 12 '12 at 23:25
source share

David Lung provides this gem on github, which sets up two rake tasks.

With erb2haml, you can easily convert an entire project from erb to haml with rake haml:convert_erbs or rake haml:replace_erbs .

+13
Sep 29 '13 at 6:30
source share

On the haml-rails git page, it provides a cli command to convert all erb to haml directly into your project.

add gem "haml-rails" to your gemfile

run: rake haml:erb2haml

+10
Oct 20 '15 at 3:51 on
source share

very simple

in Gemfile add

 gem "erb2haml", :group => :development 

then run bundle install

to convert *.erb to *.haml save source files:

 rake haml:convert_erbs 

to convert *.erb to *.haml to replace the source files do:

 rake haml:replace_erbs 

it will search for all erb files in the project and convert to haml .

For short: use an online converter

http://www.htmltohaml.com

+9
Sep 15 '15 at 8:39
source share

EDIT: html2haml works as advertised, however you should use the version obtained from the current leading branch of haml github repoistory.

The html2haml version included with haml gem, currently available from rubygems, is not good. This is the version you will get if you need to do gem install haml right now. Using the version that comes with the stone will result in an invalid haml, as it will not be able to handle the ruby ​​properly.

+4
Feb 11 '10 at 19:48
source share

html2haml is now in the html2haml gem, so you can use:

 $ gem install html2haml $ html2haml path/to/yourfile.html path/to/yourfile.haml 
+1
Apr 26 '13 at 0:37
source share

Late in the game, but this post still flies high on Google looking for similar solutions.

Install the html2haml , put it in your application / presentation directory and try:

 find ./ -name '*.erb' -exec html2haml -e {} {}.haml \; find ./ -name "*.erb.haml" -exec sh -c 'mv "$1" "${1%.erb.haml}.haml"' _ {} \; find ./ -name '*.erb' -exec rm {} \; 

The disadvantage of this solution is that it does not save the change history from old .erb files to your new .haml files. But at times, when the history of revising these view files does not really matter, I really liked this solution.

In addition, be sure to check for any errors in the html2haml line before deleting old .erb files.

+1
Jun 24 '15 at 13:34
source share



All Articles