unmagic-components 0.4.0 → 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: 9c4fbdc3dbc2a5dbba7758240b2c0fa271c81f46e00435e898ad179f23ce1937
4
- data.tar.gz: 1ce6acc98aecc0153da190eca815d5ca469e6e46c0fe61bdd8b1fc75dd437e10
3
+ metadata.gz: acc506f1f415e9fa5c52d7e54e8790581b0b402e76769f52888c2ab25efa025f
4
+ data.tar.gz: e6fd6a1c65c1945efb5c05320af6a6b76b57bda43a948ac9e6528966ee21a6fe
5
5
  SHA512:
6
- metadata.gz: 2cbcb4011c8504a0247e3a26d49042da521e22ccc658615049e7bdfc7ec9411fa86f984acb2abc9e59a99bc398c245dd03f99de30616f00c2a5ecc49ed688251
7
- data.tar.gz: 6599c73d2d0c5846a8b5206e3df0071b31c8d958f88b3e21dcbdda761c48820c1f2a1854762c99ce09b6f360985be017a10c007be5887c26a5ae5c097ca4807a
6
+ metadata.gz: d72cc016685d0cdf5b0da795badbe6f0ffba6dd603dd2c5ff3b715675e979e2be87ca5efedb26af84b4538b21dbe0e9b476061adbfa88edb6e71628737443b33
7
+ data.tar.gz: 68c74166b2ce4ea52dc5746cf6c63148dfdbdfabff6cdb8b635400651dd5e540f89b7e045da6bcbb36c8c8a1e7742da4cf4ffa2af058bc2521eb677a4975bdef
data/CHANGELOG.md CHANGED
@@ -7,6 +7,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.5.0] - 2026-09-17
11
+
12
+ ### Added
13
+
14
+ - `Unmagic::Components.with_default_configuration { … }` runs a block with the
15
+ built-in seams, whatever the app configured. The override is per thread or
16
+ fiber, so the app's other requests aren't affected.
17
+
18
+ ### Changed
19
+
20
+ - The component browser ignores the host's configuration and renders every
21
+ example through the built-in seams. A host whose `empty_state` or
22
+ `pagination` rendered its own partials had to hand the browser the helpers
23
+ those partials call; now none of the host's code runs inside the browser.
24
+
10
25
  ## [0.4.0] - 2026-09-16
11
26
 
12
27
  ### Added
@@ -257,7 +272,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
257
272
  - Configurable empty-state, pagination and Pagy seams so the gem depends on neither
258
273
  Pagy nor any host helper.
259
274
 
260
- [Unreleased]: https://github.com/unreasonable-magic/unmagic-components/compare/v0.4.0...HEAD
275
+ [Unreleased]: https://github.com/unreasonable-magic/unmagic-components/compare/v0.5.0...HEAD
276
+ [0.5.0]: https://github.com/unreasonable-magic/unmagic-components/compare/v0.4.0...v0.5.0
261
277
  [0.4.0]: https://github.com/unreasonable-magic/unmagic-components/compare/v0.3.0...v0.4.0
262
278
  [0.3.0]: https://github.com/unreasonable-magic/unmagic-components/compare/v0.2.0...v0.3.0
263
279
  [0.2.0]: https://github.com/unreasonable-magic/unmagic-components/compare/v0.1.0...v0.2.0
data/README.md CHANGED
@@ -99,9 +99,9 @@ mount Unmagic::Components::Browser::Engine => "/unmagic/components" if Rails.env
99
99
 
100
100
  It brings its own stylesheet, prebuilt with Tailwind's default theme, and loads
101
101
  the components' JavaScript and Turbo itself, so nothing in your CSS or JS
102
- changes. It needs `turbo-rails` in your bundle. It renders through your
103
- configuration, so a `control_class` pointed at your own classes leaves its form
104
- examples unstyled.
102
+ changes. It needs `turbo-rails` in your bundle. It shows the components as the
103
+ gem draws them: your configuration doesn't apply inside it, so an `empty_state`
104
+ that renders your own partial runs only in your app.
105
105
 
106
106
  Its controllers inherit `ActionController::Base`, so your authentication doesn't
107
107
  cover it. Its demo endpoints only write to the visitor's session, but mount it
@@ -24,6 +24,12 @@ module Unmagic
24
24
 
25
25
  before_action :require_turbo, :remember_theme, :load_catalog
26
26
 
27
+ # The browser shows the gem's own components, not the host's take on them:
28
+ # its stylesheet has only the gem's classes, and a host's empty_state or
29
+ # pagination would render the host's partials, which call helpers this
30
+ # controller doesn't have.
31
+ around_action :with_default_configuration
32
+
27
33
  private
28
34
 
29
35
  # Checked per request rather than at load, because a host that eager loads
@@ -42,6 +48,8 @@ module Unmagic
42
48
 
43
49
  def dark_theme? = browser_session[:theme] == "dark"
44
50
 
51
+ def with_default_configuration(&) = Unmagic::Components.with_default_configuration(&)
52
+
45
53
  def load_catalog
46
54
  Catalog.reload! if Rails.env.development?
47
55
  @components = Catalog.all
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Unmagic
4
4
  module Components
5
- VERSION = "0.4.0"
5
+ VERSION = "0.5.0"
6
6
  end
7
7
  end
@@ -5,6 +5,7 @@ require "active_support/core_ext/object/try"
5
5
  require "active_support/core_ext/hash/except"
6
6
  require "active_support/core_ext/module/delegation"
7
7
  require "active_support/core_ext/string/output_safety"
8
+ require "active_support/isolated_execution_state"
8
9
 
9
10
  require_relative "components/version"
10
11
  require_relative "components/configuration"
@@ -76,18 +77,38 @@ module Unmagic
76
77
  module Components
77
78
  class << self
78
79
  def configure
79
- yield(configuration) if block_given?
80
- configuration
80
+ yield(app_configuration) if block_given?
81
+ app_configuration
81
82
  end
82
83
 
84
+ # The app's configuration, unless the current request or job is inside
85
+ # with_default_configuration.
83
86
  def configuration
84
- @configuration ||= Configuration.new
87
+ ActiveSupport::IsolatedExecutionState[:unmagic_components_configuration] || app_configuration
88
+ end
89
+
90
+ # Runs the block with the built-in seams, whatever the app configured. The
91
+ # browser renders through this, so none of a host's code (its partials, and
92
+ # the helpers they call) runs inside it. The override is per thread or fiber,
93
+ # so the app's own requests running alongside keep the app's configuration.
94
+ def with_default_configuration
95
+ previous = ActiveSupport::IsolatedExecutionState[:unmagic_components_configuration]
96
+ ActiveSupport::IsolatedExecutionState[:unmagic_components_configuration] = Configuration.new
97
+ yield
98
+ ensure
99
+ ActiveSupport::IsolatedExecutionState[:unmagic_components_configuration] = previous
85
100
  end
86
101
 
87
102
  # Drops every customisation, restoring the built-in seams. Intended for
88
103
  # tests; an app configures once at boot.
89
104
  def reset_configuration!
90
- @configuration = nil
105
+ @app_configuration = nil
106
+ end
107
+
108
+ private
109
+
110
+ def app_configuration
111
+ @app_configuration ||= Configuration.new
91
112
  end
92
113
  end
93
114
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unmagic-components
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Keith Pitt