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?
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.
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.
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.
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.
I use gem 'haml-rails', '= 0.3.4'
in my gemfile. it automatically generates *.html.haml
without any configuration.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With