Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

haml by default

Is there a way to configure rails to use haml by default, i.e. when a scaffold is generated the according scaffold_name/index.html.haml is generated instead of scaffold_name/index.html.erb.

Similar to how you are able to add config.sass.preferred_syntax = :sass to config/application.rb and have scaffold_name.sass generated by default.

Tried adding the following to config/application.rb

config.generators do |g|    g.template_engine :haml end 

but ened up with the following

$ rails generate scaffold foo name:string   invoke  active_record   create    db/migrate/20120208152550_create_foos.rb   create    app/models/foo.rb   invoke    test_unit   create      test/unit/foo_test.rb   create      test/fixtures/foos.yml    route  resources :foos   invoke  scaffold_controller   create    app/controllers/foos_controller.rb    error    haml [not found]   invoke    test_unit   create      test/functional/foos_controller_test.rb   invoke    helper   create      app/helpers/foos_helper.rb   invoke      test_unit   create        test/unit/helpers/foos_helper_test.rb   invoke  assets   invoke    coffee   create      app/assets/javascripts/foos.js.coffee   invoke    sass   create      app/assets/stylesheets/foos.css.sass   invoke  sass   identical    app/assets/stylesheets/scaffolds.css.sass $ rails destroy scaffold foo                                                                                                                           invoke  active_record   remove    db/migrate/20120208152550_create_foos.rb   remove    app/models/foo.rb   invoke    test_unit   remove      test/unit/foo_test.rb   remove      test/fixtures/foos.yml    route  resources :foos   invoke  scaffold_controller   remove    app/controllers/foos_controller.rb    error    haml [not found]   invoke    test_unit   remove      test/functional/foos_controller_test.rb   invoke    helper   remove      app/helpers/foos_helper.rb   invoke      test_unit   remove        test/unit/helpers/foos_helper_test.rb   invoke  assets   invoke    coffee   remove      app/assets/javascripts/foos.js.coffee   invoke    sass   remove      app/assets/stylesheets/foos.css.sass   invoke  sass 

I created a nice little bundle command to replace all erb with haml files following this screencast but I'm still interested in making it default when the scaffold is created! How do I make it so haml files (not erb!) are generated by default?

like image 406
rudolph9 Avatar asked Feb 08 '12 02:02

rudolph9


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.

Is HAML better than HTML?

HAML is just a templating language that gets transformed into HTML (e.g. same final output). If you find the HAML syntax to be easier than HTML then go for it. However IMHO - abstracting away what actual elements you are generating just makes applying CSS and doing JavaScript navigation that much more difficult.

What is HAML code?

Haml (HTML Abstraction Markup Language) is a templating system that is designed to avoid writing inline code in a web document and make the HTML cleaner. Haml gives the flexibility to have some dynamic content in HTML.

How does HAML work?

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.


1 Answers

I use gem 'haml-rails', '= 0.3.4' in my gemfile. it automatically generates *.html.haml without any configuration.

like image 59
raymondralibi Avatar answered Sep 18 '22 22:09

raymondralibi