lib/happy/controller/actions.rb in happy-0.1.0.pre19 vs lib/happy/controller/actions.rb in happy-0.1.0.pre20

- old
+ new

@@ -6,11 +6,11 @@ # Don't serve is data is not a string. return unless data.is_a?(String) # Mix in default options options = { - :layout => context.layout + :layout => response.layout }.merge(options) # Add status code from options response.status = options.delete(:status) if options.has_key?(:status) @@ -29,13 +29,13 @@ response.body = [data] halt! end end - def halt!(message = :done) + def halt!(message = :done, what = nil) only_if_path_matches do - throw message + throw message, what || response end end def redirect!(to, status = 302) only_if_path_matches do @@ -44,11 +44,11 @@ halt! end end def layout(name) - context.layout = name + response.layout = name end def content_type(type) header :content_type, type end @@ -77,15 +77,14 @@ end def run(thing, options = {}, &blk) if thing.is_a?(Class) && thing.ancestors.include?(Happy::Controller) # Happy controllers! - thing.new(env, options, &blk).perform + thing.new(self, options, &blk).route elsif thing.respond_to?(:call) # Rack apps! - context.response = thing.call(request.env) - throw :done + throw :done, thing.call(request.env) elsif thing.respond_to?(:to_s) thing.to_s else raise "Don't know how to run #{thing.inspect} :(" end @@ -97,10 +96,10 @@ # Execute the provided block, unless there are still bits of # unprocessed path left (which indicates that the current path # is not the path the user requested.) # def only_if_path_matches - yield if remaining_path.empty? + yield if unprocessed_path.empty? end end end end