baldur 0.2.0 → 0.2.3

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.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -1
  3. data/TODO.md +7 -1
  4. data/app/assets/stylesheets/baldur/application/components/auth-page.css +7 -0
  5. data/app/assets/tailwind/baldur/engine.css +2 -2
  6. data/app/helpers/baldur/marketing_helper.rb +71 -69
  7. data/app/helpers/baldur/optional/auth_page_helper.rb +4 -2
  8. data/app/helpers/baldur/optional/google_auth_helper.rb +2 -2
  9. data/app/helpers/baldur/optional/panel_secondary_helper.rb +3 -2
  10. data/app/helpers/baldur/ui_helper.rb +151 -138
  11. data/app/helpers/baldur/ui_helper_feedback.rb +38 -36
  12. data/app/helpers/baldur/ui_helper_forms.rb +81 -76
  13. data/app/helpers/baldur/ui_helper_sidebar.rb +6 -5
  14. data/app/helpers/baldur/ui_helper_unavailable.rb +17 -15
  15. data/app/views/baldur/components/_theme_toggle.html.erb +23 -0
  16. data/app/views/baldur/optional/_auth_page.html.erb +6 -0
  17. data/baldur.gemspec +23 -23
  18. data/config/importmap.rb +2 -2
  19. data/lib/baldur/configuration.rb +6 -6
  20. data/lib/baldur/engine.rb +3 -3
  21. data/lib/baldur/version.rb +1 -1
  22. data/lib/baldur.rb +5 -5
  23. data/lib/generators/baldur/install/install_generator.rb +19 -19
  24. data/lib/generators/baldur/install/templates/baldur_initializer.rb +7 -7
  25. data/lib/generators/baldur/install/templates/theme.css +32 -6
  26. data/lib/generators/baldur/install_google_auth/install_google_auth_generator.rb +2 -2
  27. data/lib/generators/baldur/install_panel_right/install_panel_right_generator.rb +2 -2
  28. data/lib/generators/baldur/install_panel_secondary/install_panel_secondary_generator.rb +3 -3
  29. data/script/verify_host_install +59 -31
  30. data/test/confirmation_modal_helper_test.rb +34 -34
  31. data/test/csp_rendering_test.rb +21 -21
  32. data/test/engine_css_test.rb +36 -0
  33. data/test/fixtures/shared/_brand_lockup.html.erb +1 -0
  34. data/test/gemspec_test.rb +7 -5
  35. data/test/install_generator_test.rb +25 -21
  36. data/test/install_panel_secondary_generator_test.rb +12 -9
  37. data/test/marketing_helper_test.rb +7 -7
  38. data/test/run_all.rb +1 -1
  39. data/test/sidebar_helper_test.rb +16 -16
  40. data/test/test_helper.rb +14 -14
  41. data/test/theme_toggle_helper_test.rb +119 -0
  42. data/test/tmp/install_generator/app/assets/stylesheets/theme.css +32 -6
  43. data/test/tmp/install_generator/config/initializers/baldur.rb +7 -7
  44. metadata +5 -1
@@ -1,21 +1,24 @@
1
- require_relative "test_helper"
2
- require_relative "../lib/generators/baldur/install_panel_secondary/install_panel_secondary_generator"
1
+ require_relative 'test_helper'
2
+ require_relative '../lib/generators/baldur/install_panel_secondary/install_panel_secondary_generator'
3
3
 
4
4
  class BaldurInstallPanelSecondaryGeneratorTest < Rails::Generators::TestCase
5
5
  tests Baldur::Generators::InstallPanelSecondaryGenerator
6
- destination File.expand_path("tmp/install_panel_secondary_generator", __dir__)
6
+ destination File.expand_path('tmp/install_panel_secondary_generator', __dir__)
7
7
  setup :prepare_destination
8
8
 
9
9
  setup do
10
- FileUtils.mkdir_p File.join(destination_root, "app/assets/tailwind")
11
- File.write(File.join(destination_root, "app/assets/tailwind/application.css"), "@import \"tailwindcss\";\n@import \"../builds/tailwind/baldur.css\";\n")
10
+ FileUtils.mkdir_p File.join(destination_root, 'app/assets/tailwind')
11
+ File.write(File.join(destination_root, 'app/assets/tailwind/application.css'),
12
+ "@import \"tailwindcss\";\n@import \"../builds/tailwind/baldur.css\";\n")
12
13
  end
