Slim in Starter Apps from the RailsApps Project

The RailsApps project now has improved support for the Slim template language. Like Haml, Slim is an alternative to ERB, the default Rails template language. Slim is like Haml, only slimmer.

I like both Haml and Slim, though I use ERB for all the RailsApps example applications and the Learn Ruby on Rails book because it is more familiar to beginners. The Rails Composer tool, which generates starter applications, has offered the option of both ERB and Haml, and I’ve wanted to support Slim as well. Benedict Lee stepped forward and made a code contribution this week to add Slim templates to the rails_layout gem.

The rails_layout gem is what I use to create files for the application layout, navigation, and flash messages in the starter apps that are generated by the Rails Composer tool. With Benedict Lee’s code contribution, and some fixes to the rails_apps_composer gem, you can now choose from ERB, Haml, or Slim when you build a starter app.

The rails_layout gem offers a choice of front-end frameworks, too. So, in addition to choosing ERB, Haml, or Slim when you build a starter app, you can choose:

  • Bootstrap 2.3
  • Bootstrap 3.0
  • Zurb Foundation 4.0
  • Zurb Foundation 5.0

and get the application layout, navigation, and flash messages set up for your favorite front-end framework.

Try it out by building a starter app that is featured in the Learn Ruby on Rails book:

$ rails new learn-rails -m https://raw.github.com/RailsApps/rails-composer/master/composer.rb

You’ll see a prompt:

question  Install an example application for Rails 4.0?
  1)  Build a RailsApps starter application
  2)  Build a contributed application
  3)  I want to build my own application

Enter “1” to select Build a RailsApps starter application. You’ll see a prompt:

question  Starter apps for Rails 4.0. More to come.
  1)  learn-rails
  2)  rails-bootstrap

Choose learn-rails. The application generator template will ask you for additional preferences:

question  Web server for development?
   1)  WEBrick (default)
   2)  Thin
   3)  Unicorn
   4)  Puma
question  Web server for production?
   1)  Same as development
   2)  Thin
   3)  Unicorn
   4)  Puma
question  Template engine?
   1)  ERB
   2)  Haml
   3)  Slim
question  Continuous testing?
   1)  None
   2)  Guard
question  Front-end framework?
   1)  None
   2)  Zurb Foundation 5.0
   3)  Zurb Foundation 4.0
   4)  Twitter Bootstrap 3.0
   5)  Twitter Bootstrap 2.3
   6)  Simple CSS
extras  Set a robots.txt file to ban spiders? (y/n)
extras  Create a GitHub repository? (y/n)
extras  Use or create a project-specific rvm gemset? (y/n)

In a few moments, you’ll have a complete example application with your preferred template language and front-end framework.