voltron-flash 0.1.2 → 0.1.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/lib/voltron/flash/version.rb +1 -1
- data/lib/voltron/flash.rb +15 -23
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1f706827eaa82fc21f386839dd9b20f280573622
|
4
|
+
data.tar.gz: 6422d9fb168c0ba1e56732f56a80044706e5a8ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 315ef39aaf64f42a72ef8d53612aa6fbdb3e6cbbcc25837d22dd92c0dafea867811acd3ad3584ce96bc12d5335e96238542c83e75521724d1c41405bb6e2dac7
|
7
|
+
data.tar.gz: 841e0719e3ed007b2298d058def944bf50061547e8825ee33c225c5be638200f4cde6da5cf1ac2e9e4b6d9860ff25dd64cca94429179006c993b544f3fdbb618
|
data/lib/voltron/flash.rb
CHANGED
@@ -11,14 +11,22 @@ module Voltron
|
|
11
11
|
|
12
12
|
def render(*args)
|
13
13
|
include_flash_now
|
14
|
-
super
|
14
|
+
super
|
15
|
+
end
|
16
|
+
|
17
|
+
def redirect_to(options={}, response_status={})
|
18
|
+
include_flash_later
|
19
|
+
super
|
15
20
|
end
|
16
21
|
|
17
22
|
def flash!(**flashes)
|
18
23
|
flashes.symbolize_keys.each do |type,messages|
|
19
24
|
stored_flashes[type] ||= []
|
20
|
-
stored_flashes[type]
|
25
|
+
stored_flashes[type] += Array.wrap(messages)
|
21
26
|
end
|
27
|
+
|
28
|
+
# Set the headers initially. If redirecting, they will be removed as the flash will instead be a part of `flash`
|
29
|
+
response.headers[Voltron.config.flash.header] = stored_flashes.to_json
|
22
30
|
end
|
23
31
|
|
24
32
|
private
|
@@ -30,31 +38,15 @@ module Voltron
|
|
30
38
|
# Before rendering, include any flash messages in flash.now,
|
31
39
|
# so they will be available when the page is rendered
|
32
40
|
def include_flash_now
|
33
|
-
|
41
|
+
stored_flashes.each { |type,messages| flash.now[type] = messages }
|
34
42
|
end
|
35
43
|
|
36
|
-
#
|
37
|
-
# in the appropriate outlet, either response headers or `flash` itself
|
44
|
+
# When redirecting, remove the flash from the headers (unless ajax request), append it all to the `flash` object
|
38
45
|
def include_flash_later
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
response.headers[Voltron.config.flash.header] = flash_hash.to_json
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def is_redirecting?
|
47
|
-
self.status == 302 || self.status == 301
|
48
|
-
end
|
49
|
-
|
50
|
-
def flash_hash(rendering=false)
|
51
|
-
flashes = stored_flashes.map do |type,messages|
|
52
|
-
{ type => messages.map do |f|
|
53
|
-
f[:messages] if !(f[:ajax] == false && request.xhr?) || (f[:ajax] == false && request.xhr? && rendering)
|
54
|
-
end.compact.flatten
|
55
|
-
}
|
46
|
+
unless request.xhr?
|
47
|
+
response.headers.except! Voltron.config.flash.header
|
48
|
+
stored_flashes.each { |type,messages| flash[type] = messages }
|
56
49
|
end
|
57
|
-
flashes.reduce(Hash.new, :merge).reject { |k,v| v.blank? || k == :ajax }
|
58
50
|
end
|
59
51
|
|
60
52
|
end
|