keystone_ui 0.38.0 → 0.39.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ba03a37368cf5e1f7e0b18721a1eca9a04aae5dea7a5b3d8887e3db9956f9e8f
4
- data.tar.gz: 6c0eb35d049ec308a68984f32cd787d8fa1c183057a975322844187f294c31fc
3
+ metadata.gz: b11fa4104f5668547e8efeff23c90f69f4c3d1b7374103c33d7dc2c208363acb
4
+ data.tar.gz: 719716203afcd39869e402674d72a6bf8f1e5f4e7fce163a76c3429ae2bc77e2
5
5
  SHA512:
6
- metadata.gz: 36f95ca64410c3d39cae7355a0f1f7673a66e963ecf78a67d82a5559c74eef5ea02de3dc4668aef26fdab81b7b330d8d30dbb1a0aea658f13a188fdfdf296e27
7
- data.tar.gz: 41c5aff5beccf97a8fac694a8cb6e4250e9b6c4456efb78dc1335df8c5a3be086bacae0b5a28292520666bfae44f7df5b8d6cc9c2fbe36f88f619c0a61e33cc1
6
+ metadata.gz: b4849b26d1df9c8a45c7721fa966569e6d0f556780b5139a479a73e08c0602ce1db0eab5d4f8bfedcf5a30301cc4d1bba3cffdb0bf82e91a65a3d87c9fdb575c
7
+ data.tar.gz: 8fdb709bfbf187d4792a76c5057ebec69651fb5d4ba2e5b7a6b527b5e0ae68f437689896a492ec390f46ddc7d330fd3e00e2946588f41932d85bf82e790104e3
@@ -6,11 +6,11 @@
6
6
  <% if logo? %>
7
7
  <div><%= logo %></div>
8
8
  <% end %>
9
- <% groups.each do |group, tabs| %>
9
+ <% groups.each do |group| %>
10
10
  <div class="<%= SIDEBAR_GROUP_CLASSES %>">
11
- <p class="<%= sidebar_group_label_classes(tabs) %>"><%= group.label %></p>
12
- <% tabs.each do |tab| %>
13
- <a class="<%= sidebar_tab_classes(tab) %>" href="<%= tab.href_for(helpers) %>"><%= tab.label %></a>
11
+ <p class="<%= sidebar_group_label_classes(group) %>"><%= group.label %></p>
12
+ <% group.tabs.each do |tab| %>
13
+ <a class="<%= sidebar_tab_classes(tab) %>" href="<%= tab.href %>"><%= tab.label %></a>
14
14
  <% end %>
15
15
  </div>
16
16
  <% end %>
@@ -31,10 +31,10 @@
31
31
  <% navbar.with_logo do %><%= logo %><% end %>
32
32
  <% end %>
33
33
  <% navbar.with_desktop_links do %>
34
- <% groups.each do |group, tabs| %>
35
- <%= render Keystone::Ui::NavDropdownComponent.new(title: group.label, area: group.label, active: holds_current?(tabs)) do %>
36
- <% tabs.each do |tab| %>
37
- <%= render Keystone::Ui::NavItemComponent.new(label: tab.label, href: tab.href_for(helpers), active: current?(tab)) %>
34
+ <% groups.each do |group| %>
35
+ <%= render Keystone::Ui::NavDropdownComponent.new(title: group.label, area: group.label, active: group.active) do %>
36
+ <% group.tabs.each do |tab| %>
37
+ <%= render Keystone::Ui::NavItemComponent.new(label: tab.label, href: tab.href, active: tab.active) %>
38
38
  <% end %>
39
39
  <% end %>
40
40
  <% end %>
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "keystone_ui/navigation_order"
3
+ require "keystone_ui/visible_navigation"
4
4
 
5
5
  module Keystone
6
6
  module Ui
@@ -22,27 +22,20 @@ module Keystone
22
22
  attr_reader :groups
23
23
 
24
24
  def before_render
25
- permitted = KeystoneUi.configuration.navigation_groups
26
- .map { |group| [ group, group.tabs_permitted_for(helpers) ] }
27
- .reject { |_group, tabs| tabs.empty? }
28
- @groups = KeystoneUi::NavigationOrder.new(saved_navigation["order"] || []).arrange(permitted)
29
- @current_tab = KeystoneUi.configuration.supplied_current_tab(helpers)
25
+ @groups = KeystoneUi::VisibleNavigation.new(
26
+ KeystoneUi.configuration.navigation_groups,
27
+ view: helpers,
28
+ saved_order: saved_navigation["order"] || [],
29
+ current_tab: KeystoneUi.configuration.supplied_current_tab(helpers)
30
+ ).groups
30
31
  end
31
32
 
