Skip to content
Browse files

redo Page#process to allow overriding aspects of the procedure such a…

…s set_content_type
  • Loading branch information...
1 parent e3ec5ae commit 5870192e839e636220700d86c194aee85d13348a @saturnflyer saturnflyer committed Aug 27, 2012
Showing with 21 additions and 9 deletions.
  1. +21 −9 app/models/page.rb
View
30 app/models/page.rb
@@ -69,11 +69,6 @@ def child_path(child)
end
alias_method :child_url, :child_path
- def headers
- # Return a blank hash that child classes can override or merge
- { }
- end
-
def part(name)
if new_record? or parts.to_a.any?(&:new_record?)
parts.to_a.find {|p| p.name == name.to_s }
@@ -129,14 +124,31 @@ def path
def process(request, response)
@request, @response = request, response
+ set_response_headers(@response)
+ @response.body = render
+ @response.status = response_code
+ end
+
+ def headers
+ # Return a blank hash that child classes can override or merge
+ { }
+ end
+
+ def set_response_headers(response)
+ set_content_type(response)
+ headers.each { |k,v| response.headers[k] = v }
+ end
+ private :set_response_headers
+
+ def set_content_type(response)
if layout
content_type = layout.content_type.to_s.strip
- @response.headers['Content-Type'] = content_type unless content_type.empty?
+ if content_type.present?
+ response.headers['Content-Type'] = content_type
+ end
end
- headers.each { |k,v| @response.headers[k] = v }
- @response.body = render
- @response.status = response_code
end
+ private :set_content_type
def response_code
200

0 comments on commit 5870192

Please sign in to comment.
Something went wrong with that request. Please try again.