keystone_ui-colors 0.4.1 → 0.5.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: e06b73e93b9e73587971d465b75f6aa1724bebdb9fe5c0da29335e502931b625
4
- data.tar.gz: a6644a883ec9b73249c3738cd38b9342d29c5485d29c7f6218ea4657c5fd81ff
3
+ metadata.gz: 7e19d4ac1360f6f858edb7466444b610d3aa41f27c41c770f9d2b1674e51d04b
4
+ data.tar.gz: 53bc07b0653b12cd9b36f9b94908a6aebdb8cc79370618c0ba70f22a27fdf21a
5
5
  SHA512:
6
- metadata.gz: cbc58ef7595fddbe715b833b3292a40e6559a6a589f71cfd90ccf20f57275aea508b7a98347100f7607d346d6a9d4a062a17a73b6be3da5d66c91ee13d8ed2b3
7
- data.tar.gz: d66910b5ecd31bc3582bed2df71296fe0b3b614dc7e0e7dcf6a849e52febcae94c694acfc481fbde11dac0442b81e0b04de47f2c8fa634bfd8a31a728d354a1f
6
+ metadata.gz: e9e76f7316025de47b02b16e490c674dbacc7fd2eb43d0122c9a84b1d60c0350bda35a4514993a550ffa28e4b624ef7961cb72aee95bc7aeb62f576e5a3675cb
7
+ data.tar.gz: b2f238d93c3fd4384d99e94891ef4afff962dded85eb3809f6fd8ac111eb17c9513e9cda2d61f102da557deef1f9093a1f4d46598c9e3058cbd81d8d9365db79
data/README.md CHANGED
@@ -8,7 +8,7 @@ Users pick from preset themes or custom hex colors. The gem generates CSS custom
8
8
 
9
9
  - Ruby >= 3.1
10
10
  - Rails >= 7.0
