-
Notifications
You must be signed in to change notification settings - Fork 14
RendererComponents
This section covers the specifics of setting up an application using the sinatra_more generators and each templating component.
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
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