swal_rails 0.5.3 → 0.5.4
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 +4 -4
- data/CHANGELOG.md +24 -0
- data/README.md +5 -2
- data/lib/generators/swal_rails/install/templates/initializer.rb +3 -1
- data/lib/swal_rails/helpers.rb +10 -2
- data/lib/swal_rails/version.rb +1 -1
- data/npm/package.json +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ce37abdde2118615b9dfd19d6b842f4746b72f3114b768836e1bd9505aa6deb4
|
|
4
|
+
data.tar.gz: e4005e48265167c93acb12966c8c90dd3adc066f3bad03746a891379edeb1327
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6e464440f41eb284dbde8ebd70f093030fe46bc01edf03489d6a6b2bc9efa35e6ce98e1e6e85c7272061e3bba225de6668753ac4141025dd1b412ebb9293090b
|
|
7
|
+
data.tar.gz: 4d65e1922c6eae44d2213a75c3074e965b5d52aa51f1c9198e3da29ebf4c8e2761c34aea1f54b5d11390a73f7cf9e66a5252cc922111101b22f6ce8ca01d7005
|
data/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,30 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [0.5.4] - 2026-07-15
|
|
10
|
+
|
|
11
|
+
### Fixed
|
|
12
|
+
- **Toast parasite `true` sur un flash non-message** — `build_flash_payload` ne
|
|
13
|
+
filtrait que sur `blank?`, or `true.blank?` est `false` : un flash booléen
|
|
14
|
+
passait le filtre et devenait `{ text: "true" }` via `to_s`. Devise
|
|
15
|
+
`:timeoutable` pose `flash[:timedout] = true` à côté du vrai `:alert` à
|
|
16
|
+
l'expiration de session, d'où un toast bleu affichant littéralement `true` sur
|
|
17
|
+
la page de login. La clé n'étant pas dans `flash_map`, le runtime JS y
|
|
18
|
+
appliquait en plus son fallback (`icon: info`, `position: top-end`) — mais la
|
|
19
|
+
chaîne était fabriquée côté serveur. Les valeurs qui ne sont ni `String` ni
|
|
20
|
+
`Hash` sont désormais ignorées : un flag technique n'est pas un message. Même
|
|
21
|
+
garde dans `swal_flash`, où une valeur non rendable devient un no-op plutôt
|
|
22
|
+
qu'un toast absurde. Aucune app n'était fautive — le bug touchait toute
|
|
23
|
+
combinaison Devise + `swal_rails`.
|
|
24
|
+
Closes [#36](https://github.com/Metalzoid/swal_rails/issues/36).
|
|
25
|
+
- **Doc : `flash_map[:key] = nil` ne silence pas une clé** — l'initializer généré
|
|
26
|
+
affirmait « Set a key to nil to silence it ». C'est faux : `nil` sérialise en
|
|
27
|
+
`null`, le runtime résout le spec via une chaîne `||` et retombe donc sur son
|
|
28
|
+
fallback (`icon: info`, `position: top-end`, 3s) — la clé s'affiche, en pire.
|
|
29
|
+
`flash_map` choisit *comment* un message est rendu, jamais *s'il* est rendu.
|
|
30
|
+
Commentaire du template corrigé et fallback documenté dans le README ; le
|
|
31
|
+
comportement du code est inchangé.
|
|
32
|
+
|
|
9
33
|
## [0.5.3] - 2026-07-15
|
|
10
34
|
|
|
11
35
|
### Changed
|
data/README.md
CHANGED
|
@@ -582,6 +582,8 @@ SwalRails.reset_configuration! # resets to defaults (test fixture he
|
|
|
582
582
|
> 💡 **Prefer a modal for errors?** Override in your initializer:
|
|
583
583
|
> `config.flash_map[:alert] = { icon: "error", toast: false }`.
|
|
584
584
|
|
|
585
|
+
A flash key that is absent from the map — or explicitly set to `nil` — is **not** silenced: the runtime falls back to a generic info toast (`icon: "info"`, `toast: true`, `position: "top-end"`, `timer: 3000`). `flash_map` selects *how* a message renders, never *whether* it renders. What a key is never asked to render is a non-`String`/`Hash` value — see [Flash value shapes](#flash-value-shapes).
|
|
586
|
+
|
|
585
587
|
#### `to_client_payload` (internal, read-only)
|
|
586
588
|
|
|
587
589
|
Serialization contract consumed by the JS runtime via the
|
|
@@ -756,7 +758,7 @@ Returns `true` iff a complete path through the chain was confirmed. `steps` may
|
|
|
756
758
|
| `swal-config` | `to_client_payload` JSON | Runtime boot — mixin, confirm handler, flash handler. Once per page. |
|
|
757
759
|
| `swal-flash` | Array of `{ key, options }` | Flash runtime — re-read on every `turbo:load`. |
|
|
758
760
|
|
|
759
|
-
Flash entries are `{ key: "notice", options: { text: "..." } }` for string values, or `{ key: "notice", options: {...user hash...} }` for Hash values. Arrays in `flash[key]` are expanded into one entry per element.
|
|
761
|
+
Flash entries are `{ key: "notice", options: { text: "..." } }` for string values, or `{ key: "notice", options: {...user hash...} }` for Hash values. Arrays in `flash[key]` are expanded into one entry per element. Values of any other type are omitted from the payload entirely — see [Flash value shapes](#flash-value-shapes).
|
|
760
762
|
|
|
761
763
|
---
|
|
762
764
|
|
|
@@ -795,8 +797,9 @@ No flags. Copies `config/locales/swal_rails.en.yml` and `swal_rails.fr.yml` from
|
|
|
795
797
|
| ---------- | ----------- |
|
|
796
798
|
| `String` | `{ text: value }` — safe by default (SA2 renders via `text:`, no HTML injection). |
|
|
797
799
|
| `Hash` | Full SA2 options, **shadows** `flash_map[key]`. Any SA2 key is accepted (icon, timer, input, html, iconHtml, …). |
|
|
798
|
-
| `Array` | Expanded into one entry per element. Strings become `{ text: elem }`, Hashes pass through verbatim. |
|
|
800
|
+
| `Array` | Expanded into one entry per element. Strings become `{ text: elem }`, Hashes pass through verbatim. Non-renderable elements are dropped individually. |
|
|
799
801
|
| `nil` / `""` / `blank?` | Skipped. |
|
|
802
|
+
| Anything else (`true`, `Symbol`, `Integer`, arbitrary objects) | Skipped — a technical flag is not a message. Covers Devise `:timeoutable`, which writes `flash[:timedout] = true` next to the real `:alert`. |
|
|
800
803
|
|
|
801
804
|
Key normalization: Hash keys are `symbolize_keys`-ed before serialization, so `flash[:notice] = { "text" => "..." }` and `flash[:notice] = { text: "..." }` are equivalent.
|
|
802
805
|
|
|
@@ -32,7 +32,9 @@ SwalRails.configure do |config|
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
# Map Rails flash keys to SweetAlert2 options.
|
|
35
|
-
#
|
|
35
|
+
# Customize icon/toast/position/timer per key. A key that is absent from the
|
|
36
|
+
# map — or set to nil — is not silenced: it falls back to a generic info toast
|
|
37
|
+
# (top-end, 3s). Only String/Hash flash values are rendered at all.
|
|
36
38
|
config.flash_map[:notice] = { icon: "success", toast: true, position: "top-end", timer: 3000, timerProgressBar: true, showConfirmButton: false }
|
|
37
39
|
config.flash_map[:success] = { icon: "success", toast: true, position: "top-end", timer: 3000, timerProgressBar: true, showConfirmButton: false }
|
|
38
40
|
config.flash_map[:alert] = { icon: "error", toast: true, position: "top-end", timer: 4000, timerProgressBar: true, showConfirmButton: false }
|
data/lib/swal_rails/helpers.rb
CHANGED
|
@@ -33,12 +33,17 @@ module SwalRails
|
|
|
33
33
|
# Also accepts per-request option overrides:
|
|
34
34
|
# flash[:notice] = "Saved" # string shortcut
|
|
35
35
|
# flash[:notice] = { text: "Saved", icon: "star", timer: 5000 } # full SA2 options
|
|
36
|
+
#
|
|
37
|
+
# Values that are neither String nor Hash are technical flags, not messages —
|
|
38
|
+
# Devise `:timeoutable` writes `flash[:timedout] = true` — so they are skipped
|
|
39
|
+
# rather than stringified into a toast reading "true".
|
|
36
40
|
def build_flash_payload
|
|
37
41
|
flash.to_h.flat_map do |key, message|
|
|
38
42
|
flash_messages(message).filter_map do |m|
|
|
39
43
|
next if m.blank?
|
|
44
|
+
next unless m.is_a?(String) || m.is_a?(Hash)
|
|
40
45
|
|
|
41
|
-
options = m.is_a?(Hash) ? m.symbolize_keys : { text: m
|
|
46
|
+
options = m.is_a?(Hash) ? m.symbolize_keys : { text: m }
|
|
42
47
|
{ key: key.to_s, options: options }
|
|
43
48
|
end
|
|
44
49
|
end
|
|
@@ -80,12 +85,15 @@ module SwalRails
|
|
|
80
85
|
meta
|
|
81
86
|
end
|
|
82
87
|
|
|
88
|
+
# Same String/Hash gate as build_flash_payload — a non-message value is
|
|
89
|
+
# dropped, and an all-dropped list leaves the flash key unwritten.
|
|
83
90
|
def build_swal_flash_entries(messages, meta, options)
|
|
84
91
|
list = messages.is_a?(Array) ? messages : [messages]
|
|
85
92
|
list.filter_map do |m|
|
|
86
93
|
next if m.blank?
|
|
94
|
+
next unless m.is_a?(String) || m.is_a?(Hash)
|
|
87
95
|
|
|
88
|
-
base = m.is_a?(Hash) ? m.symbolize_keys : { text: m
|
|
96
|
+
base = m.is_a?(Hash) ? m.symbolize_keys : { text: m }
|
|
89
97
|
base.merge(options).merge(meta)
|
|
90
98
|
end
|
|
91
99
|
end
|
data/lib/swal_rails/version.rb
CHANGED
data/npm/package.json
CHANGED