-
Notifications
You must be signed in to change notification settings - Fork 0
How To: Create Haml and Slim Views
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.
$ gem install haml hpricot ruby_parser slim haml2slim
$ rails generate devise:views
$ for i in `find app/views/devise -name '*.erb'` ; do html2haml -e $i ${i%erb}haml ; rm $i ; done
$ for i in `find app/views/devise -name '*.haml'` ; do haml2slim $i ${i%haml}slim ; done
$ for i in `find app/views/devise -name '*.haml'` ; do rm $i ; done
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
Then, remove erb files from app/views/devise folder.
$ for i in `find app/views/devise -name '*.erb'` ; do rm $i ; done
Or, in a single step:
$ for i in `find app/views/devise -name '*.erb'` ; do html2haml -e $i ${i%erb}haml ; rm $i ; done
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.
$ for i in `find app/views/devise -name '*.haml'` ; do haml2slim $i ${i%haml}slim ; done
Then, remove haml files from app/views/devise folder.
$ for i in `find app/views/devise -name '*.haml'` ; do rm $i ; done