sortable_nested_set 0.3.0 → 0.4.0

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.
@@ -2,27 +2,27 @@ GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
4
  abstract (1.0.0)
5
- actionpack (3.0.3)
6
- activemodel (= 3.0.3)
7
- activesupport (= 3.0.3)
5
+ actionpack (3.0.4)
6
+ activemodel (= 3.0.4)
7
+ activesupport (= 3.0.4)
8
8
  builder (~> 2.1.2)
9
9
  erubis (~> 2.6.6)
10
10
  i18n (~> 0.4)
11
11
  rack (~> 1.2.1)
12
12
  rack-mount (~> 0.6.13)
13
- rack-test (~> 0.5.6)
13
+ rack-test (~> 0.5.7)
14
14
  tzinfo (~> 0.3.23)
15
- activemodel (3.0.3)
16
- activesupport (= 3.0.3)
15
+ activemodel (3.0.4)
16
+ activesupport (= 3.0.4)
17
17
  builder (~> 2.1.2)
18
18
  i18n (~> 0.4)
19
- activerecord (3.0.3)
20
- activemodel (= 3.0.3)
21
- activesupport (= 3.0.3)
19
+ activerecord (3.0.4)
20
+ activemodel (= 3.0.4)
21
+ activesupport (= 3.0.4)
22
22
  arel (~> 2.0.2)
23
23
  tzinfo (~> 0.3.23)
24
- activesupport (3.0.3)
25
- arel (2.0.7)
24
+ activesupport (3.0.4)
25
+ arel (2.0.8)
26
26
  builder (2.1.2)
27
27
  erubis (2.6.6)
28
28
  abstract (>= 1.0.0)
@@ -32,7 +32,7 @@ GEM
32
32
  bundler (~> 1.0.0)
33
33
  git (>= 1.2.5)
34
34
  rake
35
- nested_set (1.6.3)
35
+ nested_set (1.6.4)
36
36
  activerecord (>= 3.0.0)
37
37
  railties (>= 3.0.0)
38
38
  rack (1.2.1)
@@ -40,9 +40,9 @@ GEM
40
40
  rack (>= 1.0.0)
41
41
  rack-test (0.5.7)
42
42
  rack (>= 1.0)
43
- railties (3.0.3)
44
- actionpack (= 3.0.3)
45
- activesupport (= 3.0.3)
43
+ railties (3.0.4)
44
+ actionpack (= 3.0.4)
45
+ activesupport (= 3.0.4)
46
46
  rake (>= 0.8.7)
47
47
  thor (~> 0.14.4)
48
48
  rake (0.8.7)
@@ -18,10 +18,6 @@ In each "Category" (e.g. "Directory") migration:
18
18
  In the routing configuration file:
19
19
  nest the "Category" and "Item" resources
20
20
 
21
- In each "Category" model:
22
- acts_as_sortable_nested_set_of :items
23
- where :items is the pluralized, underscored "Item" model (e.g. "ImageFile"=>:image_files).
24
-
25
21
  In the "Category" and "Item" controllers:
26
22
  [new] use param[:category_id]
27
23
  [destroy] respond_to format.js (and provide associated view)
@@ -33,9 +29,17 @@ In the <head> section of the layout(s) where the trees will be displayed:
33
29
  yield(:head)
34
30
  after jQuery is loaded.
35
31
 
32
+ In each "Category" model:
33
+ acts_as_sortable_nested_set_of :items
34
+ where :items is the pluralized, underscored "Item" model (e.g. "ImageFile"=>:image_files).
35
+
36
+ == Options
37
+
38
+ :order specifies the order which "Items" will be sorted in. Defaults to nil unless "Item" acts_as_list.
39
+
36
40
  == Support for acts_as_list
37
41
 
38
- When an "Item" model acts_as_list, SortableNestedSet will use its position for sorting.
42
+ When an "Item" model acts_as_list, SortableNestedSet will automatically use its position for sorting.
39
43
 
40
44
  == Helpers
41
45
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.4.0
@@ -18,8 +18,8 @@ module SortableNestedSetHelper
18
18
 
19
19
  ancestors = category.send(options[:include_self] ? :self_and_ancestors : :ancestors)
20
20
 
