ruby_cms 0.2.0.9 → 0.2.1.1

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.
@@ -39,15 +39,6 @@ module RubyCms
39
39
  permission: :manage_analytics,
40
40
  order: 1
41
41
  )
42
- RubyCms.register_page(
43
- key: :permissions,
44
- label: "Permissions",
45
- path: lambda(&:ruby_cms_admin_permissions_path),
46
- icon: :shield_check,
47
- section: :settings,
48
- permission: :manage_permissions,
49
- order: 2
50
- )
51
42
  RubyCms.register_page(
52
43
  key: :visitor_errors,
53
44
  label: "Visitor errors",
@@ -55,7 +46,16 @@ module RubyCms
55
46
  icon: :exclamation_triangle,
56
47
  section: :settings,
57
48
  permission: :manage_visitor_errors,
58
- order: 3
49
+ order: 2
50
+ )
51
+ RubyCms.register_page(
52
+ key: :permissions,
53
+ label: "Permissions",
54
+ path: lambda(&:ruby_cms_admin_permissions_path),
55
+ icon: :shield_check,
56
+ section: :settings,
57
+ permission: :manage_permissions,
58
+ order: 10
59
59
  )
60
60
  RubyCms.register_page(
61
61
  key: :users,
@@ -64,7 +64,7 @@ module RubyCms
64
64
  icon: :user_group,
65
65
  section: :settings,
66
66
  permission: :manage_permissions,
67
- order: 4
67
+ order: 20
68
68
  )
69
69
  RubyCms.register_page(
70
70
  key: :commands,
@@ -73,16 +73,17 @@ module RubyCms
73
73
  icon: :wrench,
74
74
  section: :settings,
75
75
  permission: :manage_admin,
76
- order: 5
76
+ order: 30
77
77
  )
