Class: Corrupt::Controller::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/corrupt/framework/controller.rb

Direct Known Subclasses

AppController

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#headersObject

Return the headers for the response. TODO: Save the header hash and allow setting of custom keys.



20
21
22
23
# File 'lib/corrupt/framework/controller.rb', line 20

def headers
  { 'Content-Length' => content.size.to_s,
    'Content-Type'   => 'text/html' }
end

Instance Method Details

#contentObject

Return the content (string) to be rendered.



8
9
10
# File 'lib/corrupt/framework/controller.rb', line 8

def content
  @content
end

#content=(new_content) ⇒ Object

Set the content to be rendered.



13
14
15
16
# File 'lib/corrupt/framework/controller.rb', line 13

def content=(new_content)
  @content = new_content
  headers['Content-Length'] = content.size.to_s
end

#return_response(status = 200) {|template| ... } ⇒ Object

Return the full Rack response in this format:

[status, headers, content]

An optional status may be passed; defaults to 200.

An optional block may be passed, which will yield a Corrupt::Template object.

Yields:



30
31
32
33
34
# File 'lib/corrupt/framework/controller.rb', line 30

def return_response(status = 200)
  yield template if block_given?
  self.content = template.render
  [status, headers, content]
end

#template(file = nil) ⇒ Object

Set the template file to be rendered or return the Corrupt::Template object.



37
38
39
# File 'lib/corrupt/framework/controller.rb', line 37

def template(file = nil)
  @template ||= Corrupt::Template.new(file)
end