21
- links = ancestors.select([:id, :name]).collect do |c|
22
- link_to c.name, c, :class => :lineage
21
+ links = ancestors.collect do |c|
22
+ link_to c, c, :class => :lineage
23
23
  end
24
24
 
25
25
  content_tag :p, links.join.html_safe unless links.empty?
@@ -1,4 +1,4 @@
1
- <li id="<%= "#{item.class.name.underscore}_#{item.id}" %>" class="sns_item">
1
+ <%= content_tag_for :li, item, :class => :sns_item do %>
2
2
  <div>
3
3
  <div class="handle"><%= item %></div>
4
4
  <%= link_to image_tag('mega_menu.png'), item, :class => :mega_menu %>
@@ -8,4 +8,4 @@
8
8
  <%= link_to 'remove', item, :confirm => 'Are you sure?', :method => :delete, :remote => true %>
9
9
  </div>
10
10
  </div>
11
- </li>
11
+ <% end %>
@@ -8,9 +8,9 @@
8
8
  <%= render_tree categories, :id => :sns_categories,
9
9
  :class => :sortable,
10
10
  'data-url' => sns_sort_path(:category_class => @category_class) do |category, child| %>
11
- <li id="<%= category.class.name.underscore %>_<%= category.id %>" class="sns_category">
11
+ <%= content_tag_for :li, category, :class => :sns_category do %>
12
12
  <%= render :partial => 'sortable_nested_set/category', :object => category %>
13
13
  <ul><%= render :partial => 'sortable_nested_set/item', :collection => category.sns_items %></ul>
14
14
  <%= child %>
15
- </li>
15
+ <% end %>
16
16
  <% end %>
@@ -1,3 +1,3 @@
1
- Rails::Application.routes.draw do
1
+ Rails.application.routes.draw do
2
2
  put :sns_sort, :controller => :sortable_nested_set
3
3
  end
@@ -7,7 +7,7 @@ module SortableNestedSet
7
7
  end
8
8
 
9
9
  module ClassMethods
10
- def acts_as_sortable_nested_set_of(items_type)
10
+ def acts_as_sortable_nested_set_of(items_type, options={})
11
11
  @subcategories_type = "sub#{name.tableize}".to_sym
12
12
  @items_type = items_type
13
13
  @foreign_key = self.class.method_defined?(:parent) ? :parent_id : name.foreign_key
@@ -23,20 +23,18 @@ module SortableNestedSet
23
23
  define_method(:sns_items) { send(self.class.sns_items_type) }
24
24
  end
25
25
 
26
+ options[:order] ||= sns_items_class.new.position_column if sns_items_class.method_defined?(:position_column)
27
+
26
28
  acts_as_nested_set :parent_column => @foreign_key
27
29
 
28
30
  has_many @subcategories_type, :class_name => name, :foreign_key => @foreign_key, :dependent => :destroy
29
- has_many @items_type,
30
- :order => (sns_items_class.position_column if sns_items_class.method_defined?(:position_column)),
31
- :dependent => :destroy
32
-
33
- after_initialize :default_depth_to_zero
31
+ has_many @items_type, :order => options[:order], :dependent => :destroy
34
32
  end
35
33
  end
36
34
 
37
35
  module InstanceMethods
38
- def indented_name(indentation_character='.')
39
- indentation_character * depth + name
36
+ def self_and_descendants_with_sns_items
37
+ self_and_descendants.includes(self.class.sns_items_type).collect { |category| [category, category.sns_items] }.flatten
40
38
  end
41
39
 
42
40
  def move(parent, children)
@@ -55,12 +53,6 @@ module SortableNestedSet
55
53
  end
56
54
  end
57
55
  end
58
-
59
- private
60
-
61
- def default_depth_to_zero
62
- self.depth ||= 0 if has_attribute?(:depth)
63
- end
64
56
  end
65
57
  end
66
58
 
@@ -43,6 +43,10 @@
43
43
  margin: 0;
44
44
  }
45
45
 
46
+ #sns_categories li.sns_category div > span.handle {
47
+ font-variant: small-caps;
48
+ }
49
+
46
50
  .placeholder {
47
51
  background-color: #cfcfcf;
48
52
  }
@@ -52,11 +56,11 @@
52
56
  color: #8a1f11;
53
57
  }
54
58
 
55
- #sns_categories span.open {
59
+ #sns_categories .open {
56
60
  background: url(/images/folder_open.png) no-repeat center;
