activeadmin-menu_tree 0.1.1 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 915be184b52128a375b2b76397c266148d5a6f27847a704913623b71cec64aaa
4
- data.tar.gz: dab0db630d9510882682eb5ca72f6cc268c2f531e17e4f094b2b48aec25ccb61
3
+ metadata.gz: ae470640145da2a76875e361c8e1a5bb99838ff72894c9fc8f66dd266226004c
4
+ data.tar.gz: bc6fe3ffe900a9e8a1430ca25a82815c32d67f3b0979df55fe9af4bd25d3e223
5
5
  SHA512:
6
- metadata.gz: 9dc782fd55db0218d961c296afe543178d0a618708fe8009ed0b0bfcd408c7ecdc7bdbeab19135c0d6ddfa79d2805d118d85d5b30508f67ee0e9bcbdd8bc5192
7
- data.tar.gz: 5d8832823ad3112ecf687257e3948e3bc532331ca2dd9ca58e6a7d4c266112c2504f9b6a4054f8a6f720b3815574cadfcfeb7efc4d757885e8efd4d0f13b81da
6
+ metadata.gz: aa4d16bdde948794cc92965ffa9ec94cfbed5fdcf102c6300d941dbd6f8b80a73b69ced428cd884d37f40c582eab88d283b18299893f97cb8a69ff34a839ebbd
7
+ data.tar.gz: 53572e64a66d4aadd161f9d4f5c3d0d84ad4d9590d4310ef0c13334b205677ce447d45e4c7d4fbcb462c344d603e515152258b377d828dd829d2ac75bb786eea
@@ -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/.rubocop.yml CHANGED
@@ -11,6 +11,7 @@ AllCops:
11
11
  ExtraDetails: true
12
12
  Exclude:
13
13
  - 'spec/dummy/**/*'
14
+ - 'vendor/bundle/**/*'
14
15
 
15
16
  Style/ClassAndModuleChildren:
