katalyst-navigation 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/katalyst/navigation/items_controller.rb +10 -1
- data/app/helpers/katalyst/navigation/editor_helper.rb +4 -5
- data/app/helpers/katalyst/navigation/frontend/builder.rb +30 -14
- data/app/models/katalyst/navigation/button.rb +4 -0
- data/app/models/katalyst/navigation/item.rb +10 -0
- data/lib/katalyst/navigation/config.rb +19 -0
- data/lib/katalyst/navigation/version.rb +1 -1
- data/lib/katalyst/navigation.rb +10 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 368bcecb2264a1a536d2bbeb6c05f2dfa6762dcd693a215db21ef93db4da26f8
|
4
|
+
data.tar.gz: 83ef6762cddd830df2acc4ef1404c8037211c4de4b3dbe5d8b5501bb4cf42fd7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a4e9965e0b7e49c055e405d90dd13dcb764f2b4b1b0fb62191347eb066e784dea5c1ee069b9a848fe283d87da1241fa840663d8152a92fe2b1f73607bae11b9b
|
7
|
+
data.tar.gz: df13a7692f558a2eb5937a4e85d7137540d175ca6be500a743bfbd1caa53fc4fbba1be0acc27cc6bedf665009a8ff58439bc1d2fc35ae76028059ec0ea0614f4
|
@@ -41,8 +41,17 @@ module Katalyst
|
|
41
41
|
params[:type] || Link.name
|
42
42
|
end
|
43
43
|
|
44
|
+
def item_params_type
|
45
|
+
type = params.require(:item).fetch(:type, "")
|
46
|
+
if Katalyst::Navigation.config.items.include?(type)
|
47
|
+
type.safe_constantize
|
48
|
+
else
|
49
|
+
Item
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
44
53
|
def item_params
|
45
|
-
params.require(:item).permit(
|
54
|
+
params.require(:item).permit(item_params_type.permitted_params)
|
46
55
|
end
|
47
56
|
|
48
57
|
def set_menu
|
@@ -4,11 +4,10 @@ module Katalyst
|
|
4
4
|
module Navigation
|
5
5
|
module EditorHelper
|
6
6
|
def navigation_editor_new_items(menu)
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
]
|
7
|
+
Katalyst::Navigation.config.items.map do |item_class|
|
8
|
+
item_class = item_class.is_a?(String) ? item_class.safe_constantize : item_class
|
9
|
+
item_class.new(menu: menu)
|
10
|
+
end
|
12
11
|
end
|
13
12
|
|
14
13
|
def navigation_editor_menu(menu:, **options, &block)
|
@@ -1,22 +1,23 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# rubocop:disable Rails/HelperInstanceVariable
|
3
4
|
module Katalyst
|
4
5
|
module Navigation
|
5
6
|
module Frontend
|
6
7
|
class Builder
|
7
|
-
attr_accessor :template
|
8
|
+
attr_accessor :template
|
8
9
|
|
9
10
|
delegate_missing_to :@template
|
10
11
|
|
11
12
|
def initialize(template, list: {}, item: {}, **menu_options)
|
12
|
-
self.template
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
self.template = template
|
14
|
+
@menu_options = menu_options.freeze
|
15
|
+
@list_options = list.freeze
|
16
|
+
@item_options = item.freeze
|
16
17
|
end
|
17
18
|
|
18
19
|
def render(tree)
|
19
|
-
tag.ul
|
20
|
+
tag.ul(**menu_options(tree)) do
|
20
21
|
tree.each do |item|
|
21
22
|
concat render_item(item)
|
22
23
|
end
|
@@ -26,32 +27,47 @@ module Katalyst
|
|
26
27
|
def render_item(item)
|
27
28
|
return unless item.visible?
|
28
29
|
|
29
|
-
tag.li
|
30
|
+
tag.li(**item_options(item)) do
|
30
31
|
concat public_send("render_#{item.model_name.param_key}", item)
|
31
|
-
concat
|
32
|
+
concat render_children(item) if item.children.any?
|
32
33
|
end
|
33
34
|
end
|
34
35
|
|
35
|
-
def
|
36
|
-
tag.ul
|
37
|
-
|
36
|
+
def render_children(item)
|
37
|
+
tag.ul(**list_options(item)) do
|
38
|
+
item.children.each do |child|
|
38
39
|
concat render_item(child)
|
39
40
|
end
|
40
41
|
end
|
41
42
|
end
|
42
43
|
|
43
44
|
def render_heading(heading)
|
44
|
-
tag.
|
45
|
+
tag.span(heading.title)
|
45
46
|
end
|
46
47
|
|
47
48
|
def render_link(link)
|
48
|
-
link_to(link.title, link.url
|
49
|
+
link_to(link.title, link.url)
|
49
50
|
end
|
50
51
|
|
51
52
|
def render_button(link)
|
52
|
-
link_to(link.title, link.url,
|
53
|
+
link_to(link.title, link.url, method: link.http_method)
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def menu_options(_tree)
|
59
|
+
@menu_options
|
60
|
+
end
|
61
|
+
|
62
|
+
def list_options(_item)
|
63
|
+
@list_options
|
64
|
+
end
|
65
|
+
|
66
|
+
def item_options(_item)
|
67
|
+
@item_options
|
53
68
|
end
|
54
69
|
end
|
55
70
|
end
|
56
71
|
end
|
57
72
|
end
|
73
|
+
# rubocop:enable Rails/HelperInstanceVariable
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/configurable"
|
4
|
+
|
5
|
+
module Katalyst
|
6
|
+
module Navigation
|
7
|
+
class Config
|
8
|
+
include ActiveSupport::Configurable
|
9
|
+
|
10
|
+
config_accessor(:items) do
|
11
|
+
%w[
|
12
|
+
Katalyst::Navigation::Heading
|
13
|
+
Katalyst::Navigation::Link
|
14
|
+
Katalyst::Navigation::Button
|
15
|
+
]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/katalyst/navigation.rb
CHANGED
@@ -1,9 +1,19 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "katalyst/navigation/config"
|
3
4
|
require "katalyst/navigation/engine"
|
4
5
|
require "katalyst/navigation/version"
|
5
6
|
|
6
7
|
module Katalyst
|
7
8
|
module Navigation # :nodoc:
|
9
|
+
extend self
|
10
|
+
|
11
|
+
def config
|
12
|
+
@config ||= Config.new
|
13
|
+
end
|
14
|
+
|
15
|
+
def configure
|
16
|
+
yield config
|
17
|
+
end
|
8
18
|
end
|
9
19
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: katalyst-navigation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Katalyst Interactive
|
@@ -78,6 +78,7 @@ files:
|
|
78
78
|
- db/migrate/20220826034507_create_katalyst_navigation_items.rb
|
79
79
|
- db/migrate/20220908044500_add_depth_limit_to_menus.rb
|
80
80
|
- lib/katalyst/navigation.rb
|
81
|
+
- lib/katalyst/navigation/config.rb
|
81
82
|
- lib/katalyst/navigation/engine.rb
|
82
83
|
- lib/katalyst/navigation/version.rb
|
83
84
|
- lib/tasks/yarn.rake
|