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.

Instance Method Summary collapse

Instance Method Details

#builder(template = nil, options = {}, &block) ⇒ Object



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

def builder(template=nil, options={}, &block)
  require 'builder' unless defined? ::Builder
  options, template = template, nil if template.is_a?(Hash)
  template = lambda { block } if template.nil?
  render :builder, template, options
end

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



214
215
216
217
# File 'lib/sinatra/base.rb', line 214

def erb(template, options={})
  require 'erb' unless defined? ::ERB
  render :erb, template, options
end

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



219
220
221
222
223
# File 'lib/sinatra/base.rb', line 219

def haml(template, options={})
  require 'haml' unless defined? ::Haml
  options[:options] ||= self.class.haml if self.class.respond_to? :haml
  render :haml, template, options
end

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



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

def sass(template, options={}, &block)
  require 'sass' unless defined? ::Sass
  options[:layout] = false
  render :sass, template, options
end