keystone_ui 0.19.0 → 0.20.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: 19d3d7682e2b19ea8bdeadd90f50b0668db2587e21c891c220fdbb5af56a3780
4
- data.tar.gz: dafd5905c87e5723538ffd9f581b3e6edafe6d8a248a5364580191350778fe82
3
+ metadata.gz: 2831a7bc53b87bd905d8b270f78c26d1d47a8fe32bff2bf53c60093b8c84cf03
4
+ data.tar.gz: 36cf740c39fbeb33f4cc27d9ea4942e3ddfac9712856c195de49d3cde4989f66
5
5
  SHA512:
6
- metadata.gz: 0ee13705c4e25ef9c471d11005dfc081069acfb204482055198e35e1ddf131e836755769e42b26a3ec88e7f452e8ed47068b660430ad2d812eaaf72aeb734fb9
7
- data.tar.gz: d48180384c5199e133b23792a0b8fdd569347f9800abe0edf49ecf18dcccad7aee3b3419133e6fb4b9ced574280e0eb7659bdf60fd920b9596008cbb0870de6b
6
+ metadata.gz: ddf44be2fc4062b9ab5655f72d613dad4d6e367cfd138c95513adfd1cb749df42c7b1309972d688b629247b792cceba97f568c55850609209e6e1ae9426972c9
7
+ data.tar.gz: 70507b228b07861f2ca48449bfa3dbeb0b28019bd5f3a5a22eaf2cfa4ba852d160a7401ec0058c7a8e832afea1a06e1c548b312bab74a8f5efa93d5f05f903b1
@@ -3,11 +3,13 @@ export function keepPageThemeInStep(page = document) {
3
3
  const next = detail.newBody.closest("html")
4
4
  if (!next) return
5
5
 
6
- const theme = next.dataset.theme
7
- if (theme) {
8
- page.documentElement.dataset.theme = theme
9
- } else {
10
- delete page.documentElement.dataset.theme
6
+ for (const name of ["theme", "look"]) {
7
+ const value = next.dataset[name]
8
+ if (value) {
9
+ page.documentElement.dataset[name] = value
10
+ } else {
11
+ delete page.documentElement.dataset[name]
12
+ }
11
13
  }
12
14
  })
13
15
  }
@@ -2,6 +2,7 @@
2
2
 
3
3
  require "keystone_ui/source_css"
4
4
  require "keystone_ui/leftover_stylesheet"
5
+ require "keystone_ui/look_check"
5
6
 
6
7
  module KeystoneUi
7
8
  class Engine < ::Rails::Engine
@@ -26,7 +27,14 @@ module KeystoneUi
26
27
  # that also need the palette should use config.after_initialize too —
27
28
  # Rails runs these in engine dependency order, so KeystoneUi's block
28
29
  # executes before any engine that depends on it.
30
+ def self.check_looks
31
+ config = KeystoneUi.configuration
32
+ KeystoneUi::LookCheck.new(looks: config.looks, default: config.default_look).call
33
+ end
34
+
29
35
  config.after_initialize do
36
+ KeystoneUi::Engine.check_looks
37
+
30
38
  tailwind_dir = Rails.root.join("app/assets/tailwind")
31
39
  css_path = tailwind_dir.join("application.css")
32
40
  next unless css_path.exist?
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KeystoneUi
4
+ class LookCheck
5
+ class Error < StandardError; end
6
+
7
+ def initialize(looks:, default:)
8
+ @looks = looks
9
+ @default = default
10
+ end
11
+
12
+ def call
13
+ raise Error, "The default look #{@default} is not a registered look." if @default && !@looks.key?(@default)
14
+
15
+ @looks.each do |name, path|
16
+ raise Error, "The #{name} look's file #{path} does not exist." unless File.exist?(path)
17
+ raise Error, "The #{name} look's file #{path} sets no --ks- variables under :root[data-look=\"#{name}\"]." unless sets_variables?(name, path)
18
+ end
19
+ nil
20
+ end
21
+
22
+ private
23
+
24
+ def sets_variables?(name, path)
25
+ File.read(path).match?(/\[data-look=["']?#{Regexp.escape(name)}["']?\][^{]*\{[^}]*--ks-/)
26
+ end
27
+ end
28
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module KeystoneUi
4
- VERSION = "0.19.0"
4
+ VERSION = "0.20.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: keystone_ui
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.19.0
4
+ version: 0.20.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyler Schneider
@@ -186,6 +186,7 @@ files:
186
186
  - lib/keystone_ui/configuration.rb
187
187
  - lib/keystone_ui/engine.rb
188
188
  - lib/keystone_ui/leftover_stylesheet.rb
189
+ - lib/keystone_ui/look_check.rb
189
190
  - lib/keystone_ui/look_choice.rb
190
191
  - lib/keystone_ui/safelist.rb
191
192
  - lib/keystone_ui/source_css.rb