32
- def current?(tab)
33
- tab.key == @current_tab
34
- end
35
-
36
- def holds_current?(tabs)
37
- tabs.any? { |tab| current?(tab) }
38
- end
39
-
40
- def sidebar_group_label_classes(tabs)
41
- [ SIDEBAR_GROUP_LABEL_CLASSES, (ACTIVE_CLASS if holds_current?(tabs)) ].compact.join(" ")
33
+ def sidebar_group_label_classes(group)
34
+ [ SIDEBAR_GROUP_LABEL_CLASSES, (ACTIVE_CLASS if group.active) ].compact.join(" ")
42
35
  end
43
36
 
44
37
  def sidebar_tab_classes(tab)
45
- [ SIDEBAR_TAB_CLASSES, (ACTIVE_CLASS if current?(tab)) ].compact.join(" ")
38
+ [ SIDEBAR_TAB_CLASSES, (ACTIVE_CLASS if tab.active) ].compact.join(" ")
46
39
  end
47
40
 
48
41
  def anything_to_show?
@@ -3,6 +3,7 @@
3
3
  require "keystone_ui/source_css"
4
4
  require "keystone_ui/leftover_stylesheet"
5
5
  require "keystone_ui/look_check"
6
+ require "keystone_ui/navigation_check"
6
7
 
7
8
  module KeystoneUi
8
9
  class Engine < ::Rails::Engine
@@ -32,8 +33,13 @@ module KeystoneUi
32
33
  KeystoneUi::LookCheck.new(looks: config.looks, default: config.default_look).call
33
34
  end
34
35
 
36
+ def self.check_navigation
37
+ KeystoneUi::NavigationCheck.new(groups: KeystoneUi.configuration.navigation_groups).call
38
+ end
39
+
35
40
  config.after_initialize do
36
41
  KeystoneUi::Engine.check_looks
42
+ KeystoneUi::Engine.check_navigation
37
43
 
38
44
  tailwind_dir = Rails.root.join("app/assets/tailwind")
39
45
  css_path = tailwind_dir.join("application.css")
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KeystoneUi
4
+ class NavigationCheck
5
+ class Error < StandardError; end
6
+
7
+ def initialize(groups:)
8
+ @groups = groups
9
+ end
10
+
11
+ def call
12
+ @groups.each do |group|
13
+ raise Error, "The #{group.label} navigation group has no tabs." if group.tabs.empty?
14
+ end
15
+ tabs.each do |tab|
16
+ raise Error, "The #{tab.key} tab has no label." if blank?(tab.label)
17
+ raise Error, "The #{tab.key} tab has no link." if blank?(tab.href)
18
+ end
19
+ raise Error, "More than one navigation tab has the key #{shared_key}." if shared_key
20
+ nil
21
+ end
22
+
23
+ private
24
+
25
+ def tabs
26
+ @groups.flat_map(&:tabs)
27
+ end
28
+
29
+ def shared_key
30
+ tabs.map(&:key).tally.find { |_key, count| count > 1 }&.first
31
+ end
32
+
33
+ def blank?(value)
34
+ value.nil? || value.to_s.strip.empty?
35
+ end
36
+ end
37
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module KeystoneUi
4
- VERSION = "0.38.0"
4
+ VERSION = "0.39.0"
5
5
  end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "keystone_ui/navigation_order"
4
+
5
+ module KeystoneUi
6
+ class VisibleNavigation
7
+ Group = Struct.new(:label, :tabs, :active, keyword_init: true)
8
+ Tab = Struct.new(:label, :href, :active, keyword_init: true)
9
+
10
+ def initialize(declared_groups, view:, saved_order:, current_tab:)
11
+ @declared_groups = declared_groups
12
+ @view = view
13
+ @saved_order = saved_order
14
+ @current_tab = current_tab
15
+ end
16
+
17
+ def groups
18
+ NavigationOrder.new(@saved_order).arrange(permitted).map { |group, tabs| visible_group(group, tabs) }
19
+ end
20
+
21
+ private
22
+
23
+ def permitted
24
+ @declared_groups
25
+ .map { |group| [ group, group.tabs_permitted_for(@view) ] }
26
+ .reject { |_group, tabs| tabs.empty? }
27
+ end
28
+
29
+ def visible_group(group, tabs)
30
+ visible_tabs = tabs.map { |tab| visible_tab(tab) }
31
+ Group.new(label: group.label, tabs: visible_tabs, active: visible_tabs.any?(&:active))
32
+ end
33
+
34
+ def visible_tab(tab)
35
+ Tab.new(label: tab.label, href: tab.href_for(@view), active: tab.key == @current_tab)
36
+ end
37
+ end
38
+ end