Skip to content
billm edited this page Sep 13, 2010 · 5 revisions

This section covers the specifics of setting up an application using the sinatra_more generators and each templating component.

ERB

To use ERB, no gems need to be installed because this templating language is built into the ruby standard library.

To generate an application using ERB, simply invoke the generator:

$ sinatra_gen demo_app . -r erb

To create a new view using ERB, simply pass along instance variables from the routes and use the embedded tags to insert ruby into the template:

# app/views/sample/index.erb
<p>The time is <%= @time.to_s %></p>
# app/routes/sample.rb
class Sample < Sinatra::Application
  get '/' do
    @time = Time.now
    erb_template 'sample/index'
  end
end

For more information on ERB, check out the ERB Documentation

HAML

To use HAML / SASS, you must install the following gems:

$ sudo gem install haml hassle

To generate an application using HAML, simply invoke the generator:

$ sinatra_gen demo_app . -r haml

To create a new view using HAML, simply pass along instance variables from the routes and use the tags to insert ruby into the template:

# app/views/sample/index.haml
%p The time is #{@time.to_s}
# app/routes/sample.rb
class Sample < Sinatra::Application
  get '/' do
    @time = Time.now
    haml_template 'sample/index'
  end
end

For more information on HAML, check out the HAML Documentation

Clone this wiki locally