eac_rails_utils 0.21.0 → 0.22.0
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/lib/eac_rails_utils/engine_helper.rb +12 -0
- data/lib/eac_rails_utils/menus/action.rb +33 -0
- data/lib/eac_rails_utils/menus/group.rb +73 -0
- data/lib/eac_rails_utils/menus/node.rb +50 -0
- data/lib/eac_rails_utils/menus.rb +9 -0
- data/lib/eac_rails_utils/patches/active_model/naming.rb +17 -0
- data/lib/eac_rails_utils/patches/active_model.rb +4 -0
- data/lib/eac_rails_utils/patches/application.rb +12 -0
- data/lib/eac_rails_utils/version.rb +1 -1
- metadata +13 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2d70491a91afe401a5ff75d1ecf1d1820e9164bb725d33ecbf5a233508e70faa
|
4
|
+
data.tar.gz: 59c3693a4563491e0da78bf4496d620c75025b7b70fb4cda760405ac04c3f436
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ed28ed741a6dc380f97f1b3a1af9afaba32baebeee1c06ccf81790eab178ac8eadf022051a3dd5dffd98c01bf421fc749ce69d4db8b4a078c8d347795a286949
|
7
|
+
data.tar.gz: d5b26dc72e4a8d36e9b609b606a95264432c81e612a08fa705c40da2db94fe3e6ba23108121f170dcd1f395cea969133c6799ab15ccb6520e0f3a8a22e2ed025
|
@@ -4,6 +4,13 @@ require 'eac_ruby_utils/core_ext'
|
|
4
4
|
|
5
5
|
module EacRailsUtils
|
6
6
|
module EngineHelper
|
7
|
+
class << self
|
8
|
+
# @return [EacRailsUtils::Menus::Group]
|
9
|
+
def root_menu
|
10
|
+
@root_menu ||= ::EacRailsUtils::Menus::Group.new(:root)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
7
14
|
common_concern do
|
8
15
|
append_autoload_paths
|
9
16
|
append_self_migrations
|
@@ -21,6 +28,11 @@ module EacRailsUtils
|
|
21
28
|
end
|
22
29
|
end
|
23
30
|
end
|
31
|
+
|
32
|
+
# @return [EacRailsUtils::Menus::Group]
|
33
|
+
def root_menu
|
34
|
+
::EacRailsUtils::EnginesHelper.root_menu
|
35
|
+
end
|
24
36
|
end
|
25
37
|
end
|
26
38
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_rails_utils/menus/node'
|
4
|
+
require 'eac_ruby_utils/core_ext'
|
5
|
+
|
6
|
+
module EacRailsUtils
|
7
|
+
module Menus
|
8
|
+
class Action < ::EacRailsUtils::Menus::Node
|
9
|
+
common_constructor :path, :parent_group, super_args: -> { [parent_group] } do
|
10
|
+
self.path = [parent_group.path_first_node] + path if path.size < 2
|
11
|
+
end
|
12
|
+
|
13
|
+
# @return [Symbol]
|
14
|
+
def key
|
15
|
+
path.map(&:to_s).join('_').to_sym
|
16
|
+
end
|
17
|
+
|
18
|
+
# @param view [ActionView::Base]
|
19
|
+
# @return [Array]
|
20
|
+
def to_dropdown_menu_entries(view)
|
21
|
+
[view_path(view)]
|
22
|
+
end
|
23
|
+
|
24
|
+
# @param view [ActionView::Base]
|
25
|
+
# @return [String]
|
26
|
+
def view_path(view)
|
27
|
+
path.each_with_index.inject(view) do |a, e|
|
28
|
+
a.send(e[1] == path.count - 1 ? "#{e[0]}_path" : e[0])
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_rails_utils/menus/action'
|
4
|
+
require 'eac_rails_utils/menus/node'
|
5
|
+
require 'eac_ruby_utils/core_ext'
|
6
|
+
|
7
|
+
module EacRailsUtils
|
8
|
+
module Menus
|
9
|
+
class Group < ::EacRailsUtils::Menus::Node
|
10
|
+
class << self
|
11
|
+
# @param key [Object]
|
12
|
+
# @return [Symbol]
|
13
|
+
def sanitize_key(key)
|
14
|
+
key.to_sym
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
DEFAULT_PATH_FIRST_NODE = :main_app
|
19
|
+
SELF_LABEL_TRANSLATE_KEY_PART = '__self'
|
20
|
+
|
21
|
+
common_constructor :key, :parent_group, :path_first_node, default: [nil],
|
22
|
+
super_args: -> { [parent_group] } do
|
23
|
+
self.key = self.class.sanitize_key(key)
|
24
|
+
self.path_first_node ||= DEFAULT_PATH_FIRST_NODE
|
25
|
+
end
|
26
|
+
|
27
|
+
# @param path [Array<Symbol>]
|
28
|
+
# @return [EacRailsUtils::Menus::Action]
|
29
|
+
def action(*path)
|
30
|
+
child_action = ::EacRailsUtils::Menus::Action.new(path, self)
|
31
|
+
actions[child_action.key] ||= child_action
|
32
|
+
end
|
33
|
+
|
34
|
+
# @return [Array<EacRailsUtils::Menus::Node>]
|
35
|
+
def children
|
36
|
+
(groups.values + actions.values).sort
|
37
|
+
end
|
38
|
+
|
39
|
+
# @return [EacRailsUtils::Menus::Group]
|
40
|
+
def group(group_key, path_first_node = nil)
|
41
|
+
child_group = self.class.new(group_key, self, path_first_node)
|
42
|
+
groups[child_group.key] ||= child_group
|
43
|
+
end
|
44
|
+
|
45
|
+
# @return [String]
|
46
|
+
def label_translate_key
|
47
|
+
[super, SELF_LABEL_TRANSLATE_KEY_PART].join(TRANSLATE_KEY_SEPARATOR)
|
48
|
+
end
|
49
|
+
|
50
|
+
# @param view [ActionView::Base]
|
51
|
+
# @return [Hash]
|
52
|
+
def to_dropdown_menu_entries(view)
|
53
|
+
children.inject({}) do |a, e|
|
54
|
+
a.merge(e.label => e.to_dropdown_menu_entries(view))
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def within
|
59
|
+
yield(self)
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
|
64
|
+
def actions
|
65
|
+
@actions ||= {}
|
66
|
+
end
|
67
|
+
|
68
|
+
def groups
|
69
|
+
@groups ||= {}
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
|
5
|
+
module EacRailsUtils
|
6
|
+
module Menus
|
7
|
+
class Node
|
8
|
+
LABEL_TRANSLATE_KEY_PREFIX = 'eac_rails_utils.menus'
|
9
|
+
TRANSLATE_KEY_SEPARATOR = '.'
|
10
|
+
|
11
|
+
acts_as_abstract :key
|
12
|
+
common_constructor :parent_group
|
13
|
+
compare_by :label
|
14
|
+
attr_reader :custom_label
|
15
|
+
|
16
|
+
# @return [String]
|
17
|
+
def auto_label
|
18
|
+
::I18n.t(label_translate_key)
|
19
|
+
end
|
20
|
+
|
21
|
+
# @param custom_label [String, nil]
|
22
|
+
# @return [String, self]
|
23
|
+
def label(custom_label = nil)
|
24
|
+
if custom_label.present?
|
25
|
+
self.custom_label = custom_label
|
26
|
+
self
|
27
|
+
else
|
28
|
+
(self.custom_label || auto_label).call_if_proc
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# @return [String]
|
33
|
+
def label_translate_key
|
34
|
+
parent_label_translate_key
|
35
|
+
end
|
36
|
+
|
37
|
+
# @return [String]
|
38
|
+
def parent_label_translate_key
|
39
|
+
[
|
40
|
+
parent_group.if_present(LABEL_TRANSLATE_KEY_PREFIX, &:parent_label_translate_key),
|
41
|
+
key
|
42
|
+
].join(TRANSLATE_KEY_SEPARATOR)
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
attr_writer :custom_label
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_model/naming'
|
4
|
+
|
5
|
+
module ActiveModel
|
6
|
+
module Naming
|
7
|
+
# @return [String]
|
8
|
+
def plural_name
|
9
|
+
model_name.human(count: 2)
|
10
|
+
end
|
11
|
+
|
12
|
+
# @return [String]
|
13
|
+
def singular_name
|
14
|
+
model_name.human(count: 1)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eac_rails_utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.22.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- E.A.C.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-09-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bootstrap-sass
|
@@ -36,20 +36,20 @@ dependencies:
|
|
36
36
|
requirements:
|
37
37
|
- - "~>"
|
38
38
|
- !ruby/object:Gem::Version
|
39
|
-
version: '0.
|
39
|
+
version: '0.119'
|
40
40
|
- - ">="
|
41
41
|
- !ruby/object:Gem::Version
|
42
|
-
version: 0.
|
42
|
+
version: 0.119.2
|
43
43
|
type: :runtime
|
44
44
|
prerelease: false
|
45
45
|
version_requirements: !ruby/object:Gem::Requirement
|
46
46
|
requirements:
|
47
47
|
- - "~>"
|
48
48
|
- !ruby/object:Gem::Version
|
49
|
-
version: '0.
|
49
|
+
version: '0.119'
|
50
50
|
- - ">="
|
51
51
|
- !ruby/object:Gem::Version
|
52
|
-
version: 0.
|
52
|
+
version: 0.119.2
|
53
53
|
- !ruby/object:Gem::Dependency
|
54
54
|
name: htmlbeautifier
|
55
55
|
requirement: !ruby/object:Gem::Requirement
|
@@ -205,6 +205,10 @@ files:
|
|
205
205
|
- lib/eac_rails_utils/engine.rb
|
206
206
|
- lib/eac_rails_utils/engine_helper.rb
|
207
207
|
- lib/eac_rails_utils/htmlbeautifier.rb
|
208
|
+
- lib/eac_rails_utils/menus.rb
|
209
|
+
- lib/eac_rails_utils/menus/action.rb
|
210
|
+
- lib/eac_rails_utils/menus/group.rb
|
211
|
+
- lib/eac_rails_utils/menus/node.rb
|
208
212
|
- lib/eac_rails_utils/models.rb
|
209
213
|
- lib/eac_rails_utils/models/fetch_errors.rb
|
210
214
|
- lib/eac_rails_utils/models/inequality_queries.rb
|
@@ -225,7 +229,10 @@ files:
|
|
225
229
|
- lib/eac_rails_utils/models/test_utils.rb
|
226
230
|
- lib/eac_rails_utils/models/validations.rb
|
227
231
|
- lib/eac_rails_utils/patches.rb
|
232
|
+
- lib/eac_rails_utils/patches/active_model.rb
|
233
|
+
- lib/eac_rails_utils/patches/active_model/naming.rb
|
228
234
|
- lib/eac_rails_utils/patches/active_model_associations.rb
|
235
|
+
- lib/eac_rails_utils/patches/application.rb
|
229
236
|
- lib/eac_rails_utils/patches/numeric.rb
|
230
237
|
- lib/eac_rails_utils/patches/numeric/number_helper.rb
|
231
238
|
- lib/eac_rails_utils/patches/rails_4.rb
|