[Ruby on Rails] Converting .erb Files to .haml Using erb2haml
I converted .erb files to .haml using erb2haml in Ruby on Rails, so I’ll introduce the method.
First, add haml-rails and erb2haml to your Gemfile and run bundle install.
Gemfile
# Use Haml for template engine
gem 'haml-rails'
group :development do
# Convert .erb -> .haml
gem 'erb2haml'
end
Once erb2haml is installed, run the following rake task that becomes available:
rake haml:replace_erbs
Here are the execution results:
After converting ERB files to Haml, it deletes the .erb files.
Looking for ERB files to convert to Haml...
Converting: app/views/home/index.html.erb... Done!
Removing: app/views/home/index.html.erb... Removed!
Converting: app/views/layouts/application.html.erb... Done!
Removing: app/views/layouts/application.html.erb... Removed!
Converting: app/views/layouts/mailer.html.erb... Done!
Removing: app/views/layouts/mailer.html.erb... Removed!
Converting: app/views/layouts/mailer.text.erb... Done!
Removing: app/views/layouts/mailer.text.erb... Removed!
That’s all from the Gemba where we quickly converted from ERB to Haml using erb2haml.