1
0
Fork 0
mirror of https://github.com/haml/haml-rails.git synced 2022-11-09 12:34:15 -05:00
let your Gemfile do the talking
Find a file
Akira Matsuda 4c6bcaaa23
Merge pull request #183 from cpanderson/readme_update
updated readme to reflect that html2haml is no longer part of the haml-rails install
2022-10-07 11:51:14 +09:00
.github/workflows There's a newer version of actions/checkout 2022-03-29 11:54:02 +09:00
gemfiles CI against rails 7.0 2022-03-29 11:35:05 +09:00
lib Check the result of external html2haml command and output a proper message 2022-10-07 11:43:56 +09:00
test So we can run the tests without bundle exec 2022-09-26 10:02:00 +09:00
.gitignore Ignore test logs 2019-06-09 07:28:50 +09:00
Appraisals CI against rails 7.0 2022-03-29 11:35:05 +09:00
Gemfile Get rid of rbx specific dependencies 2022-03-29 10:57:09 +09:00
haml-rails.gemspec Update haml-rails.gemspec 2022-09-23 16:24:38 +05:30
LICENSE fix LICENSE 2015-01-29 21:47:38 +03:00
Rakefile update appraisal to 1.0 2015-01-28 23:37:17 +03:00
README.md updated readme to reflect that html2haml is no longer part of the haml-rails install 2022-10-06 09:34:19 -06:00

Haml-rails

Build Status

Haml-rails provides Haml generators for Rails 5, 6, and 7. It also enables Haml as the templating engine for you, so you don't have to screw around in your own application.rb when your Gemfile already clearly indicated what templating engine you have installed. Hurrah.

To use it, add this line to your Gemfile:

gem "haml-rails", "~> 2.0"

This ensures that:

  • Any time you generate a resource, view, or mailer, you'll get Haml templates (instead of ERB)
  • When your Rails application loads, Haml will be loaded and initialized automatically
  • Haml templates will be respected by the view template cache digestor

Pretty fancy, eh? The modern world is just so amazing.

Converting Rails application layout file to haml format

Once Haml-rails is installed on the Rails application, you can convert the erb layout file, app/views/layouts/application.html.erb to app/views/layouts/application.html.haml using this command:

$ rails generate haml:application_layout convert

This requires the html2haml gem and you can install it locally:

gem install html2haml

After the application layout file is converted successfully, make sure to delete app/views/layouts/application.html.erb, so Rails can start using app/views/layouts/application.html.haml instead.

Converting all .erb views to haml format

If you want to convert all of your .erb views into .haml, you can do so using the following command:

$ rails haml:erb2haml

If you already have .haml files for one or more of the .erb files, the rake task will give you the option of either replacing these .haml files or leaving them in place.

Once the task is complete, you will have the option of deleting the original .erb files. Unless you are under version control, it is recommended that you decline this option. If you are running in a script, you can use an environment variable to answer this question.

$ HAML_RAILS_DELETE_ERB=true rails haml:erb2haml

Running the above will not prompt for the question and will delete the original .erb files. Setting this value to false will also not prompt, however, will leave the .erb files intact.

Older versions of Rails

The current version of Haml-rails requires Rails 5.1 or later.

Haml-rails version 1.0.0 is the last version to support Rails 4. To use it, add this line to your Gemfile:

gem "haml-rails", "~> 1.0.0"

For Rails 3, use haml-rails version 0.4 by adding this line to your Gemfile instead:

gem "haml-rails", "~> 0.4.0"

Contributors

Haml generators originally from rails3-generators, and written by José Valim, André Arko, Paul Barry, Anuj Dutta, Louis T, and Chris Rhoden. Tests originally written by Louis T.

License

Ruby license or MIT license, take your pick.