flash_unified 0.3.1 → 0.4.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: 0717ebeb4edd16afaa95ed6bbb292021c21cf1a2fef5c4e563ccb3beb54d8665
4
- data.tar.gz: 2a43740750aedf357dbf589f0c2066b89b9a93d3cbef791adfdf2eb0e7a5f4fa
3
+ metadata.gz: ab78476991976297386a29f8497c4a6cdfa3653de8ee8cb5d1ab66c9b0d6f552
4
+ data.tar.gz: f1033c6796f66de87d6c4d274a71e0d107ff4010584b09ca691e7ec7bcb987f5
5
5
  SHA512:
6
- metadata.gz: ccdfc4a4061e885e80cd9a25aaf6e68a4f0afe82b7fbbafec1cf9525bdda8b870a2ab3d8368e75da545bfb408b0109100f2b83378d220864ef5e63cb5cf54be4
7
- data.tar.gz: a2e898fa7af7a45a71715d8c2a9864c33d371d5575d357150e127c9bc19f82cd4a6050a8f80283f01b5d2549854278a69a9372ab3fd374849615b0b1c57e17c5
6
+ metadata.gz: f1e25694b830f1ab50023cc811a7e24a898c6a6f15e5b4acbde4eb19f19e0a2c77e35f3ccdb2c8ca360bfcc91dc5865eae0e69aea9e130509a699f8d8be29c6c
7
+ data.tar.gz: b29cdfe43b56d2baf9d073a48bcd4453dc63b2b8aa69f3cc6cbe4b42c8638ec0d320cc56a9f83a897aeb480b53393e0ab56ecaf91aef990015400e8da220fbd6
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  FlashUnified provides a unified Flash message rendering mechanism for Rails applications that can be used from both server-side and client-side code.
4
4
 
5
- Server-side view helpers embed Flash messages as data in the page, and a lightweight client-side JavaScript library reads those storages and renders messages into visible containers using templates.
5
+ Server-side view helpers embed Flash messages as data in the page, and a lightweight client-side JavaScript library reads those storage elements and renders messages into visible containers using templates.
6
6
 
7
7
  ## Current status
8
8
 
@@ -23,7 +23,7 @@ The key point to solving these challenges is that rendering needs to be performe
23
23
  1. The server embeds the Flash object as a hidden DOM element within the page, renders the page, and returns it.
24
24
  2. When the client-side JavaScript detects a page change, it scans those elements, reads the embedded messages, formats them using templates, and inserts (renders) them into the specified container elements. At that time, message elements are removed from the DOM to avoid duplicate displays.
25
25
 
26
- The mechanism is simple, and to implement it, we only need to decide on the rules for how to embed. In this gem, we define the embedded DOM structure as follows and call it "storage":
26
+ The mechanism is simple; to implement it, we only need to define the rules for embedding. In this gem, we define the embedded DOM structure below and refer to it as a "storage element":
27
27
  ```erb
28
28
  <div data-flash-storage style="display: none;">
29
29
  <ul>
@@ -34,9 +34,9 @@ The mechanism is simple, and to implement it, we only need to decide on the rule
34
34
  </div>
35
35
  ```
36
36
 
37
- Since storage is a hidden element, it can be placed anywhere in the page rendered by the server. For Turbo Frames, place it inside the frame.
37
+ Since a storage element is hidden, it can be placed anywhere in the page rendered by the server. For Turbo Frames, place a storage element inside the frame.
38
38
 
39
- The "container" where Flash messages are displayed and the "templates" for formatting can be placed anywhere regardless of the storage. This means that even with Turbo Frames, it works with Flash rendering areas placed outside the frame.
39
+ The "container" where Flash messages are displayed and the "templates" for formatting can be placed anywhere, regardless of the storage element. This means that even with Turbo Frames, it works with Flash rendering areas placed outside the frame.
40
40
 
