tree_decorator 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -5,7 +5,7 @@ TreeDecorator has been designed to make it easier to decorate trees or nested
5
5
  sets of data. The tools provided, walk through a hash or nested object and
6
6
  apply code to containers and elements based on user defined rules.
7
7
 
8
- For example:
8
+ For an example of how TreeDecorator can be used in Rails:
9
9
 
10
10
  class Thing < ActiveRecord::Base
11
11
  acts_as_nested_set
@@ -15,16 +15,13 @@ For example:
15
15
  end
16
16
  end
17
17
 
18
- hanger = TreeDecorator::ObjectHanger.new(
19
- Thing.roots,
20
- :children_method => :children
21
- )
18
+ hanger = TreeDecorator::ObjectHanger.new(Thing.roots)
22
19
 
23
20
  hanger.outer {|content| content_tag('ul', content.html_safe)}
24
21
  hanger.inner {|content| content_tag('li', content.html_safe)}
25
- hanger.element {|content| content_tag('span', content.name, :class => 'thing')}
22
+ hanger.element {|thing| link_to(thing.name, thing_path(thing))}
26
23
 
27
24
  hanger.tree #----> outputs a nested HTML unordered list with each thing's name
28
- # in a span of class 'thing'.
25
+ # linking to it's default path.
29
26
 
30
27
  See lib/example and tests for examples of usage
@@ -7,9 +7,11 @@ module TreeDecorator
7
7
  class ObjectHanger < Hanger
8
8
  attr_reader :children_method, :content_method
9
9
 
10
+ DEFAULT_CHILDREN_METHOD = :children
11
+
10
12
  def initialize(root, args = {})
11
13
  @root = root
12
- @children_method = args[:children_method]
14
+ @children_method = args[:children_method] || DEFAULT_CHILDREN_METHOD
13
15
  @tree = hash
14
16
  end
15
17
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tree_decorator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: