swal_rails 0.3.2 → 0.3.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -0
- data/lib/generators/swal_rails/install/templates/initializer.rb +7 -0
- data/lib/swal_rails/configuration.rb +9 -1
- data/lib/swal_rails/engine.rb +7 -0
- data/lib/swal_rails/initializer_version_check.rb +44 -0
- data/lib/swal_rails/version.rb +1 -1
- data/lib/swal_rails.rb +9 -0
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: db0cf6b419c2e989dfcc877d644fc85244f2c85e0fc2e012661b594854d5cdad
|
|
4
|
+
data.tar.gz: f26da33eb89b79b5338eb822281f89d5bc43376ca3a22f39969aaba3c7440f66
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 35d5a3a5d411f39870070332ab2516987d9f6345ca3cf17f3fb6b0958f1ae9680608bb1a355ce2ffad3257cabb3e384fee9533018756c90784a29fc176c456c9
|
|
7
|
+
data.tar.gz: e48305dfd6fdb0bcb3bab2cbafbf4f56a017006e5d2d95cb716ecff61fa15ffd4abea636206c04e7e57f76a15a7d9888bd64cf6f114ce21bf78a346b52b43424
|
data/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [0.3.3] - 2026-04-25
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
- Boot-time initializer drift detection. The gem ships
|
|
13
|
+
`SwalRails::INITIALIZER_VERSION`, the install template stamps
|
|
14
|
+
`config.initializer_version = "<current>"`, and a Rails initializer
|
|
15
|
+
hooked after `:load_config_initializers` logs a one-line warning when
|
|
16
|
+
the user's stamp is missing or trails the gem's expected value. Includes
|
|
17
|
+
the regenerate command in the message:
|
|
18
|
+
`bin/rails g swal_rails:install --skip-layout --force`.
|
|
19
|
+
- `config.silence_initializer_warning` (Boolean, default `false`) opt-out
|
|
20
|
+
for users who don't want to regenerate.
|
|
21
|
+
|
|
9
22
|
## [0.3.2] - 2026-04-25
|
|
10
23
|
|
|
11
24
|
First stable release on top of the `0.3.1.beta1` + `0.3.1.beta2`
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
SwalRails.configure do |config|
|
|
4
|
+
# Stamps this initializer against the template version that shipped with
|
|
5
|
+
# the installed gem. The boot-time check warns if you upgrade the gem to
|
|
6
|
+
# a version with a newer template — regenerate with:
|
|
7
|
+
# bin/rails g swal_rails:install --skip-layout --force
|
|
8
|
+
# Set `config.silence_initializer_warning = true` to silence.
|
|
9
|
+
config.initializer_version = "<%= SwalRails::INITIALIZER_VERSION %>"
|
|
10
|
+
|
|
4
11
|
# How confirmation modals are wired.
|
|
5
12
|
# :off — do nothing, use Swal manually
|
|
6
13
|
# :data_attribute — intercept clicks/submits on [data-swal-confirm] (default, non-intrusive)
|
|
@@ -17,7 +17,9 @@ module SwalRails
|
|
|
17
17
|
:flash_keys_as_meta,
|
|
18
18
|
:respect_reduced_motion,
|
|
19
19
|
:expose_window_swal,
|
|
20
|
-
:flash_stack_delay
|
|
20
|
+
:flash_stack_delay,
|
|
21
|
+
:initializer_version,
|
|
22
|
+
:silence_initializer_warning
|
|
21
23
|
attr_reader :confirm_mode, :flash_map, :i18n_scope, :flash_array_mode
|
|
22
24
|
|
|
23
25
|
def initialize
|
|
@@ -28,6 +30,12 @@ module SwalRails
|
|
|
28
30
|
@flash_array_mode = :sequential
|
|
29
31
|
@flash_stack_delay = 500
|
|
30
32
|
@i18n_scope = "swal_rails"
|
|
33
|
+
# `initializer_version` left nil — apps that haven't regenerated
|
|
34
|
+
# their initializer since `SwalRails::INITIALIZER_VERSION` was
|
|
35
|
+
# introduced (0.3.3) get a one-line warning at boot. Setting it
|
|
36
|
+
# explicitly in the initializer template silences it.
|
|
37
|
+
@initializer_version = nil
|
|
38
|
+
@silence_initializer_warning = false
|
|
31
39
|
# `focusConfirm` / `returnFocus` are intentionally omitted: SA2 already
|
|
32
40
|
# defaults both to `true` internally, and passing them explicitly makes
|
|
33
41
|
# SA2 warn on every toast ("incompatible with toasts"). Listing them
|
data/lib/swal_rails/engine.rb
CHANGED
|
@@ -52,6 +52,13 @@ module SwalRails
|
|
|
52
52
|
initializer "swal_rails.i18n" do
|
|
53
53
|
config.i18n.load_path += Dir[root.join("config/locales/*.yml").to_s]
|
|
54
54
|
end
|
|
55
|
+
|
|
56
|
+
# Run AFTER user initializers so we can read whatever value they set
|
|
57
|
+
# (or didn't set) for `config.initializer_version`. One-shot, idempotent,
|
|
58
|
+
# opt-out via `config.silence_initializer_warning = true`.
|
|
59
|
+
initializer "swal_rails.check_initializer_version", after: :load_config_initializers do
|
|
60
|
+
SwalRails::InitializerVersionCheck.run!
|
|
61
|
+
end
|
|
55
62
|
end
|
|
56
63
|
end
|
|
57
64
|
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module SwalRails
|
|
4
|
+
# Compares the user's `config.initializer_version` against the gem's
|
|
5
|
+
# `SwalRails::INITIALIZER_VERSION` and logs a one-line warning when the
|
|
6
|
+
# initializer is missing the stamp or trails the gem's expected value.
|
|
7
|
+
#
|
|
8
|
+
# Wired into the engine after `:load_config_initializers` so it sees
|
|
9
|
+
# whatever the user set. Silenced via
|
|
10
|
+
# `config.silence_initializer_warning = true`.
|
|
11
|
+
module InitializerVersionCheck
|
|
12
|
+
module_function
|
|
13
|
+
|
|
14
|
+
def run!(logger: default_logger, config: SwalRails.configuration)
|
|
15
|
+
return if config.silence_initializer_warning
|
|
16
|
+
|
|
17
|
+
message = stale_message(config)
|
|
18
|
+
return unless message
|
|
19
|
+
|
|
20
|
+
logger.warn(message)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def stale_message(config)
|
|
24
|
+
user = config.initializer_version
|
|
25
|
+
current = SwalRails::INITIALIZER_VERSION
|
|
26
|
+
|
|
27
|
+
return nil if user == current
|
|
28
|
+
|
|
29
|
+
regen = "Run `bin/rails g swal_rails:install --skip-layout --force` to regenerate, or set " \
|
|
30
|
+
"`config.silence_initializer_warning = true` to silence."
|
|
31
|
+
|
|
32
|
+
if user.nil?
|
|
33
|
+
"[swal_rails] config/initializers/swal_rails.rb predates v#{current} " \
|
|
34
|
+
"(no `config.initializer_version` set). New options may be missing. #{regen}"
|
|
35
|
+
else
|
|
36
|
+
"[swal_rails] initializer template advanced to v#{current} (yours: v#{user}). #{regen}"
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def default_logger
|
|
41
|
+
defined?(Rails) && Rails.respond_to?(:logger) && Rails.logger ? Rails.logger : Logger.new($stderr)
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
data/lib/swal_rails/version.rb
CHANGED
data/lib/swal_rails.rb
CHANGED
|
@@ -5,6 +5,14 @@ require_relative "swal_rails/version"
|
|
|
5
5
|
module SwalRails
|
|
6
6
|
class Error < StandardError; end
|
|
7
7
|
|
|
8
|
+
# The initializer template version this release of the gem ships.
|
|
9
|
+
# Bump only when the template content changes in a way users should
|
|
10
|
+
# know about (new option, removed option, default flip). Compared at
|
|
11
|
+
# boot against `config.initializer_version` to warn about stale
|
|
12
|
+
# config/initializers/swal_rails.rb files. Independent from gem VERSION
|
|
13
|
+
# so non-template-touching releases don't trigger spurious warnings.
|
|
14
|
+
INITIALIZER_VERSION = "0.3.3"
|
|
15
|
+
|
|
8
16
|
class << self
|
|
9
17
|
def configuration
|
|
10
18
|
@configuration ||= Configuration.new
|
|
@@ -21,5 +29,6 @@ module SwalRails
|
|
|
21
29
|
end
|
|
22
30
|
|
|
23
31
|
require_relative "swal_rails/configuration"
|
|
32
|
+
require_relative "swal_rails/initializer_version_check"
|
|
24
33
|
require_relative "swal_rails/helpers"
|
|
25
34
|
require_relative "swal_rails/engine" if defined?(Rails::Engine)
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: swal_rails
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.3.
|
|
4
|
+
version: 0.3.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Florian Gagnaire
|
|
@@ -73,6 +73,7 @@ files:
|
|
|
73
73
|
- lib/swal_rails/configuration.rb
|
|
74
74
|
- lib/swal_rails/engine.rb
|
|
75
75
|
- lib/swal_rails/helpers.rb
|
|
76
|
+
- lib/swal_rails/initializer_version_check.rb
|
|
76
77
|
- lib/swal_rails/version.rb
|
|
77
78
|
- vendor/javascript/sweetalert2/LICENSE
|
|
78
79
|
- vendor/javascript/sweetalert2/sweetalert2.all.js
|