13
14
 
14
- test "adds helper and controller without touching the tailwind contract" do
15
+ test 'adds helper and controller without touching the tailwind contract' do
15
16
  run_generator
16
17
 
17
- assert_file "app/helpers/panel_secondary_helper.rb", /include Baldur::Optional::PanelSecondaryHelper/
18
- assert_file "app/javascript/controllers/panel_secondary_controller.js", /export \{ default \} from "baldur\/controllers\/panel_secondary_controller"/
19
- assert_equal "@import \"tailwindcss\";\n@import \"../builds/tailwind/baldur.css\";\n", File.read(File.join(destination_root, "app/assets/tailwind/application.css"))
18
+ assert_file 'app/helpers/panel_secondary_helper.rb', /include Baldur::Optional::PanelSecondaryHelper/
19
+ assert_file 'app/javascript/controllers/panel_secondary_controller.js',
20
+ %r{export \{ default \} from "baldur/controllers/panel_secondary_controller"}
21
+ assert_equal "@import \"tailwindcss\";\n@import \"../builds/tailwind/baldur.css\";\n",
22
+ File.read(File.join(destination_root, 'app/assets/tailwind/application.css'))
20
23
  end
21
24
  end
@@ -1,4 +1,4 @@
1
- require_relative "test_helper"
1
+ require_relative 'test_helper'
2
2
 
3
3
  class BaldurMarketingHelperTest < Minitest::Test
4
4
  HelperHost = Struct.new(:config) do
@@ -15,17 +15,17 @@ class BaldurMarketingHelperTest < Minitest::Test
15
15
 
16
16
  def test_uses_configured_brand_without_host_helper_fallback
17
17
  Baldur.config.marketing_brand = {
18
- name: "Standalone",
19
- wordmark: "Standalone UI",
20
- logo_src: "/standalone-logo.svg"
18
+ name: 'Standalone',
19
+ wordmark: 'Standalone UI',
20
+ logo_src: '/standalone-logo.svg'
21
21
  }
22
22
 
23
23
  helper = HelperHost.new(Baldur.config)
24
24
  resolved = helper.send(:ui_marketing_configured_brand)
25
25
 
26
- assert_equal "Standalone", resolved[:name]
27
- assert_equal "Standalone UI", resolved[:wordmark]
28
- assert_equal "/standalone-logo.svg", resolved[:logo_src]
26
+ assert_equal 'Standalone', resolved[:name]
27
+ assert_equal 'Standalone UI', resolved[:wordmark]
28
+ assert_equal '/standalone-logo.svg', resolved[:logo_src]
29
29
  end
30
30
 
31
31
  def test_returns_empty_brand_hash_when_no_brand_is_configured
data/test/run_all.rb CHANGED
@@ -1,3 +1,3 @@
1
- Dir[File.expand_path("*_test.rb", __dir__)].sort.each do |path|
1
+ Dir[File.expand_path('*_test.rb', __dir__)].sort.each do |path|
2
2
  require path
3
3
  end
@@ -1,10 +1,10 @@
1
- require_relative "test_helper"
1
+ require_relative 'test_helper'
2
2
 
3
- require "action_controller"
3
+ require 'action_controller'
4
4
 
5
5
  class BaldurSidebarHelperTest < Minitest::Test
6
6
  class TestController < ActionController::Base
7
- append_view_path File.expand_path("../app/views", __dir__)
7
+ append_view_path File.expand_path('../app/views', __dir__)
8
8
  helper Baldur::UiHelper
9
9
  helper Baldur::UiHelperSidebar
10
10
  end
@@ -12,10 +12,10 @@ class BaldurSidebarHelperTest < Minitest::Test
12
12
  def setup
13
13
  @original_brand = Baldur.config.marketing_brand
14
14
  Baldur.config.marketing_brand = {
15
- name: "Acme",
16
- wordmark: "Acme Ops",
17
- logo_src: "/acme.svg",
18
- logo_alt: "Acme logo"
15
+ name: 'Acme',
16
+ wordmark: 'Acme Ops',
17
+ logo_src: '/acme.svg',
18
+ logo_alt: 'Acme logo'
19
19
  }
20
20
  end
21
21
 
@@ -33,16 +33,16 @@ class BaldurSidebarHelperTest < Minitest::Test
33
33
  secondary_label: "Admin"
34
34
  ) %>
35
35
  ERB
