diff options
| author | Jérémy Zurcher <jeremy@asynk.ch> | 2011-09-11 19:20:31 +0200 | 
|---|---|---|
| committer | Jérémy Zurcher <jeremy@asynk.ch> | 2011-09-11 19:20:31 +0200 | 
| commit | b06ae981c92040fe06c0317f0d12dc3f02044d21 (patch) | |
| tree | f1f541d55977be1f1e20e6e7bb10810a2863cf67 | |
| parent | cfe72087d3179c2e80f923f9061d9450714a1547 (diff) | |
| download | zorglub-b06ae981c92040fe06c0317f0d12dc3f02044d21.zip zorglub-b06ae981c92040fe06c0317f0d12dc3f02044d21.tar.gz | |
add Node#partial
| -rw-r--r-- | examples/sample.ru | 6 | ||||
| -rw-r--r-- | lib/zorglub/node.rb | 28 | 
2 files changed, 25 insertions, 9 deletions
| diff --git a/examples/sample.ru b/examples/sample.ru index 00d1b7a..67937ac 100644 --- a/examples/sample.ru +++ b/examples/sample.ru @@ -70,9 +70,13 @@ class Node2 < Zorglub::Node      def meth0 *args          # instance level css          css 'instance_level.css' -        "<title>Node2:meth0</title><b>START</b>#{html}<a href=#{Node0.r}>back</a><br/><b>END</b>" +        "<title>Node2:meth0</title><b>START</b>#{html}<a href=#{Node2.r(:meth1,1,2)}>next</a><br/><b>END</b>"      end      # +    def meth1 *args +        more = Node2.partial :meth0, *args +        "<title>Node2:meth1</title><b>partial</b><br/>#{more}<br/><b>done</b><br/><a href=#{Node0.r}>back</a>" +    end  end  #  class Node3 < Zorglub::Node diff --git a/lib/zorglub/node.rb b/lib/zorglub/node.rb index a161cb6..6e0989f 100644 --- a/lib/zorglub/node.rb +++ b/lib/zorglub/node.rb @@ -32,7 +32,14 @@ module Zorglub                  meth||= 'index'                  node = self.new env, {:engine=>engine,:layout=>layout,:view=>r(meth),:method=>meth,:args=>args}                  return error_404 node if not node.respond_to? meth -                node.realize +                node.realize! +            end +            # +            def partial meth, *args +                node = self.new nil, {:engine=>engine,:layout=>'',:view=>r(meth),:method=>meth.to_s,:args=>args} +                return error_404 node if not node.respond_to? meth +                node.feed! +                node.content              end              #              def error_404 node @@ -45,7 +52,7 @@ module Zorglub              #          end          # -        attr_reader :action, :request, :response +        attr_reader :action, :request, :response, :content          #          def initialize env, action              @env = env @@ -54,19 +61,24 @@ module Zorglub              @response = Rack::Response.new          end          # -        def realize +        def realize!              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 +                feed!                  response.write @content                  response.finish                  response              }          end          # +        def feed! +            @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 +            @content +        end +        #          def redirect target, options={}, &block              status = options[:status] || 302              body   = options[:body] || redirect_body(target) | 
