nested_array 2.0.1 → 2.0.2
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.
- checksums.yaml +4 -4
- data/README-ru.md +60 -0
- data/dev/nested_options.rb +25 -0
- data/lib/nested_array/nested.rb +1 -1
- data/lib/nested_array/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6b941615c01b8bccb24d20065348d46a16a2fab4d6e70c08b6f5fe419f58eb46
|
4
|
+
data.tar.gz: 0ae07ed74b53e8b16d448709b23edcc9b91127b503be8402f22e30ed562cd2f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 59f1dbb039e65b4efa7aff1fba606e52ee144b9e98c2e8535f11ad436bb867a21fb2ccdfb8190c99fb308a844eae329558e469252b929876f261b581157957c7
|
7
|
+
data.tar.gz: bd79252a6d9f1814f2828f25c6eeb6a9788f1c409d5d0f7f11c7b24a3552d87aa6ba55826cd9d8d0a5c331b38423a172c450640b9de4775687727670953c119b
|
data/README-ru.md
CHANGED
@@ -41,6 +41,66 @@ gem 'nested_array', '~> 2.0.0'
|
|
41
41
|
</ul>
|
42
42
|
```
|
43
43
|
|
44
|
+
__Опции `to_nested`__
|
45
|
+
|
46
|
+
`Catalogs.all.to_a.to_nested(options)`
|
47
|
+
|
48
|
+
Для указания базовых имён полей ноды (чувствительны к string/symbol):
|
49
|
+
|
50
|
+
```
|
51
|
+
id: 'id',
|
52
|
+
parent_id: 'parent_id',
|
53
|
+
children: 'children',
|
54
|
+
level: 'level',
|
55
|
+
```
|
56
|
+
|
57
|
+
Дополнительные параметры преобразования:
|
58
|
+
|
59
|
+
```
|
60
|
+
hashed: false,
|
61
|
+
add_level: false,
|
62
|
+
root_id: nil,
|
63
|
+
```
|
64
|
+
|
65
|
+
__Опции `nested_to_html`__
|
66
|
+
|
67
|
+
```
|
68
|
+
tabulated: true,
|
69
|
+
inline: false,
|
70
|
+
tab: "\t",
|
71
|
+
ul: '<ul>',
|
72
|
+
_ul: '</ul>',
|
73
|
+
li: '<li>',
|
74
|
+
_li: '</li>',
|
75
|
+
```
|
76
|
+
|
77
|
+
### "Скеивание" вложенных структур `concat_nested`
|
78
|
+
|
79
|
+
Ноды склеиваются если путь к ним одинаков;
|
80
|
+
Путь определяется из сложения Текстов (конфигурируемо через :path_key);
|
81
|
+
|
82
|
+
__Опции `nested_to_html`__
|
83
|
+
|
84
|
+
```
|
85
|
+
path_separator: '-=path_separator=-',
|
86
|
+
path_key: 'text',
|
87
|
+
```
|
88
|
+
|
89
|
+
### Формирования опций для html-тега <select> `nested_to_options`
|
90
|
+
|
91
|
+
Возвращает массив с псевдографикой, позволяющей вывести древовидную структуру.
|
92
|
+
|
93
|
+
```
|
94
|
+
[['option_text1', 'option_value1'],['option_text2', 'option_value2'],…]
|
95
|
+
```
|
96
|
+
|
97
|
+
__Опции `nested_to_options`__
|
98
|
+
|
99
|
+
```
|
100
|
+
option_value: 'id', # Что брать в качестве значений при формировании опций селекта.
|
101
|
+
option_text: 'name',
|
102
|
+
```
|
103
|
+
|
44
104
|
## Development
|
45
105
|
|
46
106
|
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require_relative '../lib/nested_array.rb'
|
2
|
+
require 'awesome_print'
|
3
|
+
|
4
|
+
a = [
|
5
|
+
{'id' => 1, 'parent_id' => nil, 'name' => 'category 1'},
|
6
|
+
{'id' => 2, 'parent_id' => nil, 'name' => 'category 2'},
|
7
|
+
{'id' => 3, 'parent_id' => 2, 'name' => 'category 3'},
|
8
|
+
{'id' => 4, 'parent_id' => nil, 'name' => 'category 4'},
|
9
|
+
{'id' => 5, 'parent_id' => 4, 'name' => 'category 5'},
|
10
|
+
{'id' => 6, 'parent_id' => 5, 'name' => 'category 6'},
|
11
|
+
{'id' => 7, 'parent_id' => nil, 'name' => 'category 7'},
|
12
|
+
{'id' => 8, 'parent_id' => 7, 'name' => 'category 8'},
|
13
|
+
{'id' => 9, 'parent_id' => 7, 'name' => 'category 9'},
|
14
|
+
{'id' => 10, 'parent_id' => 9, 'name' => 'category 10'},
|
15
|
+
{'id' => 11, 'parent_id' => 9, 'name' => 'category 11'}
|
16
|
+
]
|
17
|
+
|
18
|
+
b = a.shuffle
|
19
|
+
|
20
|
+
array = b.to_nested.nested_to_options
|
21
|
+
print 'array: '.red; p array
|
22
|
+
|
23
|
+
array.each do |v|
|
24
|
+
puts v[0]
|
25
|
+
end
|
data/lib/nested_array/nested.rb
CHANGED
@@ -295,7 +295,7 @@ module NestedArray::Nested
|
|
295
295
|
each_nested do |node, parents, level, is_last|
|
296
296
|
last[level+1] = is_last
|
297
297
|
node_text = node[options[:option_text]]
|
298
|
-
node_level = (1..level).map{|l| last[l] == true ? '
|
298
|
+
node_level = (1..level).map{|l| last[l] == true ? ' ' : '┃'}.join
|
299
299
|
node_last = is_last ? '┗' : '┣'
|
300
300
|
node_children = node[options[:children]].present? && node[options[:children]].length > 0 ? '┳' : '━'
|
301
301
|
option_text = "#{node_level}#{node_last}#{node_children}╸#{node_text}"
|
data/lib/nested_array/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nested_array
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- zlatov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-01-
|
11
|
+
date: 2020-01-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -108,6 +108,7 @@ files:
|
|
108
108
|
- bin/rake
|
109
109
|
- bin/rspec
|
110
110
|
- bin/setup
|
111
|
+
- dev/nested_options.rb
|
111
112
|
- lib/.byebug_history
|
112
113
|
- lib/nested_array.rb
|
113
114
|
- lib/nested_array/nested.rb
|