36
- formats: [ :html ]
36
+ formats: [:html]
37
37
  )
38
38
 
39
39
  assert_includes html, 'data-controller="sidebar"'
40
40
  assert_includes html, 'data-controller="mobile-sidebar"'
41
- assert_includes html, "Acme Ops"
41
+ assert_includes html, 'Acme Ops'
42
42
  assert_includes html, 'href="/dashboard"'
43
43
  assert_includes html, 'href="/settings"'
44
44
  assert_includes html, 'aria-current="page"'
45
- assert_includes html, "Admin"
45
+ assert_includes html, 'Admin'
46
46
  end
47
47
 
48
48
  def test_sidebar_renders_slot_content_and_mobile_fallbacks
@@ -57,13 +57,13 @@ class BaldurSidebarHelperTest < Minitest::Test
57
57
  <% end %>
58
58
  <% end %>
59
59
  ERB
60
- formats: [ :html ]
60
+ formats: [:html]
61
61
  )
62
62
 
63
- assert_includes html, "Tenant Switcher"
64
- assert_includes html, "user-menu"
65
- assert_includes html, "Sign out"
66
- assert_operator html.scan("Tenant Switcher").size, :>=, 2
67
- assert_operator html.scan("Sign out").size, :>=, 2
63
+ assert_includes html, 'Tenant Switcher'
64
+ assert_includes html, 'user-menu'
65
+ assert_includes html, 'Sign out'
66
+ assert_operator html.scan('Tenant Switcher').size, :>=, 2
67
+ assert_operator html.scan('Sign out').size, :>=, 2
68
68
  end
69
69
  end
data/test/test_helper.rb CHANGED
@@ -1,16 +1,16 @@
1
- ENV["MT_NO_PLUGINS"] = "1"
1
+ ENV['MT_NO_PLUGINS'] = '1'
2
2
 
3
- require "bundler/setup"
4
- require "minitest/autorun"
5
- require "rails/generators/test_case"
6
- require "rails"
7
- require "lucide-rails"
3
+ require 'bundler/setup'
4
+ require 'minitest/autorun'
5
+ require 'rails/generators/test_case'
6
+ require 'rails'
7
+ require 'lucide-rails'
8
8
 
