Skip to content

Commit

Permalink
redo Page#process to allow overriding aspects of the procedure such a…
Browse files Browse the repository at this point in the history
…s set_content_type
  • Loading branch information
saturnflyer committed Aug 27, 2012
1 parent e3ec5ae commit 5870192
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions app/models/page.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -69,11 +69,6 @@ def child_path(child)
end end
alias_method :child_url, :child_path alias_method :child_url, :child_path


def headers
# Return a blank hash that child classes can override or merge
{ }
end

def part(name) def part(name)
if new_record? or parts.to_a.any?(&:new_record?) if new_record? or parts.to_a.any?(&:new_record?)
parts.to_a.find {|p| p.name == name.to_s } parts.to_a.find {|p| p.name == name.to_s }
Expand Down Expand Up @@ -129,14 +124,31 @@ def path


def process(request, response) def process(request, response)
@request, @response = 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 if layout
content_type = layout.content_type.to_s.strip 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 end
headers.each { |k,v| @response.headers[k] = v }
@response.body = render
@response.status = response_code
end end
private :set_content_type


def response_code def response_code
200 200
Expand Down

0 comments on commit 5870192

Please sign in to comment.