activeadmin-menu_tree 0.0.1 → 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 +51 -37
- data/.rubocop.yml +18 -0
- data/Gemfile +5 -2
- data/Makefile +1 -1
- data/README.md +30 -12
- data/activeadmin-menu_tree.gemspec +1 -0
- data/lib/activeadmin/menu_tree/config.rb +9 -10
- data/lib/activeadmin/menu_tree/dsl.rb +1 -0
- data/lib/activeadmin/menu_tree/version.rb +1 -1
- data/lib/activeadmin/menu_tree.rb +1 -0
- data/rbs_collection.lock.yaml +19 -11
- data/sig/lib/activeadmin/menu_tree/config.rbs +10 -6
- data/sig/lib/activeadmin/menu_tree.rbs +2 -2
- data/sig/lib/activeadmin.rbs +6 -1
- data/sig/lib/activesupport.rbs +4 -0
- metadata +5 -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
@@ -1,47 +1,61 @@
|
|
1
1
|
name: Ruby
|
2
2
|
|
3
|
-
on:
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches:
|
6
|
+
- main
|
7
|
+
pull_request:
|
8
|
+
types:
|
9
|
+
- opened
|
10
|
+
- synchronize
|
11
|
+
- reopened
|
4
12
|
|
5
13
|
jobs:
|
6
14
|
rubocop:
|
7
15
|
runs-on: ubuntu-latest
|
8
16
|
steps:
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
- uses: actions/checkout@v2
|
18
|
+
- name: Set up Ruby
|
19
|
+
uses: ruby/setup-ruby@v1
|
20
|
+
with:
|
21
|
+
ruby-version: 3.1
|
22
|
+
- name: Install bundler
|
23
|
+
run: gem install bundler
|
24
|
+
- name: Setup
|
25
|
+
run: bin/setup
|
26
|
+
- name: Rubocop
|
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.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
|
20
42
|
rspec:
|
21
43
|
runs-on: ubuntu-latest
|
44
|
+
strategy:
|
45
|
+
matrix:
|
46
|
+
ruby:
|
47
|
+
- 2.7
|
48
|
+
- 3.0
|
49
|
+
- 3.1
|
22
50
|
steps:
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
steep:
|
35
|
-
runs-on: ubuntu-latest
|
36
|
-
steps:
|
37
|
-
- uses: actions/checkout@v2
|
38
|
-
- name: Set up Ruby
|
39
|
-
uses: ruby/setup-ruby@v1
|
40
|
-
with:
|
41
|
-
ruby-version: 3.0.0
|
42
|
-
- name: Install bundler
|
43
|
-
run: gem install bundler
|
44
|
-
- name: Setup
|
45
|
-
run: bin/setup
|
46
|
-
- name: Steep
|
47
|
-
run: bundle exec steep check
|
51
|
+
- uses: actions/checkout@v2
|
52
|
+
- name: Set up Ruby
|
53
|
+
uses: ruby/setup-ruby@v1
|
54
|
+
with:
|
55
|
+
ruby-version: ${{ matrix.ruby }}
|
56
|
+
- name: Install bundler
|
57
|
+
run: gem install bundler
|
58
|
+
- name: Setup
|
59
|
+
run: bin/setup
|
60
|
+
- name: RSpec
|
61
|
+
run: bundle exec rake spec
|
data/.rubocop.yml
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
require:
|
2
|
+
- rubocop-rake
|
3
|
+
- rubocop-rspec
|
4
|
+
- rubocop-rubycw
|
5
|
+
|
1
6
|
AllCops:
|
2
7
|
TargetRubyVersion: 2.7
|
3
8
|
NewCops: enable
|
@@ -6,6 +11,7 @@ AllCops:
|
|
6
11
|
ExtraDetails: true
|
7
12
|
Exclude:
|
8
13
|
- 'spec/dummy/**/*'
|
14
|
+
- 'vendor/bundle/**/*'
|
9
15
|
|
10
16
|
Style/ClassAndModuleChildren:
|
11
17
|
Enabled: false
|
@@ -26,6 +32,8 @@ Style/TrailingCommaInHashLiteral:
|
|
26
32
|
|
27
33
|
Layout/LineLength:
|
28
34
|
Max: 120
|
35
|
+
Exclude:
|
36
|
+
- '*.gemspec'
|
29
37
|
|
30
38
|
Layout/SpaceBeforeBlockBraces:
|
31
39
|
Enabled: false
|
@@ -36,3 +44,13 @@ Metrics/BlockLength:
|
|
36
44
|
|
37
45
|
Metrics/MethodLength:
|
38
46
|
Max: 15
|
47
|
+
|
48
|
+
RSpec:
|
49
|
+
# DisabledByDefault
|
50
|
+
Enabled: false
|
51
|
+
|
52
|
+
RSpec/ContextWording:
|
53
|
+
Enabled: true
|
54
|
+
|
55
|
+
RSpec/VerifiedDoubles:
|
56
|
+
Enabled: true
|
data/Gemfile
CHANGED
@@ -8,5 +8,8 @@ gemspec
|
|
8
8
|
gem "rake", "~> 13.0"
|
9
9
|
gem "rbs"
|
10
10
|
gem "rspec", "~> 3.0"
|
11
|
-
gem "rubocop", "~> 0
|
12
|
-
gem "
|
11
|
+
gem "rubocop", "~> 1.0", require: false
|
12
|
+
gem "rubocop-rake", require: false
|
13
|
+
gem "rubocop-rspec", require: false
|
14
|
+
gem "rubocop-rubycw", require: false
|
15
|
+
gem "steep", ">= 0.47.0"
|
data/Makefile
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# ActiveAdmin::MenuTree
|
2
2
|
|
3
|
-
|
3
|
+
[](https://badge.fury.io/rb/activeadmin-menu_tree)
|
4
|
+
[](https://github.com/shuuuuun/activeadmin-menu_tree/actions/workflows/main.yml)
|
4
5
|
|
5
6
|
Allows [ActiveAdmin](https://github.com/activeadmin/activeadmin) menus to be managed in tree format.
|
6
7
|
|
@@ -85,19 +86,22 @@ end
|
|
85
86
|
|
86
87
|
### Other ways to load configuration
|
87
88
|
|
88
|
-
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
|
+
|
89
92
|
```ruby
|
90
93
|
ActiveAdmin::MenuTree.setup do |config|
|
91
|
-
config.menu_tree = [
|
92
|
-
name: "Dashboard"
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
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
|
+
]
|
101
105
|
end
|
102
106
|
```
|
103
107
|
|
@@ -117,6 +121,7 @@ activeadmin:
|
|
117
121
|
Or you can use other configuration gems like [global gem](https://github.com/railsware/global) by converting them to hash as well.
|
118
122
|
|
119
123
|
### Full configuration example
|
124
|
+
|
120
125
|
```yaml
|
121
126
|
activeadmin:
|
122
127
|
menu_tree:
|
@@ -145,6 +150,19 @@ activeadmin:
|
|
145
150
|
url: 'https://example.com'
|
146
151
|
html_options:
|
147
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
|
148
166
|
```
|
149
167
|
|
150
168
|
## Development
|
@@ -17,6 +17,7 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.metadata["homepage_uri"] = spec.homepage
|
18
18
|
spec.metadata["source_code_uri"] = "https://github.com/shuuuuun/activeadmin-menu_tree"
|
19
19
|
# spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
20
|
+
spec.metadata["rubygems_mfa_required"] = "true"
|
20
21
|
|
21
22
|
# Specify which files should be added to the gem when it is released.
|
22
23
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module ActiveAdmin::MenuTree
|
4
|
+
# ActiveAdmin::MenuTree::Config class
|
4
5
|
class Config
|
5
6
|
attr_reader :menu_tree, :menu_options
|
6
7
|
|
@@ -13,7 +14,7 @@ module ActiveAdmin::MenuTree
|
|
13
14
|
raise ActiveAdmin::MenuTree::Error, "Invalid config" unless new_value.is_a? Array
|
14
15
|
|
15
16
|
@menu_tree = new_value.map(&:deep_symbolize_keys)
|
16
|
-
@menu_options =
|
17
|
+
@menu_options = flatten_options(@menu_tree)
|
17
18
|
end
|
18
19
|
|
19
20
|
def find_menu_option(name:)
|
@@ -22,24 +23,22 @@ module ActiveAdmin::MenuTree
|
|
22
23
|
|
23
24
|
private
|
24
25
|
|
25
|
-
def
|
26
|
-
|
27
|
-
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)
|
28
29
|
next options unless item[:children].is_a? Array
|
29
30
|
|
30
|
-
|
31
|
-
|
32
|
-
format_options(child, index: child_index, parent: item[:label])
|
33
|
-
end
|
34
|
-
|
31
|
+
next_parent = parent ? [parent, item[:label]].flatten.compact : item[:label]
|
32
|
+
children = flatten_options(item[:children], parent: next_parent)
|
35
33
|
[options] + children
|
36
34
|
end.flatten.compact
|
37
35
|
end
|
38
36
|
|
39
37
|
def format_options(item, index:, parent: nil)
|
38
|
+
# TODO: validate option
|
40
39
|
options = item.except(:children)
|
41
40
|
options[:priority] = index * 10
|
42
|
-
options[:
|
41
|
+
options[:id] ||= item[:name]
|
43
42
|
options[:parent] = parent if parent.present?
|
44
43
|
options
|
45
44
|
end
|
data/rbs_collection.lock.yaml
CHANGED
@@ -11,7 +11,7 @@ gems:
|
|
11
11
|
source:
|
12
12
|
type: git
|
13
13
|
name: ruby/gem_rbs_collection
|
14
|
-
revision:
|
14
|
+
revision: 81ace2c598ec871572beee5792e2a2781b35e762
|
15
15
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
16
16
|
repo_dir: gems
|
17
17
|
- name: actionview
|
@@ -19,7 +19,7 @@ gems:
|
|
19
19
|
source:
|
20
20
|
type: git
|
21
21
|
name: ruby/gem_rbs_collection
|
22
|
-
revision:
|
22
|
+
revision: 81ace2c598ec871572beee5792e2a2781b35e762
|
23
23
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
24
24
|
repo_dir: gems
|
25
25
|
- name: activemodel
|
@@ -27,7 +27,7 @@ gems:
|
|
27
27
|
source:
|
28
28
|
type: git
|
29
29
|
name: ruby/gem_rbs_collection
|
30
|
-
revision:
|
30
|
+
revision: 81ace2c598ec871572beee5792e2a2781b35e762
|
31
31
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
32
32
|
repo_dir: gems
|
33
33
|
- name: activerecord
|
@@ -35,7 +35,7 @@ gems:
|
|
35
35
|
source:
|
36
36
|
type: git
|
37
37
|
name: ruby/gem_rbs_collection
|
38
|
-
revision:
|
38
|
+
revision: 81ace2c598ec871572beee5792e2a2781b35e762
|
39
39
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
40
40
|
repo_dir: gems
|
41
41
|
- name: activesupport
|
@@ -43,7 +43,7 @@ gems:
|
|
43
43
|
source:
|
44
44
|
type: git
|
45
45
|
name: ruby/gem_rbs_collection
|
46
|
-
revision:
|
46
|
+
revision: 81ace2c598ec871572beee5792e2a2781b35e762
|
47
47
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
48
48
|
repo_dir: gems
|
49
49
|
- name: ast
|
@@ -51,7 +51,15 @@ gems:
|
|
51
51
|
source:
|
52
52
|
type: git
|
53
53
|
name: ruby/gem_rbs_collection
|
54
|
-
revision:
|
54
|
+
revision: 81ace2c598ec871572beee5792e2a2781b35e762
|
55
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
56
|
+
repo_dir: gems
|
57
|
+
- name: listen
|
58
|
+
version: '3.2'
|
59
|
+
source:
|
60
|
+
type: git
|
61
|
+
name: ruby/gem_rbs_collection
|
62
|
+
revision: 81ace2c598ec871572beee5792e2a2781b35e762
|
55
63
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
56
64
|
repo_dir: gems
|
57
65
|
- name: nokogiri
|
@@ -59,7 +67,7 @@ gems:
|
|
59
67
|
source:
|
60
68
|
type: git
|
61
69
|
name: ruby/gem_rbs_collection
|
62
|
-
revision:
|
70
|
+
revision: 81ace2c598ec871572beee5792e2a2781b35e762
|
63
71
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
64
72
|
repo_dir: gems
|
65
73
|
- name: parallel
|
@@ -67,7 +75,7 @@ gems:
|
|
67
75
|
source:
|
68
76
|
type: git
|
69
77
|
name: ruby/gem_rbs_collection
|
70
|
-
revision:
|
78
|
+
revision: 81ace2c598ec871572beee5792e2a2781b35e762
|
71
79
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
72
80
|
repo_dir: gems
|
73
81
|
- name: rack
|
@@ -75,7 +83,7 @@ gems:
|
|
75
83
|
source:
|
76
84
|
type: git
|
77
85
|
name: ruby/gem_rbs_collection
|
78
|
-
revision:
|
86
|
+
revision: 81ace2c598ec871572beee5792e2a2781b35e762
|
79
87
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
80
88
|
repo_dir: gems
|
81
89
|
- name: railties
|
@@ -83,7 +91,7 @@ gems:
|
|
83
91
|
source:
|
84
92
|
type: git
|
85
93
|
name: ruby/gem_rbs_collection
|
86
|
-
revision:
|
94
|
+
revision: 81ace2c598ec871572beee5792e2a2781b35e762
|
87
95
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
88
96
|
repo_dir: gems
|
89
97
|
- name: rainbow
|
@@ -91,6 +99,6 @@ gems:
|
|
91
99
|
source:
|
92
100
|
type: git
|
93
101
|
name: ruby/gem_rbs_collection
|
94
|
-
revision:
|
102
|
+
revision: 81ace2c598ec871572beee5792e2a2781b35e762
|
95
103
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
96
104
|
repo_dir: gems
|
@@ -1,18 +1,22 @@
|
|
1
1
|
module ActiveAdmin::MenuTree
|
2
2
|
class Config
|
3
|
-
|
4
|
-
|
3
|
+
type menu_tree_item = Hash[Symbol, untyped]
|
4
|
+
type menu_option = Hash[Symbol, untyped]
|
5
|
+
|
6
|
+
attr_reader menu_tree: Array[menu_tree_item]
|
7
|
+
attr_reader menu_options: Array[menu_option]
|
5
8
|
|
6
9
|
def initialize: () -> void
|
7
10
|
|
8
|
-
def menu_tree=: (untyped new_value) ->
|
11
|
+
# def menu_tree=: (Array[Hash[untyped, untyped]] new_value) -> void
|
12
|
+
def menu_tree=: (Array[untyped] new_value) -> void
|
9
13
|
|
10
|
-
def find_menu_option: (name: String) ->
|
14
|
+
def find_menu_option: (name: String) -> (menu_option | nil)
|
11
15
|
|
12
16
|
private
|
13
17
|
|
14
|
-
def flatten_menu_tree: () ->
|
18
|
+
def flatten_menu_tree: () -> Array[menu_option]
|
15
19
|
|
16
|
-
def format_options: (untyped item, index:
|
20
|
+
def format_options: (Hash[Symbol, untyped] item, index: Integer index, ?parent: String? parent) -> menu_option
|
17
21
|
end
|
18
22
|
end
|
@@ -3,12 +3,12 @@ module ActiveAdmin
|
|
3
3
|
class Error < StandardError
|
4
4
|
end
|
5
5
|
|
6
|
-
def self.setup: () { (
|
6
|
+
def self.setup: () { (Config) -> void } -> void
|
7
7
|
|
8
8
|
def self.config: () -> Config
|
9
9
|
|
10
10
|
private
|
11
11
|
|
12
|
-
def self.setup_menu_options: (
|
12
|
+
def self.setup_menu_options: (ActiveAdmin::Application) -> void
|
13
13
|
end
|
14
14
|
end
|
data/sig/lib/activeadmin.rbs
CHANGED
@@ -1,3 +1,8 @@
|
|
1
1
|
module ActiveAdmin
|
2
|
-
def self.before_load: () { (
|
2
|
+
def self.before_load: () { (ActiveAdmin::Application) -> void } -> void
|
3
|
+
|
4
|
+
class Application
|
5
|
+
def comments_menu=: (Hash[Symbol, untyped] | nil) -> void
|
6
|
+
def namespace: (Symbol) { (untyped) -> void } -> void
|
7
|
+
end
|
3
8
|
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.
|
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
|
@@ -70,12 +70,14 @@ files:
|
|
70
70
|
- sig/lib/activeadmin/menu_tree/config.rbs
|
71
71
|
- sig/lib/activeadmin/menu_tree/dsl.rbs
|
72
72
|
- sig/lib/activeadmin/menu_tree/version.rbs
|
73
|
+
- sig/lib/activesupport.rbs
|
73
74
|
homepage: https://github.com/shuuuuun/activeadmin-menu_tree
|
74
75
|
licenses:
|
75
76
|
- MIT
|
76
77
|
metadata:
|
77
78
|
homepage_uri: https://github.com/shuuuuun/activeadmin-menu_tree
|
78
79
|
source_code_uri: https://github.com/shuuuuun/activeadmin-menu_tree
|
80
|
+
rubygems_mfa_required: 'true'
|
79
81
|
post_install_message:
|
80
82
|
rdoc_options: []
|
81
83
|
require_paths:
|
@@ -91,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
91
93
|
- !ruby/object:Gem::Version
|
92
94
|
version: '0'
|
93
95
|
requirements: []
|
94
|
-
rubygems_version: 3.
|
96
|
+
rubygems_version: 3.3.3
|
95
97
|
signing_key:
|
96
98
|
specification_version: 4
|
97
99
|
summary: Allows ActiveAdmin menus to be managed in tree format.
|