Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate Haml views instead of erb

Tags:

haml

I'm building an app with Rails 2.3.4 and using

script/generate controller home index 

to generate a controller and home page. I've got Haml installed. I get an erb file:

app/views/home/index.html.erb 

but I'd prefer to have a Haml file generated instead, like:

app/views/home/index.html.haml 

I recall Merb would generate .haml views instead of .erb if a haml gem was detected. Is this not available in Rails 2.3.4? I tried

script/generate controller home index --haml 

but a "--haml" option is invalid.

Of course I can manually change my erb files to haml files but I'd rather have the generator do the work. Call me lazy. Suggestions?

like image 845
Daniel Kehoe Avatar asked Jan 31 '10 23:01

Daniel Kehoe


People also ask

Should I use HAML or ERB?

ERB has a simple syntax for mixing HTML and Ruby commands, but it can be somewhat verbose. Haml is a very popular alternative which has a condensed syntax for expressing HTML.

How do you write HAML in HTML?

In Haml, we write a tag by using the percent sign and then the name of the tag. This works for %strong , %div , %body , %html ; any tag you want. Then, after the name of the tag is = , which tells Haml to evaluate Ruby code to the right and then print out the return value as the contents of the tag.

What are HAML files?

Haml (HTML Abstraction Markup Language) Haml is a markup language that's used to cleanly and simply describe the HTML of any web document, without the use of inline code. Haml functions as a replacement for inline page templating systems such as PHP, ERB, and ASP.


2 Answers

This gem will do the trick http://github.com/indirect/haml-rails

like image 183
Alex Avatar answered Sep 29 '22 02:09

Alex


Waht actually worked for me, but in rails 3.1 is this wiki here: https://github.com/plataformatec/devise/wiki/How-To:-Create-Haml-and-Slim-Views :)

like image 26
ecoologic Avatar answered Sep 29 '22 03:09

ecoologic