zafu 0.7.1 → 0.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +5 -0
- data/lib/zafu/info.rb +1 -1
- data/lib/zafu/node_context.rb +18 -15
- data/test/node_context_test.rb +29 -0
- data/zafu.gemspec +2 -2
- metadata +3 -3
data/History.txt
CHANGED
data/lib/zafu/info.rb
CHANGED
data/lib/zafu/node_context.rb
CHANGED
@@ -31,10 +31,14 @@ module Zafu
|
|
31
31
|
name
|
32
32
|
end
|
33
33
|
|
34
|
+
def single_class
|
35
|
+
@single_class ||= Array(klass).flatten.first
|
36
|
+
end
|
37
|
+
|
34
38
|
# Return true if the NodeContext represents an element of the given type. We use 'will_be' because
|
35
39
|
# it is equivalent to 'is_a', but for future objects (during rendering).
|
36
40
|
def will_be?(type)
|
37
|
-
|
41
|
+
single_class.ancestors.include?(type)
|
38
42
|
end
|
39
43
|
|
40
44
|
# Return a new node context that corresponds to the current object when rendered alone (in an ajax response or
|
@@ -43,16 +47,15 @@ module Zafu
|
|
43
47
|
# You can also use an 'after_class' parameter to move up in the current object's class hierarchy to get
|
44
48
|
# ivar name (see #master_class).
|
45
49
|
def as_main(after_class = nil)
|
46
|
-
klass = after_class ? master_class(after_class) :
|
47
|
-
NodeContext.new("@#{klass.to_s.underscore}",
|
50
|
+
klass = after_class ? master_class(after_class) : single_class
|
51
|
+
NodeContext.new("@#{klass.to_s.underscore}", single_class)
|
48
52
|
end
|
49
53
|
|
50
54
|
# Find the class just afer 'after_class' in the class hierarchy.
|
51
55
|
# For example if we have Dog < Mamal < Animal < Creature,
|
52
56
|
# master_class(Creature) would return Animal
|
53
57
|
def master_class(after_class)
|
54
|
-
klass =
|
55
|
-
klass = klass.first if klass.kind_of?(Array)
|
58
|
+
klass = single_class
|
56
59
|
begin
|
57
60
|
up = klass.superclass
|
58
61
|
return klass if up == after_class
|
@@ -95,16 +98,16 @@ module Zafu
|
|
95
98
|
end
|
96
99
|
|
97
100
|
def get(klass)
|
98
|
-
if
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
101
|
+
if single_class <= klass
|
102
|
+
return self unless list_context?
|
103
|
+
|
104
|
+
res_class = self.klass
|
105
|
+
method = self.name
|
106
|
+
while res_class.kind_of?(Array)
|
107
|
+
method = "#{method}.first"
|
108
|
+
res_class = res_class.first
|
105
109
|
end
|
106
|
-
|
107
|
-
return self
|
110
|
+
move_to(method, res_class)
|
108
111
|
elsif @up
|
109
112
|
@up.get(klass)
|
110
113
|
else
|
@@ -130,7 +133,7 @@ module Zafu
|
|
130
133
|
# FIXME: just use klass.to_s (so that we can do clever things with 'to_s')
|
131
134
|
def class_name
|
132
135
|
if list_context?
|
133
|
-
klass =
|
136
|
+
klass = single_class
|
134
137
|
"[#{(klass.name.blank? ? klass.superclass : klass).name}]"
|
135
138
|
else
|
136
139
|
(@klass.name.blank? ? @klass.superclass : @klass).name
|
data/test/node_context_test.rb
CHANGED
@@ -229,6 +229,35 @@ class NodeContextTest < Test::Unit::TestCase
|
|
229
229
|
end
|
230
230
|
end
|
231
231
|
|
232
|
+
context 'In a deeply nested list context' do
|
233
|
+
setup do
|
234
|
+
@grandma = NodeContext.new('@page', SubPage)
|
235
|
+
@mother = @grandma.move_to('@comment', Comment)
|
236
|
+
end
|
237
|
+
|
238
|
+
subject do
|
239
|
+
@mother.move_to('list', [[[Page]]])
|
240
|
+
end
|
241
|
+
|
242
|
+
should 'find the context and resolve with first' do
|
243
|
+
assert context = subject.get(Page)
|
244
|
+
assert_equal 'list.first.first.first', context.name
|
245
|
+
assert_equal Page, context.klass
|
246
|
+
end
|
247
|
+
|
248
|
+
should 'return parent on up with class' do
|
249
|
+
assert_equal @grandma, subject.up(Page)
|
250
|
+
end
|
251
|
+
|
252
|
+
should 'return true on will_be with the same class' do
|
253
|
+
assert subject.will_be?(Page)
|
254
|
+
end
|
255
|
+
|
256
|
+
should 'return class on master_class' do
|
257
|
+
assert_equal Page, subject.master_class(ActiveRecord::Base)
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
232
261
|
context 'Generating a dom id' do
|
233
262
|
context 'in a blank context' do
|
234
263
|
subject do
|
data/zafu.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{zafu}
|
8
|
-
s.version = "0.7.
|
8
|
+
s.version = "0.7.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Gaspard Bucher"]
|
12
|
-
s.date = %q{2010-09-
|
12
|
+
s.date = %q{2010-09-22}
|
13
13
|
s.description = %q{Provides a powerful templating language based on xhtml for rails}
|
14
14
|
s.email = %q{gaspard@teti.ch}
|
15
15
|
s.extra_rdoc_files = [
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 7
|
8
|
-
-
|
9
|
-
version: 0.7.
|
8
|
+
- 2
|
9
|
+
version: 0.7.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Gaspard Bucher
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-09-
|
17
|
+
date: 2010-09-22 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|