16
17
  Enabled: false
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/Makefile CHANGED
@@ -1,7 +1,7 @@
1
1
  .PHONY: rake/* rbs/* typeprof/* steep/*
2
2
 
3
3
  rake/tasks:
4
- rake --tasks
4
+ bundle exec rake --tasks
5
5
 
6
6
  rbs/prototype: rbs/prototype/lib
7
7
 
data/README.md CHANGED
@@ -46,12 +46,12 @@ Write the configuration in a yaml file.
46
46
  # config/activeadmin-menu_tree.yml or anywhere you like
47
47
  activeadmin:
48
48
  menu_tree:
49
- - name: Dashboard
49
+ - id: Dashboard
50
50
  - label: Admin
51
51
  children:
52
- - name: AdminUser
52
+ - id: AdminUser
53
53
  label: Admin Users
54
- - name: Comment
54
+ - id: Comment
55
55
  label: Admin Comments
56
56
  ```
57
57
 
@@ -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
+ { id: "Dashboard", label: proc { I18n.t("active_admin.dashboard") } },
96
+ {
97
+ label: "Foo",
98
+ if: proc { "Something dynamic" },
99
+ children: [
100
+ { id: "Bar" },
101
+ { id: "Baz" }
102
+ ]
103
+ }
104
+ ]
102
105
  end
103
106
  ```
104
107
 
@@ -118,36 +121,53 @@ 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:
124
- # Specify the resource name with `name`.
125
- - name: Dashboard
126
- - name: Product
128
+ # Specify the resource with `id`.
129
+ - id: Dashboard
130
+ - id: Product
127
131
  # Specify a menu label with `label`.
128
132
  - label: User Info
129
133
  # Specify child elements with `children`.
130
134
  children:
131
- - name: User
132
- - name: Profile
135
+ - id: User
136
+ - id: Profile
133
137
  - label: Admin
134
138
  children:
135
- - name: AdminUser
139
+ - id: AdminUser
136
140
  label: Admin Users
137
141
  # Comment resource will be handled specially.
138
- - name: Comment
142
+ - id: Comment
139
143
  label: Admin Comments
140
144
  - label: Others
141
145
  children:
142
- - name: Foo
143
- - name: Bar
146
+ - id: Foo
147
+ - id: Bar
144
148
  - label: Example Site
145
149
  # You can pass the other options available for `menu` DSL, like `url`, `html_options`.
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
 
168
+ <img width="1573" alt="screenshot" src="https://user-images.githubusercontent.com/7542105/153759374-fd516cb8-8022-4e44-aad9-c97f77afc4e7.png">
169
+
170
+
151
171
  ## Development
152
172
 
153
173
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -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.
@@ -14,33 +14,34 @@ 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
- def find_menu_option(name:)
21
- menu_options.find { |item| item[:name] == name }
20
+ def find_menu_option(id:)
21
+ menu_options.find { |item| item[:id] == id }
22
22
  end
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
39
36
 
40
37
  def format_options(item, index:, parent: nil)
38
+ # TODO: validate option
39
+ if item.key?(:name)
40
+ ActiveAdmin::MenuTree.warn_deprecated("Use `id` key, instead of `name`.")
41
+ options[:id] ||= item[:name]
42
+ end
41
43
  options = item.except(:children)
42
44
  options[:priority] = index * 10
43
- options[:label] ||= item[:name]&.pluralize&.titleize || ""
44
45
  options[:parent] = parent if parent.present?
45
46
  options
46
47
  end
@@ -4,8 +4,7 @@ module ActiveAdmin::MenuTree
4
4
  # ActiveAdmin::MenuTree::DSL class
5
5
  module DSL
6
6
  def menu_tree(**args)
7
- options = menu_tree_config.find_menu_option(name: config.resource_name.name) || {}
8
- options = options.except(:name)
7
+ options = menu_tree_config.find_menu_option(id: config.resource_name.name) || {}
9
8
  options = options.merge(args)
10
9
  menu(**options)
11
10
  end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveAdmin
4
+ module MenuTree
5
+ # ActiveAdmin::MenuTree::Logging module
6
+ module Logging
7
+ def debug?
8
+ ENV["MENU_TREE_DEBUG"]
9
+ end
10
+
11
+ def log_debug(message)
12
+ warn("[ActiveAdmin::MenuTree] #{message}") if debug?
13
+ end
14
+
15
+ def warn_deprecated(message)
16
+ warn("[ActiveAdmin::MenuTree] [DEPRECATION] #{message}")
17
+ end
18
+ end
19
+ end
20
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ActiveAdmin
4
4
  module MenuTree
5
- VERSION = "0.1.1"
5
+ VERSION = "0.2.1"
6
6
  end
7
7
  end
@@ -4,6 +4,7 @@ require "active_support"
4
4
  require "active_support/core_ext"
5
5
 
6
6
  require_relative "menu_tree/version"
7
+ require_relative "menu_tree/logging"
7
8
  require_relative "menu_tree/config"
8
9
  require_relative "menu_tree/dsl"
9
10
 
@@ -13,6 +14,8 @@ module ActiveAdmin
13
14
  class Error < StandardError; end
14
15
 
15
16
  class << self
17
+ include ActiveAdmin::MenuTree::Logging
18
+
16
19
  def setup
17
20
  raise ActiveAdmin::MenuTree::Error, "No block given, require a block" unless block_given?
18
21
 
@@ -32,13 +35,13 @@ module ActiveAdmin
32
35
  private
33
36
 
34
37
  def setup_menu_options(aa_config)
35
- comments_menu = config.find_menu_option(name: "Comment")
38
+ comments_menu = config.find_menu_option(id: "Comment")
36
39
  aa_config.comments_menu = comments_menu if comments_menu.present?
37
40
 
38
41
  menu_options = config.menu_options
39
- .reject{ |item| item[:name] == "Comment" }
40
- .map{ |item| item.except(:name) }
42
+ .reject{ |item| item[:id] == "Comment" }
41
43
 
44
+ ActiveAdmin::MenuTree.log_debug("menu_options: #{menu_options.inspect}")
42
45
  aa_config.namespace :admin do |admin|
43
46
  admin.build_menu do |menu|
44
47
  menu_options.each do |options|
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.1
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - shuuuuuny
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-10-03 00:00:00.000000000 Z
11
+ date: 2022-02-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activeadmin
@@ -61,6 +61,7 @@ files:
61
61
  - lib/activeadmin/menu_tree.rb
62
62
  - lib/activeadmin/menu_tree/config.rb
63
63
  - lib/activeadmin/menu_tree/dsl.rb
64
+ - lib/activeadmin/menu_tree/logging.rb
64
65
  - lib/activeadmin/menu_tree/version.rb
65
66
  - rbs_collection.lock.yaml
66
67
  - rbs_collection.yaml
@@ -77,6 +78,7 @@ licenses:
77
78
  metadata:
78
79
  homepage_uri: https://github.com/shuuuuun/activeadmin-menu_tree
79
80
  source_code_uri: https://github.com/shuuuuun/activeadmin-menu_tree
81
+ rubygems_mfa_required: 'true'
80
82
  post_install_message:
81
83
  rdoc_options: []
82
84
  require_paths:
@@ -92,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
92
94
  - !ruby/object:Gem::Version
93
95
  version: '0'
94
96
  requirements: []
95
- rubygems_version: 3.2.28
97
+ rubygems_version: 3.3.3
96
98
  signing_key:
97
99
  specification_version: 4
98
100
  summary: Allows ActiveAdmin menus to be managed in tree format.