From d7c217bd3057b18c8c2dff12e0a5974719185b68 Mon Sep 17 00:00:00 2001 From: Gibheer Date: Sat, 17 Nov 2012 09:25:05 +0100 Subject: make class functions more clear in renderer --- lib/zero/renderer.rb | 46 ++++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/lib/zero/renderer.rb b/lib/zero/renderer.rb index 740d156..3ae515b 100644 --- a/lib/zero/renderer.rb +++ b/lib/zero/renderer.rb @@ -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 -- cgit v1.2.3-70-g09d2 From 4e2a4b8931327b7540320ca8f8d65e5ce0ab3a09 Mon Sep 17 00:00:00 2001 From: Gibheer Date: Sat, 17 Nov 2012 11:35:49 +0100 Subject: use Zero::Request instead of the rack one --- lib/zero/controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/zero/controller.rb b/lib/zero/controller.rb index 3c3af8c..76d0f46 100644 --- a/lib/zero/controller.rb +++ b/lib/zero/controller.rb @@ -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 -- cgit v1.2.3-70-g09d2 From 7fa20e6131d652d8dc3304a68dab40bef6e4cd73 Mon Sep 17 00:00:00 2001 From: Gibheer Date: Sat, 17 Nov 2012 13:27:30 +0100 Subject: make a wrapper over the static transform --- lib/zero/renderer.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/zero/renderer.rb b/lib/zero/renderer.rb index 3ae515b..40a9bed 100644 --- a/lib/zero/renderer.rb +++ b/lib/zero/renderer.rb @@ -74,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 -- cgit v1.2.3-70-g09d2 From 019bccd4a2d83571eabb58662f3be44f0f3d9951 Mon Sep 17 00:00:00 2001 From: Gibheer Date: Sat, 17 Nov 2012 14:23:01 +0100 Subject: add a spec controller --- spec/spec_helper.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 154faf4..c345b2c 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,6 +1,11 @@ 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 -- cgit v1.2.3-70-g09d2 From 8e1b79663c1ac1a105e0e1103b4d09c0d897371d Mon Sep 17 00:00:00 2001 From: Gibheer Date: Sat, 17 Nov 2012 14:23:20 +0100 Subject: added a basic spec for the controller --- spec/unit/controller/call_spec.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 spec/unit/controller/call_spec.rb diff --git a/spec/unit/controller/call_spec.rb b/spec/unit/controller/call_spec.rb new file mode 100644 index 0000000..af6f719 --- /dev/null +++ b/spec/unit/controller/call_spec.rb @@ -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 -- cgit v1.2.3-70-g09d2 From 926775f029dfcbedcda087242151dae7ee31b51f Mon Sep 17 00:00:00 2001 From: Gibheer Date: Sat, 17 Nov 2012 14:23:41 +0100 Subject: seperated the methods of the basic controller --- lib/zero/controller.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/zero/controller.rb b/lib/zero/controller.rb index 76d0f46..5784aa0 100644 --- a/lib/zero/controller.rb +++ b/lib/zero/controller.rb @@ -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 -- cgit v1.2.3-70-g09d2 From 495d8f650302d5226cd677b062891ea9021483d5 Mon Sep 17 00:00:00 2001 From: Gibheer Date: Tue, 20 Nov 2012 20:36:25 +0100 Subject: add simplecov to get metrics This only works with MRI, but should be good enough. --- spec/spec_helper.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index c345b2c..909e1e8 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,3 +1,10 @@ +unless RUBY_ENGINE == 'rbx' then + require 'simplecov' + SimpleCov.start do + add_filter '_spec.rb' + end +end + require 'rack' require 'zero/all' -- cgit v1.2.3-70-g09d2