voltron-flash 0.1.1 → 0.1.2
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
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0d659cb376f6d21612a62b40803e6abc7eaa21d6
|
4
|
+
data.tar.gz: f57c9abb3a446e306b8831d93d15fe54d80a9d01
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8a00c035cf0b05afe2429df810205743912893d281aa4f2ad0514b2b321048d16063e159de4c045034a13c6dcf085af553afaa0e0e82fbd83c1593f00a5965a2
|
7
|
+
data.tar.gz: 67c166c9edf0aa815e6503cfe9b3a4579cf7896a18d1b8f953760217dbecfe81f2b534c03b979229877f40aa1a71f4c0f4781a764010a0b1bf244cf15bda54b7
|
@@ -1,6 +1,8 @@
|
|
1
1
|
//= require voltron
|
2
2
|
|
3
3
|
Voltron.addModule('Flash', function(){
|
4
|
+
var _initialized = false;
|
5
|
+
|
4
6
|
var _defaults = {
|
5
7
|
class: '',
|
6
8
|
bind: 'body',
|
@@ -18,9 +20,12 @@ Voltron.addModule('Flash', function(){
|
|
18
20
|
|
19
21
|
return {
|
20
22
|
initialize: function(){
|
21
|
-
|
22
|
-
|
23
|
-
|
23
|
+
if(!_initialized){
|
24
|
+
_initialized = true;
|
25
|
+
Voltron('Dispatch/addEventWatcher', 'click');
|
26
|
+
this.on('click:close-alert', 'click:close-notice', 'click:close-warning', this.clear);
|
27
|
+
this.addListener();
|
28
|
+
}
|
24
29
|
},
|
25
30
|
|
26
31
|
setConfig: function(options){
|
@@ -1,16 +1,13 @@
|
|
1
1
|
<% if flash.count > 0 %>
|
2
2
|
<div id="flashes" class="<%= container_class %>">
|
3
3
|
<% if Voltron.config.flash.group %>
|
4
|
-
|
5
4
|
<% flash.each do |type,messages| %>
|
6
5
|
<div class="flash <%= type %>">
|
7
6
|
<p class="flash-message"><%= Array.wrap(messages).join("<br />").html_safe %></p>
|
8
7
|
<button class="flash-close" type="button" id="close-<%= type %>" data-dispatch="click"></button>
|
9
8
|
</div>
|
10
9
|
<% end %>
|
11
|
-
|
12
10
|
<% else %>
|
13
|
-
|
14
11
|
<% flash.each do |type,messages| %>
|
15
12
|
<% Array.wrap(messages).each do |message| %>
|
16
13
|
<div class="flash <%= type %>">
|
@@ -19,7 +16,6 @@
|
|
19
16
|
</div>
|
20
17
|
<% end %>
|
21
18
|
<% end %>
|
22
|
-
|
23
19
|
<% end %>
|
24
20
|
</div>
|
25
21
|
<% end %>
|
@@ -1,16 +1,13 @@
|
|
1
1
|
<% if flash.count > 0 %>
|
2
2
|
<div id="flashes" class="<%= container_class %>">
|
3
3
|
<% if Voltron.config.flash.group %>
|
4
|
-
|
5
4
|
<% flash.each do |type,messages| %>
|
6
5
|
<div class="flash <%= type %>">
|
7
6
|
<p class="flash-message"><%= Array.wrap(messages).join("<br />").html_safe %></p>
|
8
7
|
<button class="flash-close" type="button" id="close-<%= type %>" data-dispatch="click"></button>
|
9
8
|
</div>
|
10
9
|
<% end %>
|
11
|
-
|
12
10
|
<% else %>
|
13
|
-
|
14
11
|
<% flash.each do |type,messages| %>
|
15
12
|
<% Array.wrap(messages).each do |message| %>
|
16
13
|
<div class="flash <%= type %>">
|
@@ -19,7 +16,6 @@
|
|
19
16
|
</div>
|
20
17
|
<% end %>
|
21
18
|
<% end %>
|
22
|
-
|
23
19
|
<% end %>
|
24
20
|
</div>
|
25
21
|
<% end %>
|
data/lib/voltron/flash.rb
CHANGED
@@ -17,7 +17,7 @@ module Voltron
|
|
17
17
|
def flash!(**flashes)
|
18
18
|
flashes.symbolize_keys.each do |type,messages|
|
19
19
|
stored_flashes[type] ||= []
|
20
|
-
stored_flashes[type]
|
20
|
+
stored_flashes[type] << { ajax: flashes.delete(:ajax), messages: Array.wrap(messages) }
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
@@ -30,18 +30,16 @@ module Voltron
|
|
30
30
|
# Before rendering, include any flash messages in flash.now,
|
31
31
|
# so they will be available when the page is rendered
|
32
32
|
def include_flash_now
|
33
|
-
|
34
|
-
stored_flashes.each { |type,messages| flash.now[type] = messages }
|
35
|
-
end
|
33
|
+
flash_hash(true).each { |type,messages| flash.now[type] = messages }
|
36
34
|
end
|
37
35
|
|
38
36
|
# If request is an ajax request, or we are redirecting, include flash messages
|
39
37
|
# in the appropriate outlet, either response headers or `flash` itself
|
40
38
|
def include_flash_later
|
41
|
-
if
|
42
|
-
|
43
|
-
elsif
|
44
|
-
|
39
|
+
if is_redirecting?
|
40
|
+
flash_hash.each { |type,messages| flash[type] = messages }
|
41
|
+
elsif request.xhr?
|
42
|
+
response.headers[Voltron.config.flash.header] = flash_hash.to_json
|
45
43
|
end
|
46
44
|
end
|
47
45
|
|
@@ -49,6 +47,16 @@ module Voltron
|
|
49
47
|
self.status == 302 || self.status == 301
|
50
48
|
end
|
51
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
|
+
}
|
56
|
+
end
|
57
|
+
flashes.reduce(Hash.new, :merge).reject { |k,v| v.blank? || k == :ajax }
|
58
|
+
end
|
59
|
+
|
52
60
|
end
|
53
61
|
end
|
54
62
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: voltron-flash
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Hainer
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-02-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -215,7 +215,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
215
215
|
version: '0'
|
216
216
|
requirements: []
|
217
217
|
rubyforge_project:
|
218
|
-
rubygems_version: 2.
|
218
|
+
rubygems_version: 2.6.6
|
219
219
|
signing_key:
|
220
220
|
specification_version: 4
|
221
221
|
summary: Voltron library to more easily deal with flash messages
|