Class: Corrupt::Controller::Base
- Inherits:
-
Object
- Object
- Corrupt::Controller::Base
- Defined in:
- lib/corrupt/framework/controller.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#headers ⇒ Object
Return the headers for the response.
Instance Method Summary collapse
-
#content ⇒ Object
Return the content (string) to be rendered.
-
#content=(new_content) ⇒ Object
Set the content to be rendered.
-
#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. -
#template(file = nil) ⇒ Object
Set the template file to be rendered or return the Corrupt::Template object.
Instance Attribute Details
#headers ⇒ Object
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
#content ⇒ Object
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.
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 |