activeadmin-menu_tree 0.1.2 → 0.1.3
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/.github/workflows/main.yml +16 -15
- data/Gemfile +1 -1
- data/README.md +28 -11
- data/lib/activeadmin/menu_tree/config.rb +6 -9
- data/lib/activeadmin/menu_tree/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c09eb5f2943471291e5f48ea280f82c0b3007057a6717db372447a6b8dc9ab01
|
4
|
+
data.tar.gz: a169f0d879cb014bab3974e45a86ad8e23ac129e8752a1a22b968f6a3b0a048e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 28860c7fbd65dc2530a41a037145d59dbaf6c9cec497a40b696dad4349dac833d0dfc24803ecb1e0832c3273b33d1ca18c2c98ba1c2be6f178c1f53189dc75a2
|
7
|
+
data.tar.gz: 63e48fef67ff9bd247c6e44e479cb32dff83038f9221953c91f764b94d6cd0a3d446b7e45ba42b419068c3683b531f9bea19a11964ced1b3e4c0849e6f4e6e05
|
data/.github/workflows/main.yml
CHANGED
@@ -18,27 +18,27 @@ jobs:
|
|
18
18
|
- name: Set up Ruby
|
19
19
|
uses: ruby/setup-ruby@v1
|
20
20
|
with:
|
21
|
-
ruby-version: 3.
|
21
|
+
ruby-version: 3.1
|
22
22
|
- name: Install bundler
|
23
23
|
run: gem install bundler
|
24
24
|
- name: Setup
|
25
25
|
run: bin/setup
|
26
26
|
- name: Rubocop
|
27
27
|
run: bundle exec rake rubocop
|
28
|
-
steep:
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
28
|
+
# steep:
|
29
|
+
# runs-on: ubuntu-latest
|
30
|
+
# steps:
|
31
|
+
# - uses: actions/checkout@v2
|
32
|
+
# - name: Set up Ruby
|
33
|
+
# uses: ruby/setup-ruby@v1
|
34
|
+
# with:
|
35
|
+
# ruby-version: 3.1
|
36
|
+
# - name: Install bundler
|
37
|
+
# run: gem install bundler
|
38
|
+
# - name: Setup
|
39
|
+
# run: bin/setup
|
40
|
+
# - name: Steep
|
41
|
+
# run: bundle exec steep check
|
42
42
|
rspec:
|
43
43
|
runs-on: ubuntu-latest
|
44
44
|
strategy:
|
@@ -46,6 +46,7 @@ jobs:
|
|
46
46
|
ruby:
|
47
47
|
- 2.7
|
48
48
|
- 3.0
|
49
|
+
- 3.1
|
49
50
|
steps:
|
50
51
|
- uses: actions/checkout@v2
|
51
52
|
- name: Set up Ruby
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -86,19 +86,22 @@ end
|
|
86
86
|
|
87
87
|
### Other ways to load configuration
|
88
88
|
|
89
|
-
It is also possible to simply use hash instead of yaml.
|
89
|
+
It is also possible to simply use hash instead of yaml.
|
90
|
+
If you want to use dynamic specification using `proc` in menu_tree (instead of in ActiveAdmin Resource), you may want to use this one.
|
91
|
+
|
90
92
|
```ruby
|
91
93
|
ActiveAdmin::MenuTree.setup do |config|
|
92
|
-
config.menu_tree = [
|
93
|
-
name: "Dashboard"
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
94
|
+
config.menu_tree = [
|
95
|
+
{ name: "Dashboard", label: proc { I18n.t("active_admin.dashboard") } },
|
96
|
+
{
|
97
|
+
label: "Foo",
|
98
|
+
if: proc { "Something dynamic" },
|
99
|
+
children: [
|
100
|
+
{ name: "Bar" },
|
101
|
+
{ name: "Baz" }
|
102
|
+
]
|
103
|
+
}
|
104
|
+
]
|
102
105
|
end
|
103
106
|
```
|
104
107
|
|
@@ -118,6 +121,7 @@ activeadmin:
|
|
118
121
|
Or you can use other configuration gems like [global gem](https://github.com/railsware/global) by converting them to hash as well.
|
119
122
|
|
120
123
|
### Full configuration example
|
124
|
+
|
121
125
|
```yaml
|
122
126
|
activeadmin:
|
123
127
|
menu_tree:
|
@@ -146,6 +150,19 @@ activeadmin:
|
|
146
150
|
url: 'https://example.com'
|
147
151
|
html_options:
|
148
152
|
target: blank
|
153
|
+
# Nesting of children is also available.
|
154
|
+
- label: Lorem
|
155
|
+
children:
|
156
|
+
- label: ipsum
|
157
|
+
children:
|
158
|
+
- label: dolor
|
159
|
+
children:
|
160
|
+
- label: sit
|
161
|
+
children:
|
162
|
+
- label: amet
|
163
|
+
url: 'https://wikipedia.org/wiki/Lorem_ipsum'
|
164
|
+
html_options:
|
165
|
+
target: blank
|
149
166
|
```
|
150
167
|
|
151
168
|
## Development
|
@@ -14,7 +14,7 @@ module ActiveAdmin::MenuTree
|
|
14
14
|
raise ActiveAdmin::MenuTree::Error, "Invalid config" unless new_value.is_a? Array
|
15
15
|
|
16
16
|
@menu_tree = new_value.map(&:deep_symbolize_keys)
|
17
|
-
@menu_options =
|
17
|
+
@menu_options = flatten_options(@menu_tree)
|
18
18
|
end
|
19
19
|
|
20
20
|
def find_menu_option(name:)
|
@@ -23,16 +23,13 @@ module ActiveAdmin::MenuTree
|
|
23
23
|
|
24
24
|
private
|
25
25
|
|
26
|
-
def
|
27
|
-
|
28
|
-
options = format_options(item, index: index)
|
26
|
+
def flatten_options(items, parent: nil)
|
27
|
+
items.map.with_index(1) do |item, index|
|
28
|
+
options = format_options(item, index: index, parent: parent)
|
29
29
|
next options unless item[:children].is_a? Array
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
format_options(child, index: child_index, parent: item[:label])
|
34
|
-
end
|
35
|
-
|
31
|
+
next_parent = parent ? [parent, item[:label]].flatten.compact : item[:label]
|
32
|
+
children = flatten_options(item[:children], parent: next_parent)
|
36
33
|
[options] + children
|
37
34
|
end.flatten.compact
|
38
35
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activeadmin-menu_tree
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- shuuuuuny
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-02-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activeadmin
|
@@ -93,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
93
93
|
- !ruby/object:Gem::Version
|
94
94
|
version: '0'
|
95
95
|
requirements: []
|
96
|
-
rubygems_version: 3.
|
96
|
+
rubygems_version: 3.3.3
|
97
97
|
signing_key:
|
98
98
|
specification_version: 4
|
99
99
|
summary: Allows ActiveAdmin menus to be managed in tree format.
|