From b06ae981c92040fe06c0317f0d12dc3f02044d21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Sun, 11 Sep 2011 19:20:31 +0200 Subject: add Node#partial --- examples/sample.ru | 6 +++++- 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' - "Node2:meth0START#{html}back
END" + "Node2:meth0START#{html}next
END" end # + def meth1 *args + more = Node2.partial :meth0, *args + "Node2:meth1partial
#{more}
done
back" + 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) -- cgit v1.1-2-g2b99