tree_decorator 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +4 -4
- data/lib/tree_decorator/object_hanger.rb +2 -2
- metadata +1 -1
data/README.md
CHANGED
@@ -16,14 +16,14 @@ For example:
|
|
16
16
|
end
|
17
17
|
|
18
18
|
hanger = TreeDecorator::ObjectHanger.new(
|
19
|
-
Thing.roots,
|
19
|
+
Thing.roots.to_a,
|
20
20
|
:children_method => :children,
|
21
21
|
:content_method => :name
|
22
22
|
)
|
23
23
|
|
24
|
-
hanger.outer {|content|
|
25
|
-
hanger.inner {|content|
|
26
|
-
hanger.element {|content|
|
24
|
+
hanger.outer {|content| content_tag('ul', content.html_safe)}
|
25
|
+
hanger.inner {|content| content_tag('li', content.html_safe)}
|
26
|
+
hanger.element {|content| content_tag('span', content.html_safe, :class => 'thing')}
|
27
27
|
|
28
28
|
hanger.tree #----> outputs a nested HTML unordered list with each thing's name
|
29
29
|
# in a span of class 'thing'.
|
@@ -26,12 +26,12 @@ module TreeDecorator
|
|
26
26
|
|
27
27
|
def populate_with_children(object)
|
28
28
|
content = Hash.new
|
29
|
-
children = object.respond_to?(:each) ? object : object.send(children_method)
|
29
|
+
children = object.respond_to?(:each) ? object.to_a : object.send(children_method)
|
30
30
|
|
31
31
|
if children and !children.empty?
|
32
32
|
children.each do |child|
|
33
33
|
unless child.respond_to? content_method
|
34
|
-
raise "
|
34
|
+
raise "#{child.class.to_s} does not have :#{content_method} method: #{child.inspect}"
|
35
35
|
end
|
36
36
|
content[child.send(content_method)] = populate_with_children(child)
|
37
37
|
end
|