the_sortable_tree 1.0.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,8 +1,10 @@
1
1
  ### TheSortableTree
2
2
 
3
- GUI for nested_set gem. Rails 3+
3
+ Engine Based GUI for nested_set gem. Rails 3+
4
4
 
5
- **Engine Based**
5
+ **sortable_tree** - recursive helper-method for render sortable nested_set tree.
6
+
7
+ **sortable_tree** use partials for rendering, that's why it is **so easy to customize**!
6
8
 
7
9
  ### Install
8
10
 
@@ -12,28 +14,44 @@ bundle
12
14
 
13
15
  ### Require
14
16
 
15
- 1. gem 'nested_set'
17
+ 1. gem 'nested_set' or gem 'awesome_nested_set'
16
18
  2. gem 'haml'
17
19
  3. JQuery UI
18
20
 
19
- ### Extend you Model
21
+ ### Example of using with Page Model
22
+
23
+ ### Extend your Model
24
+
25
+ ``` ruby
26
+ class Page < ActiveRecord::Base
27
+ # SCOPES FOR SORTABLE NESTED SET
28
+ include TheSortableTree::Scopes
29
+ # any code here
30
+ end
31
+ ```
32
+
33
+ ### Extend your Controller
20
34
 
21
35
  ``` ruby
22
- # SCOPES FOR SORTABLE NESTED SET
23
- scope :nested_set, order('lft ASC')
24
- scope :reversed_nested_set, order('lft DESC')
36
+ class PagesController < ApplicationController
37
+ include TheSortableTreeController::Rebuild
38
+ # any code here
39
+ end
25
40
  ```
26
41
 
27
- ### Extend you Controller
42
+ or (for reversed tree)
28
43
 
29
44
  ``` ruby
30
- include TheSortableTreeController::Rebuild
45
+ class PagesController < ApplicationController
46
+ include TheSortableTreeController::ReversedRebuild
47
+ # any code here
48
+ end
31
49
  ```
32
50
 
33
- ### Extend you Routes
51
+ ### Extend your Routes
34
52
 
35
53
  ``` ruby
36
- resources :elements do
54
+ resources :pages do
37
55
  collection do
38
56
  get :manage
39
57
  post :rebuild
@@ -41,15 +59,40 @@ resources :elements do
41
59
  end
42
60
  ```
43
61
 
44
- ### Find you tree
62
+ **manage** action or any else action for show sortable tree
63
+
64
+ **rebuild** action is _required_ action for correctly work of **the_sortable_tree**
65
+
66
+ ### Find your tree
45
67
 
46
68
  ``` ruby
47
- def manage
48
- @elements = Element.all.nested_set
69
+ class PagesController < ApplicationController
70
+ include TheSortableTreeController::Rebuild
71
+
72
+ def manage
73
+ @pages = Page.nested_set.all
74
+ end
75
+
76
+ # any code here
49
77
  end
78
+
50
79
  ```
51
80
 
52
- ### Render you tree with TheSortableTree
81
+ or
82
+
83
+ ``` ruby
84
+ class PagesController < ApplicationController
85
+ include TheSortableTreeController::ReversedRebuild
86
+
87
+ def manage
88
+ @pages = Page.reversed_nested_set.all
89
+ end
90
+
91
+ # any code here
92
+ end
93
+ ```
94
+
95
+ ### Render your tree with TheSortableTree (Haml markup)
53
96
 
54
97
  ``` ruby
55
98
  - content_for :css do
@@ -57,11 +100,51 @@ end
57
100
  - content_for :js do
58
101
  = javascript_include_tag 'jquery.ui.nestedSortable'
59
102
 
60
- = sortable_tree @elements, :klass => :element, :rebuild_url => rebuild_elements_path
103
+ = sortable_tree @pages, :klass => :page, :rebuild_url => rebuild_pages_path
61
104
  ```
62
105
 
63
106
  ### Customize
64
107
 
