2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/forge/app/helpers/forge/tree_helper.rb', line 2
def nested_li(objects, &block)
objects = objects.order(:lft) if objects.is_a? Class
return '' if objects.size == 0
output = %{<li class="top">\n<div class="item-content">\n}
path = [nil]
objects.each_with_index do |o, i|
if o.parent_id != path.last
if path.include?(o.parent_id)
while path.last != o.parent_id
path.pop
output << %{\n</li>\n</ul>}
end
if o.parent_id
output << %{\n</li>\n<li class="subpage">\n}
else
output << %{\n</li>\n<li class="top">\n<div class="item-content">\n}
end
else
path << o.parent_id
output << %{\n<ul class="subpages">\n<li class="subpage">\n}
end
elsif i != 0
if o.parent_id
output << %{\n</li>\n<li class="subpage">\n}
else
output << %{\n</li>\n<li class="top">\n<div class="item-content">\n}
end
end
output << capture(o, path.size - 1, &block)
end
path.each do |p|
if p
output << %{\n</li>\n</ul>}
else
output << %{\n</div>\n</li>}
end
end
output.html_safe
end
|