9
- require_relative "../lib/baldur"
10
- require_relative "../app/helpers/baldur/render_helper"
11
- require_relative "../app/helpers/baldur/ui_helper_feedback"
12
- require_relative "../app/helpers/baldur/ui_helper_unavailable"
13
- require_relative "../app/helpers/baldur/ui_helper_forms"
14
- require_relative "../app/helpers/baldur/marketing_helper"
15
- require_relative "../app/helpers/baldur/ui_helper_sidebar"
16
- require_relative "../app/helpers/baldur/ui_helper"
9
+ require_relative '../lib/baldur'
10
+ require_relative '../app/helpers/baldur/render_helper'
11
+ require_relative '../app/helpers/baldur/ui_helper_feedback'
12
+ require_relative '../app/helpers/baldur/ui_helper_unavailable'
13
+ require_relative '../app/helpers/baldur/ui_helper_forms'
14
+ require_relative '../app/helpers/baldur/marketing_helper'
15
+ require_relative '../app/helpers/baldur/ui_helper_sidebar'
16
+ require_relative '../app/helpers/baldur/ui_helper'
@@ -0,0 +1,119 @@
1
+ require_relative 'test_helper'
2
+ require_relative '../app/helpers/baldur/optional/auth_page_helper'
3
+
4
+ require 'action_controller'
5
+
6
+ class BaldurThemeToggleHelperTest < Minitest::Test
7
+ class TestController < ActionController::Base
8
+ append_view_path File.expand_path('../app/views', __dir__)
9
+ helper Baldur::UiHelper
10
+ helper Baldur::RenderHelper
11
+ end
12
+
13
+ def test_ui_theme_toggle_renders_switch_markup
14
+ html = TestController.render(
15
+ inline: '<%= ui_theme_toggle %>',
16
+ formats: [:html]
17
+ )
18
+
19
+ assert_includes html, 'class="switch theme-toggle"'
20
+ assert_includes html, 'data-theme-target="toggle"'
21
+ assert_includes html, 'data-theme-toggle'
22
+ assert_includes html, 'aria-label="Toggle theme"'
23
+ end
24
+
25
+ def test_ui_theme_toggle_renders_compact_button
26
+ html = TestController.render(
27
+ inline: '<%= ui_theme_toggle %>',
28
+ formats: [:html]
29
+ )
30
+
31
+ assert_includes html, 'data-action="click->theme#toggle"'
32
+ assert_includes html, 'theme-toggle__compact'
33
+ end
34
+
35
+ def test_ui_theme_toggle_custom_aria_label
36
+ html = TestController.render(
37
+ inline: '<%= ui_theme_toggle(aria_label: "Switch appearance") %>',
38
+ formats: [:html]
39
+ )
40
+
41
+ assert_includes html, 'aria-label="Switch appearance"'
42
+ refute_includes html, 'aria-label="Toggle theme"'
43
+ end
44
+
45
+ def test_ui_theme_toggle_custom_classes
46
+ html = TestController.render(
47
+ inline: '<%= ui_theme_toggle(classes: "my-extra") %>',
48
+ formats: [:html]
49
+ )
50
+
51
+ assert_includes html, 'my-extra'
52
+ assert_includes html, 'switch theme-toggle'
53
+ end
54
+
55
+ def test_ui_theme_toggle_renders_sun_and_moon_icons
56
+ html = TestController.render(
57
+ inline: '<%= ui_theme_toggle %>',
58
+ formats: [:html]
59
+ )
60
+
61
+ assert_includes html, 'switch__icon--sun'
62
+ assert_includes html, 'switch__icon--moon'
63
+ assert_includes html, 'theme-toggle__compact-icon--sun'
64
+ assert_includes html, 'theme-toggle__compact-icon--moon'
65
+ end
66
+ end
67
+
68
+ class BaldurAuthPageTopRailTest < Minitest::Test
69
+ FIXTURE_VIEWS = File.expand_path('fixtures', __dir__)
70
+
71
+ class TestController < ActionController::Base
72
+ append_view_path File.expand_path('../app/views', __dir__)
73
+ append_view_path FIXTURE_VIEWS
74
+ helper Baldur::UiHelper
75
+ helper Baldur::Optional::AuthPageHelper
76
+ end
77
+
78
+ def test_auth_page_without_top_rail_omits_element
79
+ html = TestController.render(
80
+ inline: <<~ERB,
81
+ <%= ui_auth_page(title: "Sign in", description: nil) do %>
82
+ <p>Form here</p>
83
+ <% end %>
84
+ ERB
85
+ formats: [:html]
86
+ )
87
+
88
+ refute_includes html, 'auth-page__top-rail'
89
+ end
90
+
91
+ def test_auth_page_with_top_rail_renders_slot
92
+ html = TestController.render(
93
+ inline: <<~ERB,
94
+ <%= ui_auth_page(title: "Sign in", description: nil, top_rail: "<span>Version 1.0</span>".html_safe) do %>
95
+ <p>Form here</p>
96
+ <% end %>
97
+ ERB
98
+ formats: [:html]
99
+ )
100
+
101
+ assert_includes html, 'auth-page__top-rail'
102
+ assert_includes html, 'Version 1.0'
103
+ end
104
+
105
+ def test_auth_page_top_rail_with_theme_toggle
106
+ html = TestController.render(
107
+ inline: <<~ERB,
108
+ <%= ui_auth_page(title: "Sign in", description: nil, top_rail: ui_theme_toggle) do %>
109
+ <p>Form here</p>
110
+ <% end %>
111
+ ERB
112
+ formats: [:html]
113
+ )
114
+
115
+ assert_includes html, 'auth-page__top-rail'
116
+ assert_includes html, 'data-theme-target="toggle"'
117
+ assert_includes html, 'data-action="click->theme#toggle"'
118
+ end
119
+ end
@@ -1,12 +1,36 @@
1
1
  /*
2
2
  * Host theme overrides.
3
3
  *
4
- * Override only the base palette inputs below. Baldur remains the source of
5
- * truth for semantic tokens, light/dark role mapping, and component styling.
6
- * Use `fonts.css` to load font files, then map those loaded families to the
7
- * font tokens below.
4
+ * ── Brand inputs ─────────────────────────────────────────
5
+ * Override the four base palette tokens to rebrand. Baldur
6
+ * derives all semantic and role tokens from these inputs;
7
+ * do NOT override the semantic outputs directly.
8
8
  *
9
- * Example:
9
+ * --_primary-base primary actions / CTA
10
+ * --_secondary-base sidebar, nav, subdued surfaces
11
+ * --_accent-base highlights, badges, tags
12
+ * --_neutral-base surfaces, text, borders
13
+ *
14
+ * Values are oklch(). To pick a color, convert to oklch and
15
+ * paste the three channels (L C H) — no parens needed:
16
+ *
17
+ * --_primary-base: oklch(0.68 0.16 27);
18
+ *
19
+ * ── Semantic tokens ──────────────────────────────────────
20
+ * Baldur owns all --color-* semantic tokens (e.g. --color-primary,
21
+ * --color-surface, --color-on-surface). They adapt between
22
+ * light/dark automatically. Do not override them here.
23
+ *
24
+ * ── Font mapping ─────────────────────────────────────────
25
+ * Load web fonts in fonts.css, then map the loaded families
26
+ * to the tokens below. Baldur uses --font-body as the default
27
+ * family for body, heading, and UI text unless overridden.
28
+ *
29
+ * --font-body body copy
30
+ * --font-heading headings (falls back to --font-body)
31
+ * --font-ui buttons, labels, form text (falls back to --font-body)
32
+ *
33
+ * ── Example ──────────────────────────────────────────────
10
34
  * :root {
11
35
  * --_primary-base: oklch(0.68 0.16 27);
12
36
  * --_secondary-base: oklch(0.30 0.04 195);
@@ -15,6 +39,8 @@
15
39
  * --font-body: "Geist", "Inter", "Segoe UI", "Helvetica Neue", Arial, system-ui, -apple-system, sans-serif;
16
40
  * --font-heading: var(--font-body);
17
41
  * --font-ui: var(--font-body);
42
+ * --font-family: var(--font-body);
43
+ * --font-sans: var(--font-body);
18
44
  * }
19
45
  */
