the_sortable_tree 2.0.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # TheSortableTree v2.0.0
1
+ # TheSortableTree v2.1.0
2
2
 
3
3
  Nested Set + Drag&Drop GUI. Very fast! Best render helper! **2000 nodes/sec**. Ready for rails 4 ([RubyGems](http://rubygems.org/gems/the_sortable_tree))
4
4
 
@@ -10,24 +10,21 @@ Nested Set + Drag&Drop GUI. Very fast! Best render helper! **2000 nodes/sec**. R
10
10
 
11
11
  ![Render tree](https://raw.github.com/the-teacher/the_sortable_tree/master/docs/tree.jpg)
12
12
 
13
+ ## Render Nested Options
14
+
15
+ ![Render tree](https://raw.github.com/the-teacher/the_sortable_tree/master/docs/nested_options.jpg)
16
+
13
17
  ## Keywords
14
18
 
15
19
  Awesome nested set, Nested set, Ruby, Rails, Nested set view helper, Sortable nested set, Drag&Drop GUI for nested set, View helper for nested set, render tree
16
20
 
17
21
  ## Install
18
22
 
19
- **Gemfile** (Rails 4)
23
+ **Gemfile** (Rails 3, Rails 4)
20
24
 
21
25
  ```ruby
22
26
  gem 'awesome_nested_set' # or any similar gem (gem 'nested_set')
23
- gem 'the_sortable_tree'
24
- ```
25
-
26
- **Gemfile** (Rails 3)
27
-
28
- ```ruby
29
- gem 'awesome_nested_set'
30
- gem 'the_sortable_tree', :branch => "rails_3"
27
+ gem "the_sortable_tree", "~> 2.1.0"
31
28
  ```
32
29
 
33
30
  Console
@@ -64,6 +61,7 @@ Add next JS only for Sortable GUI
64
61
  ```ruby
65
62
  *= require tree
66
63
  *= require sortable_tree
64
+ *= require nested_options
67
65
  ```
68
66
 
69
67
  ### Extend your Routes for Sortable GUI
@@ -122,6 +120,14 @@ end
122
120
  = build_server_tree @pages, type: :sortable
123
121
  ```
124
122
 
123
+ ## Render Nested Options Tree
124
+
125
+ **app/views/pages/manage.html.haml**
126
+
127
+ ```haml
128
+ = select_tag :pages, nested_options(@pages, :selected => Page.last), class: :nested_options
129
+ ```
130
+
125
131
  ## build_server_tree options
126
132
 
127
133
  **Client side:**
@@ -213,6 +219,11 @@ Try to create view helpers for:
213
219
  4. Comments Tree gem
214
220
  3. gem Ancestry (???)
215
221
 
222
+ ## Аcknowledgment
223
+
224
+ 1. [mjsarfatti/nestedSortable](https://github.com/mjsarfatti/nestedSortable)
225
+ 2. [iconza](http://iconza.com)
226
+
216
227
  ## The MIT License (MIT)
217
228
 
218
229
  Copyright 2009-2013 Ilya N. Zykin (the-teacher), Mikhail Dieterle (Mik-die), Matthew Clark
@@ -0,0 +1,25 @@
1
+ .nested_options{
2
+ padding: 3px;
3
+ font-size: 18px;
4
+ font-family: Arial;
5
+ border: 1px solid gray;
6
+
7
+ option{
8
+ color: black; padding: 3px;
9
+ &.selected{ font-weight: bold; color: red; }
10
+ }
11
+
12
+ @for $i from 1 through 2{
13
+ .l_#{$i}{
14
+ padding-left: #{($i - 1)*15}px;
15
+ font-size: #{(100 - $i * 10) + '%'};
16
+ }
17
+ }
18
+
19
+ @for $i from 3 through 10{
20
+ .l_#{$i}{
21
+ padding-left: #{($i - 1)*15}px;
22
+ font-size: 70%;
23
+ }
24
+ }
25
+ }
@@ -0,0 +1,20 @@
1
+ module RenderSelectOptionsHelper
2
+ class Render
3
+ class << self
4
+ attr_accessor :h, :options
5
+
6
+ def render_node(h, options)
7
+ @h, @options = h, options
8
+
9
+ node = options[:node]
10
+ selected = (options[:selected] == node) ? ' selected' : nil
11
+
12
+ "
13
+ <option value='#{node[:id]}' class='l_#{ options[:level] }#{selected}'>#{ node[:title] }</option>
14
+ #{ options[:children] }
15
+ "
16
+ end
17
+
18
+ end
19
+ end
20
+ end
@@ -46,7 +46,7 @@ module RenderSortableTreeHelper
46
46
  "
47
47
  <div class='controls'>
48
48
  #{ h.link_to '', edit_path, :class => :edit }
49
- #{ h.link_to '', show_path, :class => :delete, :data => { :confirm => 'Are you sure?' } }
49
+ #{ h.link_to '', show_path, :class => :delete, :method => :delete, :data => { :confirm => 'Are you sure?' } }
50
50
  </div>
51
51
  "
52
52
  end
@@ -8,7 +8,8 @@ module TheSortableTreeHelper
8
8
  # Default renderers
9
9
  TREE_RENDERERS = {
10
10
  :tree => RenderTreeHelper,
11
- :sortable => RenderSortableTreeHelper
11
+ :sortable => RenderSortableTreeHelper,
12
+ :select_options => RenderSelectOptionsHelper
12
13
  }
13
14
 
14
15
  ###############################################
@@ -27,6 +28,16 @@ module TheSortableTreeHelper
27
28
  render_module::Render::render_node(self, options)
28
29
  end
29
30
 
31
+ ###############################################
32
+ # Nested Options Helper
33
+ ###############################################
34
+
35
+ def nested_options tree, options = {}
36
+ opts = { :type => :select_options }
37
+ opts.merge!(options)
38
+ build_server_tree(tree, opts)
39
+ end
40
+
30
41
  ###############################################
31
42
  # Server Side Render Tree Helper
32
43
  ###############################################
@@ -6,8 +6,15 @@ module TheSortableTree
6
6
  module Scopes
7
7
  def self.included(base)
8
8
  base.class_eval do
9
- scope :nested_set, -> { order('lft ASC') }
10
- scope :reversed_nested_set, -> { order('lft DESC') }
9
+ if Rails::VERSION::MAJOR == 3
10
+ scope :nested_set, order('lft ASC')
11
+ scope :reversed_nested_set, order('lft DESC')
12
+ elsif Rails::VERSION::MAJOR == 4
13
+ scope :nested_set, lambda { order('lft ASC') }
14
+ scope :reversed_nested_set, lambda { order('lft DESC') }
15
+ else
16
+ puts "[TheSortableTree] ERROR: required Rails 3 or Rails 4"
17
+ end
11
18
  end
12
19
  end
13
20
  end
@@ -1,3 +1,3 @@
1
1
  module TheSortableTree
2
- VERSION = "2.0.0"
2
+ VERSION = "2.1.0"
3
3
  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: 2.0.0
4
+ version: 2.1.0
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: 2013-01-19 00:00:00.000000000 Z
12
+ date: 2013-01-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &84664520 !ruby/object:Gem::Requirement
16
+ requirement: &81000690 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '3.1'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *84664520
24
+ version_requirements: *81000690
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: sqlite3
27
- requirement: &84664130 !ruby/object:Gem::Requirement
27
+ requirement: &81000310 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *84664130
35
+ version_requirements: *81000310
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &84663700 !ruby/object:Gem::Requirement
38
+ requirement: &80999910 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *84663700
46
+ version_requirements: *80999910
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec-rails
49
- requirement: &84663410 !ruby/object:Gem::Requirement
49
+ requirement: &80999620 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *84663410
57
+ version_requirements: *80999620
58
58
  description: Drag&Drop GUI for awesom_nested_set. Render Tree Helper. Very fast! Ready
59
59
  for Rails 4
60
60
  email:
@@ -73,6 +73,7 @@ files:
73
73
  - app/assets/images/iconza/icons/move.png
74
74
  - app/assets/images/iconza/icons/delete.png
75
75
  - app/assets/images/iconza/icons/add.png
76
+ - app/assets/stylesheets/nested_options.css.scss
76
77
  - app/assets/stylesheets/tree.css.scss
77
78
  - app/assets/stylesheets/sortable_tree.css.scss
78
79
  - app/assets/javascripts/jquery.ui.nestedSortable.js
@@ -80,6 +81,7 @@ files:
80
81
  - app/assets/javascripts/sortable_tree/initializer.js.coffee
81
82
  - app/views/sortable/client/_tree.html.erb
82
83
  - app/views/tree/client/_tree.html.erb
84
+ - app/helpers/render_select_options_helper.rb
83
85
  - app/helpers/render_tree_helper.rb
84
86
  - app/helpers/the_sortable_tree_helper.rb
85
87
  - app/helpers/render_sortable_tree_helper.rb