11
- - [keystone_ui](https://github.com/DYB-Development/keystone_ui) >= 0.4.1
11
+ - [keystone_ui](https://github.com/DYB-Development/keystone_ui) >= 0.18.0
12
12
 
13
13
  ## Installation
14
14
 
@@ -172,6 +172,48 @@ end
172
172
  A choice made with keystone_ui's `ui_theme_toggle` in that browser still sets
173
173
  light or dark on these pages.
174
174
 
175
+ Such a page also shows the host's default look, over any look a user or account chose, for the same actions.
176
+
177
+ ## Looks
178
+
179
+ When the host registers looks with keystone_ui, a signed-in user's preference can
180
+ hold one in its `look` column, and every page they see carries it as
181
+ `data-look` on the `html` tag. A user with no saved look, and a visitor who is
182
+ not signed in, see the host's `default_look`. A saved look the host no longer registers is passed over for the account's look,
183
+ or for the host's default when the account's look is not registered either. The
184
+ settings page then shows no look selected and still saves. While an account's colours apply, the
185
+ page still shows the user's own look.
186
+
187
+ The colours settings page lists every registered look, with the user's current
188
+ look chosen, and saves the one they pick. A name the host does not register is
189
+ refused with a message and nothing is stored. With no looks registered the page
190
+ shows no look choice.
191
+
192
+ A host that wants every user on one look sets `user_looks` to false:
193
+
194
+ ```ruby
195
+ KeystoneUi::Colors.configure do |config|
196
+ config.user_looks = false
197
+ end
198
+ ```
199
+
200
+ The settings page then shows no look choice, a save ignores any look sent with
201
+ it and keeps the rest, and every page shows the host's default look, even for a
202
+ user who saved one earlier. `user_looks` is true by default.
203
+
204
+ An account admin picks the account's look on the account picker, which lists
205
+ every registered look with the account's current one chosen. A member with no
206
+ look of their own sees the account's look, and a member who chose one keeps it.
207
+ A host that keeps accounts off looks sets `account_looks` to false, and the
208
+ account picker then shows no look choice and a saved account look is not
209
+ applied. `account_looks` is true by default.
210
+
211
+ The account picker also has a switch for whether members choose their own
212
+ look, on by default and separate from the switch for colours. With it off, every
213
+ member sees the account's look whatever they saved, and a member's picker shows
214
+ no look choice. Run the update generator to add its column to an app that
215
+ installed an earlier version.
216
+
175
217
  ## Preset Themes
176
218
 
177
219
  | Name | Accent | Surface | Custom background | Custom text | Description |
@@ -257,7 +299,7 @@ Accepts named colors (`"blue"`) or hex values (`"#3b82f6"`) for `accent` and `su
257
299
 
258
300
  ## Updating
259
301
 
260
- Run the update generator to get the latest Stimulus controller and any new migrations (such as the text colour column), then migrate:
302
+ Run the update generator to get the latest Stimulus controller and any new migrations (such as the text colour and look columns), then migrate:
261
303
 
262
304
  ```bash
263
305
  bin/rails generate keystone_ui:colors:update
@@ -8,7 +8,7 @@ module KeystoneUi
8
8
  extend ActiveSupport::Concern
9
9
 
10
10
  included do
11
- helper_method :keystone_palette_css, :keystone_theme_mode if respond_to?(:helper_method)
11
+ helper_method :keystone_palette_css, :keystone_theme_mode, :keystone_look if respond_to?(:helper_method)
12
12
  end
13
13
 
14
14
  class_methods do
@@ -28,6 +28,7 @@ module KeystoneUi
28
28
 
29
29
  if cached && !stale_cache?(owner, cached)
30
30
  @keystone_theme_mode = cached[:mode] || KeystoneUi::Colors.configuration.default_mode
31
+ @keystone_look = own_look(cached[:look])
31
32
  build_palette_css(
32
33
  cached[:accent],
33
34
  cached[:surface],
@@ -38,6 +39,7 @@ module KeystoneUi
38
39
 
39
40
  preference = KeystoneUi::Colors::ThemePreference.find_by(owner: owner)
40
41
  @keystone_theme_mode = preference&.mode || KeystoneUi::Colors.configuration.default_mode
42
+ @keystone_look = own_look(preference&.look)
41
43
  accent = preference&.accent || KeystoneUi::Colors.configuration.default_accent
42
44
  surface = preference&.surface || KeystoneUi::Colors.configuration.default_surface
43
45
 
@@ -51,6 +53,7 @@ module KeystoneUi
51
53
  mode: preference.mode,
52
54
  template_name: preference.template_name,
53
55
  text: preference.text,
56
+ look: preference.look,
54
57
  updated_at: preference.updated_at.to_i
55
58
  }
56
59
  end
@@ -59,11 +62,13 @@ module KeystoneUi
59
62
  def apply_chosen_palette(owner, account)
60
63
  choice = KeystoneUi::Colors::ColourChoice.new(person: owner, account: account)
61
64
  @keystone_theme_mode = choice.mode
65
+ @keystone_look = choice.look
62
66
  write_palette(choice.applying_preference)
63
67
  end
64
68
 
65
69
  def apply_host_palette
66
70
  @keystone_theme_mode = KeystoneUi::Colors.configuration.default_mode
71
+ @keystone_look = nil
67
72
  build_palette_css(
68
73
  KeystoneUi::Colors.configuration.default_accent,
69
74
  KeystoneUi::Colors.configuration.default_surface,
@@ -79,8 +84,16 @@ module KeystoneUi
79
84
  @keystone_theme_mode
80
85
  end
81
86
 
87
+ def keystone_look
88
+ @keystone_look
89
+ end
90
+
82
91
  private
83
92
 
93
+ def own_look(look)
94
+ look if KeystoneUi::Colors.configuration.user_looks
95
+ end
96
+
84
97
  def keystone_account
85
98
  method = KeystoneUi::Colors.configuration.current_account_method
86
99
  send(method) if method
@@ -117,7 +130,7 @@ module KeystoneUi
117
130
  end
118
131
 
119
132
  def stale_cache?(owner, cached)
120
- return true unless cached.key?(:text)
133
+ return true unless cached.key?(:text) && cached.key?(:look)
121
134
 
122
135
  updated_at = KeystoneUi::Colors::ThemePreference
123
136
  .where(owner: owner)
@@ -14,7 +14,10 @@ module KeystoneUi
14
14
  def update
15
15
  result = PickColours.new(person: current_owner, account: nil, values: preference_params).call
16
16
 
17
- return render :show, status: :unprocessable_entity unless result.ok?
17
+ unless result.ok?
18
+ flash.now[:alert] = result.message
19
+ return render :show, status: :unprocessable_entity
20
+ end
18
21
 
19
22
  ForgetTheThemeChoice.new(controller: self).call
20
23
  redirect_to keystone_ui_colors.settings_path, notice: "Color settings updated."
@@ -29,7 +32,7 @@ module KeystoneUi
29
32
  end
30
33
 
31
34
  def preference_params
32
- params.permit(:accent, :surface, :text, :template_name, :mode).to_h.symbolize_keys
35
+ params.permit(:accent, :surface, :text, :template_name, :mode, :look).to_h.symbolize_keys
33
36
  end
34
37
  end
35
38
  end
@@ -27,6 +27,16 @@ module KeystoneUi
27
27
  own_preference&.mode || KeystoneUi::Colors.configuration.default_mode
28
28
  end
29
29
 
30
+ def look
31
+ [ (own_preference&.look if person_chooses_look?), (account_preference&.look if KeystoneUi::Colors.configuration.account_looks) ].find { |look| KeystoneUi.configuration.looks.key?(look) }
32
+ end
33
+
34
+ def person_chooses_look?
35
+ return false unless KeystoneUi::Colors.configuration.user_looks
36
+
37
+ account_preference.nil? || account_preference.members_choose_look
38
+ end
39
+
30
40
  def custom_offered?
31
41
  preference = applying_preference
32
42
  background = CustomColours.new(template_name: preference&.template_name, surface: preference&.surface, text: preference&.text).background
@@ -11,10 +11,11 @@ module KeystoneUi
11
11
  def call
12
12
  return Refusal.new("This app does not let accounts choose their colours.") unless KeystoneUi::Colors.configuration.account_colors
13
13
 
14
- result = PickColours.new(owner: @account, values: @values.except(:members_choose, :mode)).call
15
- return result unless result.ok? && @values.key?(:members_choose)
14
+ result = PickColours.new(owner: @account, values: @values.except(:members_choose, :members_choose_look, :mode), look_allowed: KeystoneUi::Colors.configuration.account_looks).call
15
+ return result unless result.ok?
16
16
 
17
- ThemePreference.find_by(owner: @account).update!(members_choose: @values[:members_choose] == "1")
17
+ switches = @values.slice(:members_choose, :members_choose_look).transform_values { |value| value == "1" }
18
+ ThemePreference.find_by(owner: @account).update!(switches) if switches.any?
18
19
  result
19
20
  end
20
21
  end
@@ -3,14 +3,16 @@
3
3
  module KeystoneUi
4
4
  module Colors
5
5
  class PickColours
6
- def initialize(values:, person: nil, account: nil, owner: nil)
6
+ def initialize(values:, person: nil, account: nil, owner: nil, look_allowed: KeystoneUi::Colors.configuration.user_looks)
7
7
  @owner = person || owner
8
+ @look_allowed = look_allowed
8
9
  @account = account
9
10
  @values = values
10
11
  end
11
12
 
12
13
  def call
13
14
  preference.assign_attributes(chosen_colours)
15
+ preference.look = @values[:look] if @values.key?(:look) && @look_allowed
14
16
 
15
17
  return Refusal.new(preference.errors.full_messages.first) unless preference.save
16
18
 
@@ -20,6 +20,7 @@ module KeystoneUi
20
20
  validates :template_name, inclusion: { in: Templates.names.map(&:to_s) }, allow_blank: true
21
21
  validates :mode, inclusion: { in: MODES }, allow_nil: true
22
22
  validates :text, format: { with: HEX_COLOR }, allow_blank: true
23
+ validate :look_is_registered, if: :will_save_change_to_look?
23
24
 
24
25
  def apply_template!(name)
25
26
  template = Templates[name]
@@ -32,6 +33,12 @@ module KeystoneUi
32
33
 
33
34
  private
34
35
 
36
+ def look_is_registered
37
+ return if look.nil? || KeystoneUi.configuration.looks.key?(look)
38
+
39
+ errors.add(:look, "is not a look this app offers")
40
+ end
41
+
35
42
  def accent_is_valid
36
43
  return if SUPPORTED_ACCENTS.include?(accent) || accent&.match?(HEX_COLOR)
37
44
 
@@ -9,9 +9,17 @@
9
9
  <div style="display: flex; flex-direction: column; gap: 2rem;">
10
10
  <%= render partial: "keystone_ui/colors/settings/colours", locals: { preference: preference } %>
11
11
 
12
+ <% if KeystoneUi.configuration.looks.any? && KeystoneUi::Colors.configuration.account_looks %>
13
+ <%= render partial: "keystone_ui/colors/settings/looks", locals: { preference: preference } %>
14
+ <% end %>
15
+
12
16
  <%= ui_section(title: "Members", spacing: :sm) do %>
13
17
  <%= hidden_field_tag "members_choose", "0", id: nil %>
14
18
  <%= ui_checkbox_row(name: "members_choose", value: "1", label: "Members choose their own colours", checked: preference.members_choose) %>
19
+ <% if KeystoneUi.configuration.looks.any? && KeystoneUi::Colors.configuration.account_looks %>
20
+ <%= hidden_field_tag "members_choose_look", "0", id: nil %>
21
+ <%= ui_checkbox_row(name: "members_choose_look", value: "1", label: "Members choose their own look", checked: preference.members_choose_look) %>
22
+ <% end %>
15
23
  <% end %>
16
24
 
17
25
  <div>
@@ -0,0 +1,7 @@
1
+ <%= ui_section(title: "Look", spacing: :sm) do %>
2
+ <div style="display: flex; flex-wrap: wrap; gap: 0.5rem;">
3
+ <% KeystoneUi.configuration.looks.each_key do |look| %>
4
+ <%= ui_radio_card(name: "look", value: look, label: look.humanize, checked: (preference.look || KeystoneUi.configuration.default_look) == look) %>
5
+ <% end %>
6
+ </div>
7
+ <% end %>
@@ -16,6 +16,10 @@
16
16
  <%= render partial: "keystone_ui/colors/settings/colours", locals: { preference: preference } %>
17
17
  <% end %>
18
18
 
19
+ <% if KeystoneUi.configuration.looks.any? && choice.person_chooses_look? %>
20
+ <%= render partial: "keystone_ui/colors/settings/looks", locals: { preference: preference } %>
21
+ <% end %>
22
+
19
23
  <%= ui_section(title: "Mode", spacing: :sm) do %>
20
24
  <div style="display: flex; flex-wrap: wrap; gap: 0.5rem;">
21
25
  <% KeystoneUi::Colors::ThemePreference::MODES.each do |mode| %>
@@ -1,5 +1,9 @@
1
1
  <%= ui_page_header(title: "Color Settings") %>
2
2
 
3
+ <% if flash[:alert] %>
4
+ <%= ui_alert(message: flash[:alert], type: :error) %>
5
+ <% end %>
6
+
3
7
  <% if flash[:notice] %>
4
8
  <%= ui_alert(message: flash[:notice], type: :success) %>
5
9
  <% end %>
@@ -6,7 +6,9 @@ class CreateKeystoneUiColorsThemePreferences < ActiveRecord::Migration[<%= Activ
6
6
  t.string :template_name
7
7
  t.string :mode
8
8
  t.string :text
9
+ t.string :look
9
10
  t.boolean :members_choose, default: true, null: false
11
+ t.boolean :members_choose_look, default: true, null: false
10
12
  t.references :owner, polymorphic: true, null: false
11
13
  t.timestamps
12
14
  end
@@ -0,0 +1,5 @@
1
+ class AddLookToKeystoneUiColorsThemePreferences < ActiveRecord::Migration[<%= ActiveRecord::Migration.current_version %>]
2
+ def change
3
+ add_column :keystone_ui_colors_theme_preferences, :look, :string
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class AddMembersChooseLookToKeystoneUiColorsThemePreferences < ActiveRecord::Migration[<%= ActiveRecord::Migration.current_version %>]
2
+ def change
3
+ add_column :keystone_ui_colors_theme_preferences, :members_choose_look, :boolean, default: true, null: false
4
+ end
5
+ end
@@ -40,6 +40,24 @@ module KeystoneUi
40
40
  )
41
41
  end
42
42
 
43
+ def add_look_migration
44
+ return if column_migrated?(:look)
45
+
46
+ migration_template(
47
+ File.expand_path("templates/add_look_to_keystone_ui_colors_theme_preferences.rb.erb", __dir__),
48
+ "db/migrate/add_look_to_keystone_ui_colors_theme_preferences.rb"
49
+ )
50
+ end
51
+
52
+ def add_members_choose_look_migration
53
+ return if column_migrated?(:members_choose_look)
54
+
55
+ migration_template(
56
+ File.expand_path("templates/add_members_choose_look_to_keystone_ui_colors_theme_preferences.rb.erb", __dir__),
57
+ "db/migrate/add_members_choose_look_to_keystone_ui_colors_theme_preferences.rb"
58
+ )
59
+ end
60
+
43
61
  def copy_stimulus_controller
44
62
  copy_file "theme_settings_controller.js",
45
63
  "app/javascript/controllers/keystone_ui/colors/theme_settings_controller.js"
@@ -3,7 +3,7 @@
3
3
  module KeystoneUi
4
4
  module Colors
5
5
  class Configuration
6
- attr_accessor :current_owner_method, :authentication_method, :default_template, :default_accent, :default_surface, :default_mode, :default_background, :default_text, :account_colors, :current_account_method, :layout
6
+ attr_accessor :current_owner_method, :authentication_method, :default_template, :default_accent, :default_surface, :default_mode, :default_background, :default_text, :account_colors, :current_account_method, :layout, :user_looks, :account_looks
7
7
 
8
8
  def initialize
9
9
  @current_owner_method = :current_user
@@ -17,6 +17,8 @@ module KeystoneUi
17
17
  @account_colors = true
18
18
  @current_account_method = nil
19
19
  @layout = "application"
20
+ @user_looks = true
21
+ @account_looks = true
20
22
  end
21
23
  end
22
24
 
@@ -13,6 +13,12 @@ module KeystoneUi
13
13
  end
14
14
  end
15
15
 
16
+ initializer "keystone_ui.colors.look" do
17
+ KeystoneUi.configure do |config|
18
+ config.look_supplier = ->(view) { view.keystone_look if view.respond_to?(:keystone_look) }
19
+ end
20
+ end
21
+
16
22
  initializer "keystone_ui.colors.tailwind" do
17
23
  KeystoneUi.configuration.tailwind_sources << root.join("app/views/**/*.erb").to_s
18
24
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module KeystoneUi
4
4
  module Colors
5
- VERSION = "0.4.1"
5
+ VERSION = "0.5.0"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: keystone_ui-colors
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyler Schneider
@@ -15,14 +15,14 @@ dependencies:
15
15
  requirements:
16
16
  - - ">="
17
17
  - !ruby/object:Gem::Version
18
- version: 0.15.1
18
+ version: 0.18.0
19
19
  type: :runtime
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
23
  - - ">="
24
24
  - !ruby/object:Gem::Version
25
- version: 0.15.1
25
+ version: 0.18.0
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: railties
28
28
  requirement: !ruby/object:Gem::Requirement
@@ -92,11 +92,14 @@ files:
92
92
  - app/models/keystone_ui/colors/theme_preference.rb
93
93
  - app/views/keystone_ui/colors/settings/_account_picker.html.erb
94
94
  - app/views/keystone_ui/colors/settings/_colours.html.erb
95
+ - app/views/keystone_ui/colors/settings/_looks.html.erb
95
96
  - app/views/keystone_ui/colors/settings/_picker.html.erb
96
97
  - app/views/keystone_ui/colors/settings/show.html.erb
97
98
  - config/routes.rb
98
99
  - lib/generators/keystone_ui/colors/install/install_generator.rb
99
100
  - lib/generators/keystone_ui/colors/install/templates/create_keystone_ui_colors_theme_preferences.rb.erb
101
+ - lib/generators/keystone_ui/colors/update/templates/add_look_to_keystone_ui_colors_theme_preferences.rb.erb
102
+ - lib/generators/keystone_ui/colors/update/templates/add_members_choose_look_to_keystone_ui_colors_theme_preferences.rb.erb
100
103
  - lib/generators/keystone_ui/colors/update/templates/add_members_choose_to_keystone_ui_colors_theme_preferences.rb.erb
101
104
  - lib/generators/keystone_ui/colors/update/templates/add_mode_to_keystone_ui_colors_theme_preferences.rb.erb
102
105
  - lib/generators/keystone_ui/colors/update/templates/add_text_to_keystone_ui_colors_theme_preferences.rb.erb