diff options
| author | Jérémy Zurcher <jeremy@asynk.ch> | 2011-09-11 00:47:01 +0200 | 
|---|---|---|
| committer | Jérémy Zurcher <jeremy@asynk.ch> | 2011-09-11 01:03:24 +0200 | 
| commit | cfe72087d3179c2e80f923f9061d9450714a1547 (patch) | |
| tree | dfdf53ce9e578713bf7a1db8d9c304a581fa704a /lib | |
| parent | 889cdf7749217c0425e2984cf13d7791ad79cb48 (diff) | |
| download | zorglub-cfe72087d3179c2e80f923f9061d9450714a1547.zip zorglub-cfe72087d3179c2e80f923f9061d9450714a1547.tar.gz  | |
implement Node#redirect + add tests in sample.ru
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/zorglub/node.rb | 28 | 
1 files changed, 21 insertions, 7 deletions
diff --git a/lib/zorglub/node.rb b/lib/zorglub/node.rb index 357b97f..a161cb6 100644 --- a/lib/zorglub/node.rb +++ b/lib/zorglub/node.rb @@ -55,13 +55,27 @@ module Zorglub          end          #          def realize -            @content = self.send @action[:method], *@action[:args] -            e, v, l = Config.engine_proc(@action[:engine]), view, layout -            # TODO compile and cache -            @content = e.call v, self if e and File.exists? v -            @content = e.call l, self if e and File.exists? l -            response.write @content -            response.finish +            catch(:stop_realize) { +                @content = self.send @action[:method], *@action[:args] +                e, v, l = Config.engine_proc(@action[:engine]), view, layout +                # TODO compile and cache +                @content = e.call v, self if e and File.exists? v +                @content = e.call l, self if e and File.exists? l +                response.write @content +                response.finish +                response +            } +        end +        # +        def redirect target, options={}, &block +            status = options[:status] || 302 +            body   = options[:body] || redirect_body(target) +            header = response.header.merge('Location' => target.to_s) +            throw :stop_realize, Rack::Response.new(body, status, header, &block) +        end +        # +        def redirect_body target +            "You are being redirected, please follow this link to: <a href='#{target}'>#{target}</a>!"          end          #          def engine engine=nil  | 