65
108
  ``` ruby
66
- rails g the_sortable_tree:views elements
109
+ rails g the_sortable_tree:views pages
110
+ ```
111
+
112
+ It's will generate view partials for **sortable_tree** helper
113
+
114
+ ``` ruby
115
+ create app/views/pages/the_sortable_tree
116
+ create app/views/pages/the_sortable_tree/_controls.html.haml
117
+ create app/views/pages/the_sortable_tree/_item.html.haml
118
+ create app/views/pages/the_sortable_tree/_js_init_sortable_tree.html.haml
119
+ create app/views/pages/the_sortable_tree/_js_on_update_tree.html.haml
120
+ create app/views/pages/the_sortable_tree/_js_rebuild_ajax.html.haml
121
+ create app/views/pages/the_sortable_tree/_link.html.haml
122
+ create app/views/pages/the_sortable_tree/_nested_set.html.haml
123
+ create app/views/pages/the_sortable_tree/_new.html.haml
124
+ create app/views/pages/the_sortable_tree/_tree.html.haml
67
125
  ```
126
+
127
+ **_tree** - root container for nested set elements
128
+
129
+ **_item** - element of tree (link to current element and childs)
130
+
131
+ **_link** - decoration of link to current element of tree
132
+
133
+ **_nested_set** - decoration of childs
134
+
135
+ **_new** - create new element link
136
+
137
+ **_controls** - control elements for current tree element
138
+
139
+
140
+ **_js_init_sortable_tree** - JS for sortable tree
141
+
142
+ **_js_on_update_tree**- JS for sortable tree
143
+
144
+ **_js_rebuild_ajax**- JS for sortable tree
145
+
146
+ Customize and use it!
147
+
148
+ ``` ruby
149
+ = sortable_tree @pages, :klass => :page, :rebuild_url => rebuild_pages_path, :path => 'pages/the_sortable_tree'
150
+ ```
@@ -93,7 +93,7 @@ module TheSortableTreeHelper
93
93
  # build views
94
94
  childs_res= childs_res.blank? ? '' : render(:partial => "#{opts[:path]}/nested_set", :locals => {:opts => opts, :parent => node, :childs => childs_res})
95
95
  link= render(:partial => "#{opts[:path]}/link", :locals => {:opts => opts, :node => node, :root => root, :controls => controls})
96
- res= render(:partial => "#{opts[:path]}/nested_set_item", :locals => {:opts => opts, :node => node, :link => link, :childs => childs_res})
96
+ res= render(:partial => "#{opts[:path]}/item", :locals => {:opts => opts, :node => node, :link => link, :childs => childs_res})
97
97
 
98
98
  # delete current node from tree if you want
99
99
  # recursively moving by tree is 25%+ faster on 500 elems
@@ -1,3 +1,3 @@
1
1
  module TheSortableTree
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.1"
3
3
  end
@@ -3,5 +3,13 @@ require "the_sortable_tree/engine"
3
3
  require "the_sortable_tree/version"
4
4
 
5
5
  module TheSortableTree
6
- # TheSortableTree
6
+ # include TheSortableTree::Scopes
7
+ module Scopes
8
+ def self.included(base)
9
+ base.class_eval do
10
+ scope :nested_set, order('lft ASC')
11
+ scope :reversed_nested_set, order('lft DESC')
12
+ end
13
+ end
14
+ end
7
15
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: the_sortable_tree
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-02 00:00:00.000000000Z
12
+ date: 2012-01-06 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: haml
16
- requirement: &84037710 !ruby/object:Gem::Requirement
16
+ requirement: &74340490 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '3.0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *84037710
24
+ version_requirements: *74340490
25
25
  description: Drug&Drop GUI for nested_set gem. Sortable tree view helper
26
26
  email:
27
27
  - zykin-ilya@ya.ru
@@ -61,12 +61,12 @@ files:
61
61
  - app/controllers/the_sortable_tree_controller.rb
62
62
  - app/helpers/the_sortable_tree_helper.rb
63
63
  - app/views/the_sortable_tree/_controls.html.haml
64
+ - app/views/the_sortable_tree/_item.html.haml
64
65
  - app/views/the_sortable_tree/_js_init_sortable_tree.html.haml
65
66
  - app/views/the_sortable_tree/_js_on_update_tree.html.haml
66
67
  - app/views/the_sortable_tree/_js_rebuild_ajax.html.haml
67
68
  - app/views/the_sortable_tree/_link.html.haml
68
69
  - app/views/the_sortable_tree/_nested_set.html.haml
69
- - app/views/the_sortable_tree/_nested_set_item.html.haml
70
70
  - app/views/the_sortable_tree/_new.html.haml
71
71
  - app/views/the_sortable_tree/_tree.html.haml
72
72
  - lib/generators/the_sortable_tree/views_generator.rb