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



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

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



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

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

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



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

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



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

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