78
- RubyCms.register_page(
78
+ RubyCms.nav_group(
79
79
  key: :settings,
80
80
  label: "Settings",
81
81
  path: lambda(&:ruby_cms_admin_settings_path),
82
82
  icon: :cog_6_tooth,
83
- section: :settings,
84
- permission: :manage_admin,
85
- order: 6
83
+ section: RubyCms::NAV_SECTION_BOTTOM,
84
+ children: %i[permissions users commands],
85
+ default_open: false,
86
+ order: 3
86
87
  )
87
88
  end
88
89
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RubyCms
4
- VERSION = "0.2.0.9"
4
+ VERSION = "0.2.1.1"
5
5
  end
data/lib/ruby_cms.rb CHANGED
@@ -75,6 +75,7 @@ module RubyCms
75
75
  resolved_path = path.kind_of?(Symbol) ? ->(v) { v.main_app.send(path) } : path
76
76
  resolved_icon = icon.nil? ? nil : RubyCms::Icons.resolve(icon)
77
77
  entry = {
78
+ type: :link,
78
79
  key: normalized_key,
79
80
  label: label.to_s,
80
81
  path: resolved_path,
@@ -94,6 +95,49 @@ module RubyCms
94
95
  entry
95
96
  end
96
97
 
98
+ # Register a navigation group (accordion) in the sidebar.
99
+ #
100
+ # A group can optionally have its own page (`path:`) and can contain child pages
101
+ # (registered via `register_page` / `nav_register`) referenced by their keys.
102
+ #
103
+ # Notes:
104
+ # - `children:` is an array of nav keys (Symbol/String) that will be rendered under the group.
105
+ # - Children are filtered by the same visibility rules as regular nav links.
106
+ # - A group is hidden if it has no visible children and no `path`.
107
+ def self.nav_group(
108
+ key:, label:, children:,
109
+ path: nil, icon: nil, section: nil, order: nil,
110
+ permission: nil, default_visible: true, default_open: true, **options
111
+ )
112
+ normalized_key = key.to_sym
113
+ normalized_section = section.presence || NAV_SECTION_MAIN
114
+ resolved_path = path.nil? ? nil : (path.kind_of?(Symbol) ? ->(v) { v.main_app.send(path) } : path)
115
+ resolved_icon = icon.nil? ? nil : RubyCms::Icons.resolve(icon)
116
+ normalized_children = Array(children).map(&:to_s).map(&:strip).reject(&:blank?).map(&:to_sym)
117
+
118
+ entry = {
119
+ type: :group,
120
+ key: normalized_key,
121
+ label: label.to_s,
122
+ path: resolved_path,
123
+ icon: resolved_icon,
124
+ section: normalized_section,
125
+ order: order,
126
+ permission: permission&.to_s,
127
+ default_visible: default_visible ? true : false,
128
+ default_open: default_open ? true : false,
129
+ children: normalized_children,
130
+ if: options[:if]
131
+ }
132
+
133
+ self.nav_registry = nav_registry.reject {|e| e[:key] == normalized_key }
134
+ self.nav_registry += [entry]
135
+
136
+ register_navigation_setting!(entry)
137
+
138
+ entry
139
+ end
140
+
97
141
  VALID_PAGE_SECTIONS = %i[main settings].freeze
98
142
 
99
143
  # Unified API to register an admin page: nav item + permission key in one call.
@@ -133,6 +177,45 @@ module RubyCms
133
177
  []
134
178
  end
135
179
 
180
+ # Sidebar rows for a given section. Includes groups (accordions) and top-level links.
181
+ # Returns an array of:
182
+ # - { type: :link, entry: <nav entry hash> }
183
+ # - { type: :group, group: <group entry hash>, children: [<nav entry hash>...] }
184
+ def self.visible_nav_sidebar_rows(section:, view_context: nil, user: nil)
185
+ visible = visible_nav_registry(view_context:, user:)
186
+ links = visible.select {|e| e[:type].to_s == "link" }
187
+ groups = visible.select {|e| e[:type].to_s == "group" }
188
+
189
+ links_by_key = links.index_by {|e| e[:key].to_sym }
190
+ nested_keys = groups.flat_map {|g| Array(g[:children]) }.map(&:to_sym).to_set
191
+
192
+ section_key = section.to_s
193
+ section_name = (section_key == "settings" ? NAV_SECTION_BOTTOM : NAV_SECTION_MAIN)
194
+
195
+ # groups first; children order uses their own order/label.
196
+ group_rows = groups
197
+ .select {|g| g[:section].to_s == section_name }
198
+ .sort_by {|g| nav_sort_tuple(g) }
199
+ .filter_map do |g|
200
+ child_entries = Array(g[:children]).map {|k| links_by_key[k.to_sym] }.compact
201
+ child_entries = child_entries.sort_by {|c| [c[:order] || 1000, c[:label].to_s] }
202
+ next if child_entries.empty? && g[:path].blank?
203
+ { type: :group, group: g, children: child_entries }
204
+ end
205
+
206
+ link_rows = links
207
+ .select {|e| e[:section].to_s == section_name }
208
+ .reject {|e| nested_keys.include?(e[:key].to_sym) }
209
+ .sort_by {|e| nav_sort_tuple(e) }
210
+ .map {|e| { type: :link, entry: e } }
211
+
212
+ merged = (group_rows.map {|r| [r, nav_sort_tuple(r[:group])] } +
213
+ link_rows.map {|r| [r, nav_sort_tuple(r[:entry])] })
214
+ .sort_by {|(_, tuple)| tuple }
215
+ .map(&:first)
216
+ merged
217
+ end
218
+
136
219
  module Nav
137
220
  def self.register(key:, label:, path:, icon: nil, section: nil, order: nil, permission: nil, default_visible: true, **)
138
221
  RubyCms.nav_register(
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_cms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0.9
4
+ version: 0.2.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Codebyjob
@@ -162,6 +162,7 @@ files:
162
162
  - app/views/layouts/ruby_cms/_admin_sidebar.html.erb
163
163
  - app/views/layouts/ruby_cms/admin.html.erb
164
164
  - app/views/layouts/ruby_cms/minimal.html.erb
165
+ - app/views/ruby_cms/_tailwind_safelist.html.erb
165
166
  - app/views/ruby_cms/admin/analytics/index.html.erb
166
167
  - app/views/ruby_cms/admin/analytics/page_details.html.erb
167
168
  - app/views/ruby_cms/admin/analytics/partials/_back_button.html.erb