From e02cbcfae357acd51811b9ee0ddb353b7b4bb48c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Fri, 1 Feb 2013 10:59:17 +0100 Subject: Node#partial: add first param env, allow by passing hooks --- Changelog | 2 ++ lib/zorglub/node.rb | 12 ++++++------ spec/node_spec.rb | 20 ++++++++++++++++++-- spec/spec_helper.rb | 4 ++++ 4 files changed, 30 insertions(+), 8 deletions(-) diff --git a/Changelog b/Changelog index d6ccf5c..b224a98 100644 --- a/Changelog +++ b/Changelog @@ -4,6 +4,8 @@ * before_all and after_all accept parameter or proc * use instance variables instead of @options hash * add optional cache_lifetime to static pages + * add firs parameter env to Node#partial + * allow by passing hooks in partials 2013-01-08 Jérémy Zurcher * release 0.6 diff --git a/lib/zorglub/node.rb b/lib/zorglub/node.rb index d22c1c9..d4057db 100644 --- a/lib/zorglub/node.rb +++ b/lib/zorglub/node.rb @@ -228,10 +228,10 @@ module Zorglub node.realize! end # - def partial meth, *args - node = self.new nil, meth.to_s, args, true + def partial env, meth, *args + node = self.new env, meth.to_s, args, true return error_404 node if not node.respond_to? meth - node.feed! + node.feed! env[:no_hooks] node.content end # @@ -274,9 +274,9 @@ module Zorglub } end # - def feed! + def feed! no_hooks=false @state = :pre_cb - self.class.call_before_hooks self + self.class.call_before_hooks self unless no_hooks @state = :meth @content = self.send @meth, *@args static_path = static @@ -286,7 +286,7 @@ module Zorglub static_page! static_path end @state = :post_cb - self.class.call_after_hooks self + self.class.call_after_hooks self unless no_hooks @state = :finished return @content, @mime end diff --git a/spec/node_spec.rb b/spec/node_spec.rb index 654966f..021aea5 100644 --- a/spec/node_spec.rb +++ b/spec/node_spec.rb @@ -167,11 +167,27 @@ describe Zorglub do end # it "partial should render correctly" do - Node0.partial(:do_partial, 1, 2).should == 'partial_content' + Node0.partial({},:do_partial, 1, 2).should == 'partial_content' end # it "method level view should work" do - Node0.partial(:other_view).should == 'partial_content' + Node0.partial({},:other_view).should == 'partial_content' + end + # + it "partial with hooks should be default" do + Node3.before = 0 + Node3.after = 0 + Node3.partial({},:do_partial,1,2).should == 'partial_content' + Node3.before.should == 1 + Node3.after.should == 1 + end + # + it "partial without hooks should work" do + Node3.before = 0 + Node3.after = 0 + Node3.partial({:no_hooks=>true},:do_partial,1,2).should == 'partial_content' + Node3.before.should == 0 + Node3.after.should == 0 end # it "static pages should be generated" do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 4d6740d..3347cf6 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -116,6 +116,10 @@ class Node3 < Zorglub::Node def index (Node3.before-Node3.after).should == 1 end + def do_partial a1, a2 + view! Node0.r('do_partial') + engine! 'real' + end end # class Node8 < Node3 -- cgit v1.1-2-g2b99