41
41
  When handling cases on the client-side where a proxy returns an error when a form is submitted, instead of displaying the error message directly from JavaScript, you can render Flash in the same way (using the same templates and processing flow) by temporarily embedding the message as a storage element.
42
42
 
@@ -87,29 +87,52 @@ import "flash_unified/all";
87
87
 
88
88
  ### 3. Server-side setup
89
89
 
90
- Place the "sources" with the helper right after `<body>` in your layout:
90
+ Place the "sources" helper right after `<body>` in your layout. This emits hidden elements and therefore does not affect your layout:
91
91
  ```erb
92
92
  <body>
93
93
  <%= flash_unified_sources %>
94
94
  ...
95
95
  ```
96
96
 
97
- Place the "container" with the helper at the location where you want to display messages:
97
+ Place the "container" helper at the location where you want to display messages:
98
98
  ```erb
99
99
  <div class="notify">
100
100
  <%= flash_container %>
101
101
  ...
102
102
  ```
103
103
 
104
- That's it event handlers that monitor page changes will scan storages and render messages into containers.
104
+ When using Turbo, you need to place storage elements (hidden elements) within the content that updates.
105
105
 
106
- As mentioned earlier, no changes are required in your controllers for setting Flash messages.
106
+ **Turbo Frame**
107
107
 
108
- **For detailed usage** (customization, API reference, Turbo/network helpers, templates, locales, generator usage, and examples), see [`ADVANCED.md`](ADVANCED.md). Examples for using asset pipelines like Sprockets are also provided.
108
+ Place a storage element inside the frame:
109
+ ```erb
110
+ <turbo-frame id="foo">
111
+ <%= flash_storage %>
112
+ ```
113
+
114
+ **Turbo Stream**
115
+
116
+ Add a stream to append a storage element to the global storage:
117
+ ```erb
118
+ <%= flash_turbo_stream %>
119
+ ```
120
+
121
+
122
+ Or in a controller:
123
+ ```ruby
124
+ render turbo_stream: helpers.flash_turbo_stream
125
+ ```
126
+
127
+ That's it. Event handlers that monitor page changes will scan storage elements and render messages into containers.
128
+
129
+ ## Detailed usage
130
+
131
+ For customization options, API references, Turbo/network helpers, templates, locales, generators, and more, see [`ADVANCED.md`](ADVANCED.md). Examples for using asset pipelines like Sprockets are also provided.
109
132
 
110
133
  ## Development
111
134
 
112
- For detailed development and testing procedures, see [DEVELOPMENT.md](DEVELOPMENT.md).
135
+ For detailed development and testing procedures, see [`DEVELOPMENT.md`](DEVELOPMENT.md).
113
136
 
114
137
  ## Changelog
115
138
 
@@ -28,6 +28,19 @@ module FlashUnified
28
28
  render partial: "flash_unified/general_error_messages"
29
29
  end
30
30
 
31
+ # Turbo Stream helper that appends flash storage to the global storage element.
32
+ # This is a convenience helper for the common pattern of appending flash messages
33
+ # via Turbo Stream to the global flash-storage container.
34
+ #
35
+ # Usage in views:
36
+ # <%= flash_turbo_stream %>
37
+ #
38
+ # Usage in controllers:
39
+ # render turbo_stream: helpers.flash_turbo_stream
40
+ def flash_turbo_stream
41
+ turbo_stream.append("flash-storage", partial: "flash_unified/storage")
42
+ end
43
+
31
44
  # Wrapper helper that renders the common flash-unified pieces in a single
32
45
  # call. This is a non-destructive convenience helper which calls the
33
46
  # existing partial-rendering helpers in a sensible default order. Pass a
@@ -1,3 +1,3 @@
1
1
  module FlashUnified
2
- VERSION = "0.3.1"
2
+ VERSION = "0.4.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flash_unified
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - hiroaki
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-10-30 00:00:00.000000000 Z
11
+ date: 2025-11-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails