reuse render for actual rendering
The splitting of rendering and processing is good, but on the other side it makes some double steps or even introduce workarounds. That is why I made the method #render just a call to the renderer. This should help much more than the strict seperation. The method will only return the resulting string and not add it to the body of the response. That still has to be taken care of by the user.
This commit is contained in:
parent
b0954de7dc
commit
b20c0c527c
|
@ -56,13 +56,22 @@ module Zero
|
|||
|
||||
# build the response and return it
|
||||
#
|
||||
# This method calls #process if it was defined so make it easier to process
|
||||
# the request before rendering stuff.
|
||||
# This method calls #process. #process has to be provided by the actual
|
||||
# implementation and should do all processing necessary to provide the
|
||||
# content.
|
||||
# @return Response a rack conform response
|
||||
def response
|
||||
process if respond_to?(:process)
|
||||
render
|
||||
process
|
||||
@response.to_a
|
||||
end
|
||||
|
||||
# renders a template
|
||||
#
|
||||
# This method calls #render of the provided renderer and gives it the
|
||||
# template name and accept types, so that the renderer can search for the
|
||||
# appropiate template to render.
|
||||
def render(template)
|
||||
@renderer.render(template, @request.accept.types, self)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Zero::Controller, '#render' do
|
||||
subject { Zero::Controller.new(env) }
|
||||
let(:env) { EnvGenerator.get('/foo') }
|
||||
let(:renderer) { mock }
|
||||
let(:template) { '/foo' }
|
||||
|
||||
before :each do
|
||||
Zero::Controller.renderer = renderer
|
||||
renderer.should_receive(:render).with(template,
|
||||
kind_of(Zero::Request::AcceptType), subject)
|
||||
end
|
||||
after :each do
|
||||
Zero::Controller.renderer = nil
|
||||
end
|
||||
|
||||
it { subject.render(template) }
|
||||
end
|
Loading…
Reference in New Issue