0
0
Fork 0

Merge remote-tracking branch 'origin/master'

This commit is contained in:
Stormwind 2012-11-23 18:10:27 +01:00
commit 1b96ebb36d
4 changed files with 68 additions and 24 deletions

View File

@ -7,7 +7,7 @@ module Zero
class Controller
# initialize a new instance of the controller and call response on it
def self.call(env)
new(Rack::Request.new(env)).response
new(Zero::Request.new(env)).response
end
# initialize the controller
@ -20,7 +20,17 @@ module Zero
# build the response and return it
# @return Response a rack conform response
def response
raise NotImplementedError.new("Not Implemented in ${__FILE__}")
process if respond_to?(:process)
render
@response
end
def process
raise NotImplementedError.new("'render' not implemented in #{self.class}")
end
def process
raise NotImplementedError.new("'render' not implemented in #{self.class}")
end
end
end

View File

@ -14,30 +14,32 @@ module Zero
# The call to #render will return the String representation of the template
# with all data given.
class Renderer
# set a base path for template search
# @param path [String] the path to the template base dir
def self.template_path=(path)
@@path = path + '/'
end
class << self
# set a base path for template search
# @param path [String] the path to the template base dir
def template_path=(path)
@@path = path + '/'
end
# save a mapping hash for the type
#
# With that it is possible to map long and complex contant types to simpler
# representations. These get then used in the finding process for the best
# fitting template.
#
# @example
# Zero::Renderer.map = {'text/html' => 'html'}
#
# @param map [Hash] maps the content type to a simple representation
def self.type_map=(map)
@@map = map
end
# save a mapping hash for the type
#
# With that it is possible to map long and complex contant types to simpler
# representations. These get then used in the finding process for the best
# fitting template.
#
# @example
# Zero::Renderer.map = {'text/html' => 'html'}
#
# @param map [Hash] maps the content type to a simple representation
def type_map=(map)
@@map = map
end
# returns the type map
# @return [Hash] the mapping for types
def self.type_map
@@map ||= {}
# returns the type map
# @return [Hash] the mapping for types
def type_map
@@map ||= {}
end
end
# take the path and render the template within the context
@ -72,6 +74,12 @@ module Zero
raise FileNotFoundError.new("Template '#{template_path}' not found!")
end
# @see transform
# @api private
def transform(string)
self.class.transform(string)
end
# transform a type into a simpler representation
# @api private
# @param string [String] the original type name

View File

@ -1,6 +1,18 @@
unless RUBY_ENGINE == 'rbx' then
require 'simplecov'
SimpleCov.start do
add_filter '_spec.rb'
end
end
require 'rack'
require 'zero/all'
class SpecController < Zero::Controller
def process; end
def render; @response = [200, {'Content-Type' => 'text/html'}, ['foo']]; end
end
class SpecApp
attr_reader :env

View File

@ -0,0 +1,14 @@
require 'spec_helper'
describe Zero::Controller, '.call' do
subject { SpecController.call(env) }
let(:env) { EnvGenerator.get('/foo') }
it "returns a response" do
subject.should be_respond_to(:to_a)
end
it "returns an object with the first element being a status" do
subject[0].should be_kind_of(Numeric)
end
end