Module: Sinatra::Templates

Included in:
Base
Defined in:
lib/sinatra/base.rb

Overview

Template rendering methods. Each method takes a 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



238
239
240
241
242
# File 'lib/sinatra/base.rb', line 238

def builder(template=nil, options={}, locals={}, &block)
  options, template = template, nil if template.is_a?(Hash)
  template = lambda { block } if template.nil?
  render :builder, template, options, locals
end

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



225
226
227
# File 'lib/sinatra/base.rb', line 225

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

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



229
230
231
# File 'lib/sinatra/base.rb', line 229

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

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



233
234
235
236
# File 'lib/sinatra/base.rb', line 233

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