Skip to content

How To: Create Haml and Slim Views

eduardordm edited this page Apr 25, 2011 · 10 revisions

The Haml/Slim view generators were removed from Devise 1.2 . Here is a tutorial how to create Haml/Slim views with Devise 1.2 or later.

Create Haml views

The Haml-gem obviously needs to be installed.

$ gem install haml

With Haml comes a command line tool called ‘html2haml’ which will be used. It has some dependencies which are not installed alongside Haml, so you need to install these next.

$ gem install hpricot
$ gem install ruby_parser

Next you need run the generator to create the devise views.

$ rails generate devise:views

If you have HAML set as default, add the ERB option.

$ rails generate devise:views -e erb

Now convert the erb-files to Haml with the following command.

$ for i in `find app/views/devise -name '*.erb'` ; do html2haml -e $i ${i%erb}haml ; done

Create Slim views

The Slim-gem obviously needs to be installed. We use a gem called ‘haml2slim’ to create the Slim-views.

$ gem install slim
$ gem install haml2slim

As we need Haml-views to convert them to Slim-views, you need to follow the steps to create the Haml-views described above. Afterwards the views can be converted with the following command.

$ find app/views/devise -name '*haml' | xargs ruby -e 'ARGV.each { |i| puts "haml2slim #{i} #{i.sub(/haml$/,"slim")};rm #{i}"}' | bash

Then, remove erb files from app/views/devise folder.
Clone this wiki locally