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