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

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, options={}, locals={}, &block)
  options, template = template, nil if template.is_a?(Hash)
  template = Proc.new { block } if template.nil?
  render :builder, template, options, locals
end

#erb(template, options = {}, locals = {}) ⇒ Object



287
288
289
# File 'lib/sinatra/base.rb', line 287

def erb(template, options={}, locals={})
  render :erb, template, options, locals
end

#erubis(template, options = {}, locals = {}) ⇒ Object



291
292
293
# File 'lib/sinatra/base.rb', line 291

def erubis(template, options={}, locals={})
  render :erubis, template, options, locals
end

#haml(template, options = {}, locals = {}) ⇒ Object



295
296
297
# File 'lib/sinatra/base.rb', line 295

def haml(template, options={}, locals={})
  render :haml, template, options, locals
end

#sass(template, options = {}, locals = {}) ⇒ Object



299
300
301
302
# File 'lib/sinatra/base.rb', line 299

def sass(template, options={}, locals={})
  options[:layout] = false
  render :sass, template, options, locals
end