zafu 0.8.2 → 0.8.3
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 +20 -7
- data/lib/zafu/process/ajax.rb +14 -9
- data/lib/zafu/process/context.rb +1 -0
- data/lib/zafu/process/forms.rb +1 -1
- data/test/node_context_test.rb +29 -5
- data/zafu.gemspec +2 -2
- metadata +4 -4
data/History.txt
CHANGED
data/lib/zafu/info.rb
CHANGED
data/lib/zafu/node_context.rb
CHANGED
@@ -51,7 +51,7 @@ module Zafu
|
|
51
51
|
# ivar name (see #master_class).
|
52
52
|
def as_main(after_class = nil)
|
53
53
|
klass = after_class ? master_class(after_class) : single_class
|
54
|
-
res = self.class.new("@#{klass.to_s.underscore}", single_class, nil)
|
54
|
+
res = self.class.new("@#{klass.to_s.underscore}", single_class, nil)
|
55
55
|
res.dom_prefix = self.dom_prefix
|
56
56
|
res
|
57
57
|
end
|
@@ -94,11 +94,14 @@ module Zafu
|
|
94
94
|
str || "<%= #{code} %>"
|
95
95
|
end
|
96
96
|
else
|
97
|
-
@saved_dom_id ||
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
97
|
+
@saved_dom_id || if options[:list]
|
98
|
+
scopes = dom_scopes
|
99
|
+
scopes = [dom_prefix] if scopes.empty?
|
100
|
+
scopes + [make_scope_id]
|
101
|
+
else
|
102
|
+
scopes = dom_scopes
|
103
|
+
scopes + ((@up || scopes.empty?) ? [dom_prefix] : [])
|
104
|
+
end.compact.uniq.join('_')
|
102
105
|
end
|
103
106
|
end
|
104
107
|
|
@@ -173,7 +176,17 @@ module Zafu
|
|
173
176
|
protected
|
174
177
|
# List of scopes defined in ancestry (used to generate dom_id).
|
175
178
|
def dom_scopes
|
176
|
-
|
179
|
+
return [@saved_dom_id] if @saved_dom_id
|
180
|
+
if @up
|
181
|
+
scopes = @up.dom_scopes
|
182
|
+
if @dom_scope
|
183
|
+
(scopes.empty? ? [dom_prefix] : scopes) + [make_scope_id]
|
184
|
+
else
|
185
|
+
scopes
|
186
|
+
end
|
187
|
+
else
|
188
|
+
@dom_scope ? [dom_prefix, make_scope_id] : []
|
189
|
+
end
|
177
190
|
end
|
178
191
|
|
179
192
|
private
|
data/lib/zafu/process/ajax.rb
CHANGED
@@ -36,20 +36,25 @@ module Zafu
|
|
36
36
|
end
|
37
37
|
|
38
38
|
if need_ajax?(each_block)
|
39
|
+
#node.dom_prefix = dom_name
|
39
40
|
# We need to build the templates for ajax rendering.
|
41
|
+
# HACK to avoid changing dom_prefix in drag&drop
|
42
|
+
|
43
|
+
# The bug with wrong prefix between drop inline and ajax result comes from
|
44
|
+
# here (see selenium test drop1 and drop2).
|
45
|
+
node.dom_prefix = dom_name
|
40
46
|
|
41
47
|
# 1. Render inline
|
42
48
|
# assign [] to var
|
43
49
|
out "<% if (#{var} = #{finder[:method]}) || (#{node}.#{finder[:class].first <= Comment ? "can_comment?" : "can_write?"} && #{var}=[]) %>"
|
44
50
|
# The list is not empty or we have enough rights to add new elements.
|
45
51
|
|
46
|
-
node.dom_prefix = dom_name
|
47
|
-
|
48
52
|
# New node context.
|
49
53
|
open_node_context(finder, :node => self.node.move_to(var, finder[:class])) do
|
50
54
|
# Pagination count and other contextual variables exist here.
|
51
55
|
|
52
|
-
|
56
|
+
tmplt_node = self.node.move_to(var, finder[:class])
|
57
|
+
tmplt_node.dom_prefix = node.dom_prefix
|
53
58
|
|
54
59
|
# INLINE ==========
|
55
60
|
out wrap(
|
@@ -72,11 +77,11 @@ module Zafu
|
|
72
77
|
)
|
73
78
|
|
74
79
|
# 2. Save 'each' template
|
75
|
-
store_block(each_block, :node =>
|
80
|
+
store_block(each_block, :node => tmplt_node)
|
76
81
|
|
77
82
|
# 3. Save 'form' template
|
78
83
|
cont = {
|
79
|
-
:saved_template => form_url(
|
84
|
+
:saved_template => form_url(tmplt_node.dom_prefix),
|
80
85
|
:klass => klass,
|
81
86
|
:make_form => each_block == form_block,
|
82
87
|
# Used to get parameters like 'publish', 'done', 'after'
|
@@ -238,8 +243,7 @@ module Zafu
|
|
238
243
|
klass = @context[:klass] || node.single_class
|
239
244
|
|
240
245
|
# New object to render form.
|
241
|
-
new_node = node.move_to("#{var}_new", klass,
|
242
|
-
:new_keys => {})
|
246
|
+
new_node = node.move_to("#{var}_new", klass, :new_keys => {})
|
243
247
|
|
244
248
|
|
245
249
|
if new_node.will_be?(Node)
|
@@ -313,6 +317,7 @@ module Zafu
|
|
313
317
|
if @context[:saved_template]
|
314
318
|
# render to start a saved template
|
315
319
|
node.saved_dom_id = "\#{ndom_id(#{node})}"
|
320
|
+
node.dom_prefix ||= dom_name
|
316
321
|
node.propagate_dom_scope!
|
317
322
|
@markup.set_id(node.dom_id)
|
318
323
|
|
@@ -346,7 +351,7 @@ module Zafu
|
|
346
351
|
|
347
352
|
# Return true if we need to insert the dom id for this element.
|
348
353
|
def need_dom_id?
|
349
|
-
@context[:form] ||
|
354
|
+
@context[:form] || child['unlink'] || (single_child_method && single_child_method == child['drop'])
|
350
355
|
end
|
351
356
|
|
352
357
|
# Unique template_url, ending with dom_id
|
@@ -362,7 +367,7 @@ module Zafu
|
|
362
367
|
# Context is passed when the parent needs to set dom_name on a child
|
363
368
|
# before @context is passed down.
|
364
369
|
def dom_name(context = @context)
|
365
|
-
@
|
370
|
+
@dom_name ||= unique_name(context)
|
366
371
|
end
|
367
372
|
|
368
373
|
# Return a different name on each call
|
data/lib/zafu/process/context.rb
CHANGED
data/lib/zafu/process/forms.rb
CHANGED
@@ -41,7 +41,7 @@ module Zafu
|
|
41
41
|
if v.kind_of?(String)
|
42
42
|
v = "'#{v}'" unless v.kind_of?(String) && ['"', "'"].include?(v[0..0])
|
43
43
|
out "<input type='hidden' name='#{k}' value=#{v}/>"
|
44
|
-
|
44
|
+
elsif v.kind_of?(Array)
|
45
45
|
# We use ['ffff'] to indicate that the content is already escaped and ready for ERB.
|
46
46
|
out v.first
|
47
47
|
end
|
data/test/node_context_test.rb
CHANGED
@@ -261,22 +261,30 @@ class NodeContextTest < Test::Unit::TestCase
|
|
261
261
|
context 'Generating a dom id' do
|
262
262
|
context 'in a blank context' do
|
263
263
|
subject do
|
264
|
-
NodeContext.new('@foo', Page)
|
264
|
+
n = NodeContext.new('@foo', Page)
|
265
|
+
n.dom_prefix = 'list1'
|
266
|
+
n
|
265
267
|
end
|
266
268
|
|
267
269
|
should 'return the node name in DOM id' do
|
268
|
-
assert_equal '<%= @foo.zip %>', subject.dom_id
|
270
|
+
assert_equal '<%= %Q{list1_#{@foo.zip}} %>', subject.dom_id
|
271
|
+
end
|
272
|
+
|
273
|
+
should 'not use zip on list false' do
|
274
|
+
assert_equal 'list1', subject.dom_id(:list => false)
|
269
275
|
end
|
270
276
|
|
271
277
|
should 'scope without erb on erb false' do
|
272
|
-
assert_equal '#{@foo.zip}', subject.dom_id(:erb => false)
|
278
|
+
assert_equal 'list1_#{@foo.zip}', subject.dom_id(:erb => false)
|
273
279
|
end
|
274
280
|
end
|
275
281
|
|
276
282
|
context 'in a hierarchy of contexts' do
|
277
283
|
setup do
|
278
284
|
@a = NodeContext.new('@node', Page)
|
285
|
+
@a.dom_prefix = 'a'
|
279
286
|
@b = NodeContext.new('var1', [Page], @a)
|
287
|
+
@b.dom_prefix = 'b'
|
280
288
|
@c = NodeContext.new('var2', Page, @b)
|
281
289
|
end
|
282
290
|
|
@@ -291,7 +299,22 @@ class NodeContextTest < Test::Unit::TestCase
|
|
291
299
|
end
|
292
300
|
|
293
301
|
should 'use dom_scopes' do
|
294
|
-
assert_equal '<%= %Q{#{var1.zip}_#{var2.zip}_#{var3.zip}} %>', subject.dom_id
|
302
|
+
assert_equal '<%= %Q{b_#{var1.zip}_#{var2.zip}_#{var3.zip}} %>', subject.dom_id
|
303
|
+
end
|
304
|
+
|
305
|
+
should 'use dom_scopes and dom_prefix not in list' do
|
306
|
+
subject.dom_prefix = 'd'
|
307
|
+
assert_equal '<%= %Q{b_#{var1.zip}_#{var2.zip}_d} %>', subject.dom_id(:list => false)
|
308
|
+
end
|
309
|
+
|
310
|
+
context 'with a saved dom_id' do
|
311
|
+
setup do
|
312
|
+
@c.saved_dom_id = '#{ndom_id(@foo)}'
|
313
|
+
end
|
314
|
+
|
315
|
+
should 'use saved id in scope' do
|
316
|
+
assert_equal '<%= %Q{#{ndom_id(@foo)}_#{var3.zip}} %>', subject.dom_id
|
317
|
+
end
|
295
318
|
end
|
296
319
|
end
|
297
320
|
|
@@ -302,7 +325,7 @@ class NodeContextTest < Test::Unit::TestCase
|
|
302
325
|
end
|
303
326
|
|
304
327
|
should 'not use self twice' do
|
305
|
-
assert_equal '<%= %Q{#{@node.zip}_#{var3.zip}} %>', subject.dom_id
|
328
|
+
assert_equal '<%= %Q{a_#{@node.zip}_#{var3.zip}} %>', subject.dom_id
|
306
329
|
end
|
307
330
|
end
|
308
331
|
|
@@ -312,6 +335,7 @@ class NodeContextTest < Test::Unit::TestCase
|
|
312
335
|
end
|
313
336
|
|
314
337
|
should 'use dom_prefix' do
|
338
|
+
subject.dom_prefix = nil
|
315
339
|
assert_equal '<%= %Q{cart_#{var3.zip}} %>', subject.dom_id
|
316
340
|
end
|
317
341
|
end
|
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.8.
|
8
|
+
s.version = "0.8.3"
|
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{2011-07-
|
12
|
+
s.date = %q{2011-07-12}
|
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
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zafu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 57
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 8
|
9
|
-
-
|
10
|
-
version: 0.8.
|
9
|
+
- 3
|
10
|
+
version: 0.8.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Gaspard Bucher
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-07-
|
18
|
+
date: 2011-07-12 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|