20
46
 
@@ -24,4 +50,4 @@
24
50
  --font-ui: var(--font-body);
25
51
  --font-family: var(--font-body);
26
52
  --font-sans: var(--font-body);
27
- }
53
+ }
@@ -1,13 +1,13 @@
1
- require "baldur"
1
+ require 'baldur'
2
2
 
3
3
  Baldur.configure do |config|
4
- config.unavailable_fallback_message = "Missing metric or raw data required to compute this value."
5
- config.theme_storage_key = "baldur.theme"
4
+ config.unavailable_fallback_message = 'Missing metric or raw data required to compute this value.'
5
+ config.theme_storage_key = 'baldur.theme'
6
6
  config.marketing_brand = {
7
- name: "Your Brand",
8
- wordmark: "Your Brand",
9
- logo_src: "/icon.png",
10
- logo_alt: "Your Brand logo"
7
+ name: 'Your Brand',
8
+ wordmark: 'Your Brand',
9
+ logo_src: '/icon.png',
10
+ logo_alt: 'Your Brand logo'
11
11
  }
12
12
 
13
13
  # Supply host-specific lookups when using unavailable dependency helpers.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: baldur
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Varun Murkar
@@ -179,6 +179,7 @@ files:
179
179
  - app/views/baldur/components/_table_card.html.erb
180
180
  - app/views/baldur/components/_table_footer.html.erb
181
181
  - app/views/baldur/components/_text_field.html.erb
182
+ - app/views/baldur/components/_theme_toggle.html.erb
182
183
  - app/views/baldur/components/_tooltip.html.erb
183
184
  - app/views/baldur/marketing/_cta_banner.html.erb
184
185
  - app/views/baldur/marketing/_faq_section.html.erb
@@ -209,6 +210,8 @@ files:
209
210
  - script/verify_host_install
210
211
  - test/confirmation_modal_helper_test.rb
211
212
  - test/csp_rendering_test.rb
213
+ - test/engine_css_test.rb
214
+ - test/fixtures/shared/_brand_lockup.html.erb
212
215
  - test/gemspec_test.rb
213
216
  - test/install_generator_test.rb
214
217
  - test/install_panel_secondary_generator_test.rb
@@ -216,6 +219,7 @@ files:
216
219
  - test/run_all.rb
217
220
  - test/sidebar_helper_test.rb
218
221
  - test/test_helper.rb
222
+ - test/theme_toggle_helper_test.rb
219
223
  - test/tmp/install_generator/app/assets/stylesheets/fonts.css
220
224
  - test/tmp/install_generator/app/assets/stylesheets/theme.css
221
225
  - test/tmp/install_generator/app/assets/tailwind/application.css