awesome_nested_set 2.1.6 → 3.0.0.rc.6

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/README.rdoc DELETED
@@ -1,153 +0,0 @@
1
- = AwesomeNestedSet
2
-
3
- Awesome Nested Set is an implementation of the nested set pattern for ActiveRecord models. It is replacement for acts_as_nested_set and BetterNestedSet, but more awesome.
4
-
5
- Version 2 supports Rails 3. Gem versions prior to 2.0 support Rails 2.
6
-
7
- == What makes this so awesome?
8
-
9
- This is a new implementation of nested set based off of BetterNestedSet that fixes some bugs, removes tons of duplication, adds a few useful methods, and adds STI support.
10
-
11
- == Installation
12
-
13
- Add to your Gemfile:
14
-
15
- gem 'awesome_nested_set'
16
-
17
- == Usage
18
-
19
- To make use of awesome_nested_set, your model needs to have 3 fields: lft, rgt, and parent_id.
20
- You can also have an optional field: depth:
21
-
22
- class CreateCategories < ActiveRecord::Migration
23
- def self.up
24
- create_table :categories do |t|
25
- t.string :name
26
- t.integer :parent_id
27
- t.integer :lft
28
- t.integer :rgt
29
- t.integer :depth # this is optional.
30
- end
31
- end
32
-
33
- def self.down
34
- drop_table :categories
35
- end
36
- end
37
-
38
- Enable the nested set functionality by declaring acts_as_nested_set on your model
39
-
40
- class Category < ActiveRecord::Base
41
- acts_as_nested_set
42
- end
43
-
44
- Run `rake rdoc` to generate the API docs and see CollectiveIdea::Acts::NestedSet for more info.
45
-
46
- == Callbacks
47
-
48
- There are three callbacks called when moving a node. `before_move`, `after_move` and `around_move`.
49
-
50
- class Category < ActiveRecord::Base
51
- acts_as_nested_set
52
-
53
- after_move :rebuild_slug
54
- around_move :da_fancy_things_around
55
-
56
- private
57
-
58
- def rebuild_slug
59
- # do whatever
60
- end
61
-
62
- def da_fancy_things_around
63
- # do something...
64
- yield # actually moves
65
- # do something else...
66
- end
67
- end
68
-
69
- Beside this there are also hooks to act on the newly added or removed children.
70
-
71
- class Category < ActiveRecord::Base
72
- acts_as_nested_set :before_add => :do_before_add_stuff,
73
- :after_add => :do_after_add_stuff,
74
- :before_remove => :do_before_remove_stuff,
75
- :after_remove => :do_after_remove_stuff
76
-
77
- private
78
-
79
- def do_before_add_stuff(child_node)
80
- # do whatever with the child
81
- end
82
-
83
- def do_after_add_stuff(child_node)
84
- # do whatever with the child
85
- end
86
-
87
- def do_before_remove_stuff(child_node)
88
- # do whatever with the child
89
- end
90
-
91
- def do_after_remove_stuff(child_node)
92
- # do whatever with the child
93
- end
94
- end
95
-
96
-
97
- == Protecting attributes from mass assignment
98
-
99
- It's generally best to "white list" the attributes that can be used in mass assignment:
100
-
101
- class Category < ActiveRecord::Base
102
- acts_as_nested_set
103
- attr_accessible :name, :parent_id
104
- end
105
-
106
- If for some reason that is not possible, you will probably want to protect the lft and rgt attributes:
107
-
108
- class Category < ActiveRecord::Base
109
- acts_as_nested_set
110
- attr_protected :lft, :rgt
111
- end
112
-
113
- == Conversion from other trees
114
-
115
- Coming from acts_as_tree or another system where you only have a parent_id? No problem. Simply add the lft & rgt fields as above, and then run
116
-
117
- Category.rebuild!
118
-
119
- Your tree will be converted to a valid nested set. Awesome!
120
-
121
- == View Helper
122
-
123
- The view helper is called #nested_set_options.
124
-
125
- Example usage:
126
-
127
- <%= f.select :parent_id, nested_set_options(Category, @category) {|i| "#{'-' * i.level} #{i.name}" } %>
128
-
129
- <%= select_tag 'parent_id', options_for_select(nested_set_options(Category) {|i| "#{'-' * i.level} #{i.name}" } ) %>
130
-
131
- See CollectiveIdea::Acts::NestedSet::Helper for more information about the helpers.
132
-
133
- == References
134
-
135
- You can learn more about nested sets at: http://threebit.net/tutorials/nestedset/tutorial1.html
136
-
137
- == How to contribute
138
-
139
- If you find what you might think is a bug:
140
-
141
- 1. Check the GitHub issue tracker to see if anyone else has had the same issue.
142
- https://github.com/collectiveidea/awesome_nested_set/issues/
143
- 2. If you don't see anything, create an issue with information on how to reproduce it.
144
-
145
- If you want to contribute an enhancement or a fix:
146
-
147
- 1. Fork the project on GitHub.
148
- https://github.com/collectiveidea/awesome_nested_set/
149
- 2. Make your changes with tests.
150
- 3. Commit the changes without making changes to the Rakefile, VERSION, or any other files that aren't related to your enhancement or fix
151
- 4. Send a pull request.
152
-
153
- Copyright ©2008 Collective Idea, released under the MIT license