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.



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

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.

Yields:



27
28
29
30
31
# File 'lib/corrupt/framework/controller.rb', line 27

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 to be rendered.



34
35
36
# File 'lib/corrupt/framework/controller.rb', line 34

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