Class: Deas::SinatraRunner

Inherits:
DeasRunner show all
Defined in:
lib/deas/sinatra_runner.rb

Instance Attribute Summary

Attributes inherited from Runner

#handler, #handler_class, #logger, #params, #request, #response, #router, #session, #template_source

Instance Method Summary collapse

Methods inherited from DeasRunner

#run

Constructor Details

#initialize(handler_class, args = nil) ⇒ SinatraRunner

Returns a new instance of SinatraRunner.



8
9
10
11
# File 'lib/deas/sinatra_runner.rb', line 8

def initialize(handler_class, args = nil)
  @sinatra_call = (args || {})[:sinatra_call]
  super(handler_class, args)
end

Instance Method Details

#content_type(*args) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/deas/sinatra_runner.rb', line 23

def content_type(*args)
  return @sinatra_call.content_type if args.empty?

  opts, value = [
    args.last.kind_of?(::Hash) ? args.pop : {},
    args.first
  ]
  @sinatra_call.content_type(value, {
    :charset => @sinatra_call.settings.deas_default_charset
  }.merge(opts || {}))
end

#halt(*args) ⇒ Object

Helpers



15
16
17
# File 'lib/deas/sinatra_runner.rb', line 15

def halt(*args)
  @sinatra_call.halt(*args)
end

#headers(*args) ⇒ Object



39
40
41
# File 'lib/deas/sinatra_runner.rb', line 39

def headers(*args)
  @sinatra_call.headers(*args)
end

#partial(template_name, locals = nil) ⇒ Object



60
61
62
63
64
65
66
# File 'lib/deas/sinatra_runner.rb', line 60

def partial(template_name, locals = nil)
  if self.template_source.engine_for?(template_name)
    self.template_source.partial(template_name, locals || {})
  else
    Deas::Template::Partial.new(@sinatra_call, template_name, locals).render
  end
end

#redirect(*args) ⇒ Object



19
20
21
# File 'lib/deas/sinatra_runner.rb', line 19

def redirect(*args)
  @sinatra_call.redirect(*args)
end

#render(template_name, opts = nil) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/deas/sinatra_runner.rb', line 43

def render(template_name, opts = nil)
  self.content_type(get_content_type(template_name)) if self.content_type.nil?

  options = opts || {}
  options[:locals] = {
    :view => self.handler,
    :logger => self.logger
  }.merge(options[:locals] || {})
  options[:layout] = self.handler_class.layouts if !options.key?(:layout)

  if self.template_source.engine_for?(template_name)
    self.template_source.render(template_name, self.handler, options[:locals])
  else
    Deas::Template.new(@sinatra_call, template_name, options).render
  end
end

#send_file(*args, &block) ⇒ Object



68
69
70
# File 'lib/deas/sinatra_runner.rb', line 68

def send_file(*args, &block)
  @sinatra_call.send_file(*args, &block)
end

#status(*args) ⇒ Object



35
36
37
# File 'lib/deas/sinatra_runner.rb', line 35

def status(*args)
  @sinatra_call.status(*args)
end