summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2012-01-16 14:05:05 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2012-01-16 14:05:05 +0100
commita9e7b5c1710c5dc5d9f91c4990e0cfa3beee3174 (patch)
tree8a0f0cb4713bc64c3714318a904c9de7b821817e
parent9d964f953f9aedf9362841207683ad0a47e88f30 (diff)
downloadzorglub-a9e7b5c1710c5dc5d9f91c4990e0cfa3beee3174.zip
zorglub-a9e7b5c1710c5dc5d9f91c4990e0cfa3beee3174.tar.gz
Node: remove layout! parameter checks
-rw-r--r--lib/zorglub/node.rb28
-rw-r--r--spec/node_spec.rb4
-rw-r--r--spec/spec_helper.rb19
3 files changed, 30 insertions, 21 deletions
diff --git a/lib/zorglub/node.rb b/lib/zorglub/node.rb
index 9974a20..5ebebc2 100644
--- a/lib/zorglub/node.rb
+++ b/lib/zorglub/node.rb
@@ -13,10 +13,10 @@ module Zorglub
#
class << self
#
- attr_reader :hooks, :inherited_vars
+ attr_reader :hooks, :inherited_vars, :layout
#
def inherited sub
- sub.layout layout
+ sub.layout! layout||(self==Zorglub::Node ? Config.layout : nil )
sub.engine engine
sub.instance_variable_set :@inherited_vars, {}
@inherited_vars.each do |s,v| sub.inherited_var s, *v end
@@ -27,9 +27,12 @@ module Zorglub
@engine ||= Config.engine
end
#
- def layout layout=nil
- @layout = layout unless layout.nil? or layout.empty?
- @layout ||= Config.layout
+ def no_layout!
+ @layout = nil
+ end
+ #
+ def layout! layout
+ @layout = layout
end
#
def static val=nil
@@ -189,14 +192,17 @@ module Zorglub
@options[:engine]
end
#
- def layout layout=nil
- @options[:layout] = layout unless layout.nil? or layout.empty?
- return '' if @options[:layout].nil?
- File.join(Config.layout_base_path, @options[:layout])+ext
+ def no_layout!
+ @options[:layout] = nil
end
#
- def no_layout
- @options[:layout] = nil
+ def layout! layout
+ @options[:layout] = layout
+ end
+ #
+ def layout
+ return '' if @options[:layout].nil?
+ File.join(Config.layout_base_path, @options[:layout])+ext
end
#
def static val=nil
diff --git a/spec/node_spec.rb b/spec/node_spec.rb
index 3e1c957..5c3e2e2 100644
--- a/spec/node_spec.rb
+++ b/spec/node_spec.rb
@@ -172,6 +172,10 @@ describe Zorglub do
r.header['location'].should == Node0.r(:do_partial,1,2,3)
end
#
+ it "no_layout! should be inherited" do
+ Node5.layout.should be_nil
+ end
+ #
it "inherited_vars should be inherited and extended" do
r = Node5.my_call '/index'
vars = YAML.load r.body[0]
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index a531ce9..b29ce0b 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -52,7 +52,7 @@ class Node0 < Zorglub::Node
html
end
def hello
- no_layout
+ no_layout!
'world'
end
def with_2args a1, a2
@@ -71,17 +71,17 @@ class Node0 < Zorglub::Node
redirect r(:do_partial,1,2,3)
end
def xml_file
- no_layout
+ no_layout!
engine :file
ext 'xml'
end
def plain_file
- no_layout
+ no_layout!
engine :file
ext 'txt'
end
def engines name
- no_layout
+ no_layout!
case name
when 'haml'
engine :haml
@@ -90,10 +90,10 @@ class Node0 < Zorglub::Node
end
#
class Node1 < Zorglub::Node
- layout 'layout-1'
+ layout! 'layout-1'
engine 'engine-1'
def index
- layout 'main'
+ layout! 'main'
engine 'engine-2'
end
end
@@ -114,7 +114,7 @@ class Node3 < Zorglub::Node
after_all do |node|
Node3.after +=1
end
- layout 'layout-2'
+ layout! 'layout-2'
engine 'engine-2'
def index
(self.class.before-self.class.after).should == 1
@@ -122,13 +122,12 @@ class Node3 < Zorglub::Node
end
#
class Node4 < Zorglub::Node
+ no_layout!
inherited_var :js,'js0','js1'
def index
- no_layout
inherited_var(:js).to_yaml
end
def more
- no_layout
inherited_var(:js,'js2').to_yaml
end
end
@@ -136,8 +135,8 @@ end
class Node5 < Node4
inherited_var :js, 'js3'
inherited_var :css, 'css0', 'css1'
+ # no_layout! inherited from Node4
def index
- no_layout
js = inherited_var(:js,'jsx')
css = inherited_var(:css, 'css0', 'css1','css2')
js.concat(css).to_yaml