57
61
  }
58
62
 
59
- #sns_categories span.closed {
63
+ #sns_categories .closed {
60
64
  background: url(/images/folder_closed.png) no-repeat center;
61
65
  }
62
66
 
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{sortable_nested_set}
8
- s.version = "0.3.0"
8
+ s.version = "0.4.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jason Murad"]
12
- s.date = %q{2011-01-25}
12
+ s.date = %q{2011-02-13}
13
13
  s.description = %q{reusable menu for navigation and modification or hierarchical categories}
14
14
  s.email = %q{jason@thriess.com}
15
15
  s.extra_rdoc_files = [
@@ -44,7 +44,7 @@ Gem::Specification.new do |s|
44
44
  s.homepage = %q{http://github.com/jrmurad/sortable_nested_set}
45
45
  s.licenses = ["MIT"]
46
46
  s.require_paths = ["lib"]
47
- s.rubygems_version = %q{1.3.7}
47
+ s.rubygems_version = %q{1.5.0}
48
48
  s.summary = %q{reusable menu for navigation and modification or hierarchical categories}
49
49
  s.test_files = [
50
50
  "test/helper.rb",
@@ -52,7 +52,6 @@ Gem::Specification.new do |s|
52
52
  ]
53
53
 
54
54
  if s.respond_to? :specification_version then
55
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
56
55
  s.specification_version = 3
57
56
 
58
57
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
metadata CHANGED
@@ -1,12 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sortable_nested_set
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 3
8
- - 0
9
- version: 0.3.0
4
+ prerelease:
5
+ version: 0.4.0
10
6
  platform: ruby
11
7
  authors:
12
8
  - Jason Murad
@@ -14,7 +10,7 @@ autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
12
 
17
- date: 2011-01-25 00:00:00 -05:00
13
+ date: 2011-02-13 00:00:00 -05:00
18
14
  default_executable:
19
15
  dependencies:
20
16
  - !ruby/object:Gem::Dependency
@@ -24,8 +20,6 @@ dependencies:
24
20
  requirements:
25
21
  - - ">="
26
22
  - !ruby/object:Gem::Version
27
- segments:
28
- - 0
29
23
  version: "0"
30
24
  type: :runtime
31
25
  prerelease: false
@@ -37,8 +31,6 @@ dependencies:
37
31
  requirements:
38
32
  - - ">="
39
33
  - !ruby/object:Gem::Version
40
- segments:
41
- - 0
42
34
  version: "0"
43
35
  type: :development
44
36
  prerelease: false
@@ -50,10 +42,6 @@ dependencies:
50
42
  requirements:
51
43
  - - ~>
52
44
  - !ruby/object:Gem::Version
53
- segments:
54
- - 1
55
- - 0
56
- - 0
57
45
  version: 1.0.0
58
46
  type: :development
59
47
  prerelease: false
@@ -65,10 +53,6 @@ dependencies:
65
53
  requirements:
66
54
  - - ~>
67
55
  - !ruby/object:Gem::Version
68
- segments:
69
- - 1
70
- - 5
71
- - 1
72
56
  version: 1.5.1
73
57
  type: :development
74
58
  prerelease: false
@@ -80,8 +64,6 @@ dependencies:
80
64
  requirements:
81
65
  - - ">="
82
66
  - !ruby/object:Gem::Version
83
- segments:
84
- - 0
85
67
  version: "0"
86
68
  type: :development
87
69
  prerelease: false
@@ -133,7 +115,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
133
115
  requirements:
134
116
  - - ">="
135
117
  - !ruby/object:Gem::Version
136
- hash: 3123587155221195723
118
+ hash: -1150026264485618009
137
119
  segments:
138
120
  - 0
139
121
  version: "0"
@@ -142,13 +124,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
142
124
  requirements:
143
125
  - - ">="
144
126
  - !ruby/object:Gem::Version
145
- segments:
146
- - 0
147
127
  version: "0"
148
128
  requirements: []
149
129
 
150
130
  rubyforge_project:
151
- rubygems_version: 1.3.7
131
+ rubygems_version: 1.5.0
152
132
  signing_key:
153
133
  specification_version: 3
154
134
  summary: reusable menu for navigation and modification or hierarchical categories