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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b04ec690f0cea481508a2359ede3943c33c5353e32fd1ae07d0da5e43fc66a8a
4
- data.tar.gz: b8d28caed2ce7f24facabfd707b96e710d84a20a0ec96d89350f605e73763406
3
+ metadata.gz: c09eb5f2943471291e5f48ea280f82c0b3007057a6717db372447a6b8dc9ab01
4
+ data.tar.gz: a169f0d879cb014bab3974e45a86ad8e23ac129e8752a1a22b968f6a3b0a048e
5
5
  SHA512:
6
- metadata.gz: ff9dd6bf9962dda1a7b96c3c42dbf7b369f3d74d13ee8ff660129f74e9d77ea66c43bd928a28eeb8b9ca802e240eaf1a612f903155f031f8f027e93de02ebf7d
7
- data.tar.gz: 697f1a4fd51a1832c2cfce26d363ee3f328cc953580a93229b4e3226145a0fbc4767dca6e02f025b4b23fbf1139bf5b0da29edce9b213ed4aada24f6e8a9ebb8
6
+ metadata.gz: 28860c7fbd65dc2530a41a037145d59dbaf6c9cec497a40b696dad4349dac833d0dfc24803ecb1e0832c3273b33d1ca18c2c98ba1c2be6f178c1f53189dc75a2
7
+ data.tar.gz: 63e48fef67ff9bd247c6e44e479cb32dff83038f9221953c91f764b94d6cd0a3d446b7e45ba42b419068c3683b531f9bea19a11964ced1b3e4c0849e6f4e6e05
@@ -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.0.0
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
- 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.0.0
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
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
@@ -12,4 +12,4 @@ gem "rubocop", "~> 1.0", require: false
12
12
  gem "rubocop-rake", require: false
13
13
  gem "rubocop-rspec", require: false
14
14
  gem "rubocop-rubycw", require: false
15
- gem "steep"
15
+ gem "steep", ">= 0.47.0"
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
- label: "Foo",
96
- children: [{
97
- name: "Bar"
98
- }, {
99
- name: "Baz"
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 = flatten_menu_tree
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 flatten_menu_tree
27
- menu_tree.map.with_index(1) do |item, index|
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
- children =
32
- item[:children].map.with_index(1) do |child, child_index|
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ActiveAdmin
4
4
  module MenuTree
5
- VERSION = "0.1.2"
5
+ VERSION = "0.1.3"
6
6
  end
7
7
  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.2
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: 2021-11-21 00:00:00.000000000 Z
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.2.31
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.