Module: Sinatra::Templates
- Included in:
- Base
- Defined in:
- lib/sinatra/base.rb
Overview
Template rendering methods. Each method takes the name of a template to render as a Symbol and returns a String with the rendered output, as well as an optional hash with additional options.
‘template` is either the name or path of the template as symbol (Use `:’subdir/myview’‘ for views in subdirectories), or a string that will be rendered.
Possible options are:
:layout If set to false, no layout is rendered, otherwise
the specified layout is used (Ignored for `sass`)
:locals A hash with local variables that should be available
in the template
Instance Method Summary collapse
- #builder(template = nil, options = {}, locals = {}, &block) ⇒ Object
- #erb(template, options = {}, locals = {}) ⇒ Object
- #erubis(template, options = {}, locals = {}) ⇒ Object
- #haml(template, options = {}, locals = {}) ⇒ Object
- #sass(template, options = {}, locals = {}) ⇒ Object
Instance Method Details
#builder(template = nil, options = {}, locals = {}, &block) ⇒ Object
304 305 306 307 308 |
# File 'lib/sinatra/base.rb', line 304 def builder(template=nil, ={}, locals={}, &block) , template = template, nil if template.is_a?(Hash) template = Proc.new { block } if template.nil? render :builder, template, , locals end |
#erb(template, options = {}, locals = {}) ⇒ Object
287 288 289 |
# File 'lib/sinatra/base.rb', line 287 def erb(template, ={}, locals={}) render :erb, template, , locals end |
#erubis(template, options = {}, locals = {}) ⇒ Object
291 292 293 |
# File 'lib/sinatra/base.rb', line 291 def erubis(template, ={}, locals={}) render :erubis, template, , locals end |
#haml(template, options = {}, locals = {}) ⇒ Object
295 296 297 |
# File 'lib/sinatra/base.rb', line 295 def haml(template, ={}, locals={}) render :haml, template, , locals end |
#sass(template, options = {}, locals = {}) ⇒ Object
299 300 301 302 |
# File 'lib/sinatra/base.rb', line 299 def sass(template, ={}, locals={}) [:layout] = false render :sass, template, , locals end |