show_message 1.1.6 → 2.0.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 +4 -4
- data/CHANGELOG.md +10 -0
- data/README.md +24 -12
- data/app/views/show_message/_show_message.html.erb +1 -4
- data/lib/show_message.rb +21 -8
- data/lib/show_message/railtie.rb +14 -4
- data/lib/show_message/version.rb +1 -1
- data/lib/show_message/view_helpers.rb +38 -21
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3bde680317f76e6b572431af8bc42180fb248c330c3201d48863373d9ef7f8a4
|
4
|
+
data.tar.gz: 5d530062072d13f3715b48fe087703068528c20ac8b0b639fd2a1490b03b9e9a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b67ece0552015d2f38d9620650fe9e8def7d4b1c4914961e7970a2a204ea87f92ece5bca21924d951693c317296315bdaa8a6b1c7b43e805b24d8b775bad8204
|
7
|
+
data.tar.gz: 210c6ffe6828604f4fc51c5ea4a8e53f5cc920ea83f613760b63c65ab5040c3b36f51f7d2b66af45cec8cfbd3733315dae5832cc634286988adbeec86e5a4eb0
|
data/CHANGELOG.md
ADDED
data/README.md
CHANGED
@@ -26,16 +26,20 @@ See further down for the HTML this outputs so you know how to style it.
|
|
26
26
|
<%= show_message %>
|
27
27
|
```
|
28
28
|
|
29
|
-
Now, set a message in your controller. You can use :
|
30
|
-
|
29
|
+
Now, set a message in your controller. You can use :success, :error, :warning,
|
30
|
+
:info, :notice or :alert.
|
31
31
|
|
32
|
-
Also,
|
32
|
+
Also, you can set a single message as a String or multiple as an Array
|
33
33
|
|
34
34
|
```ruby
|
35
35
|
class MyController
|
36
36
|
|
37
37
|
def test_function
|
38
|
-
|
38
|
+
# short versions
|
39
|
+
show_success('Some Success Message')
|
40
|
+
show_error('Some Error Message')
|
41
|
+
|
42
|
+
show_message :success, 'Some Success Message'
|
39
43
|
end
|
40
44
|
|
41
45
|
end
|
@@ -45,7 +49,7 @@ Now, when using remote forms I came across the issue where I would have multiple
|
|
45
49
|
This led to some issues so I added the ability to set an id on show_message
|
46
50
|
|
47
51
|
```erb
|
48
|
-
<%= show_message(
|
52
|
+
<%= show_message(:create) %>
|
49
53
|
```
|
50
54
|
|
51
55
|
There is a slight twist to setting the flash now. I use an "_" to find what I call "scoped" messages.
|
@@ -54,26 +58,34 @@ There is a slight twist to setting the flash now. I use an "_" to find what I ca
|
|
54
58
|
class MyController
|
55
59
|
|
56
60
|
def test_function
|
57
|
-
|
61
|
+
# short version
|
62
|
+
show_success_for(:create, 'Some Success Message')
|
63
|
+
show_error_for(:create, 'Some Error Message')
|
64
|
+
|
65
|
+
show_message :success, 'Some Success Message', id: :create
|
58
66
|
end
|
59
67
|
|
60
68
|
end
|
61
69
|
```
|
62
70
|
|
63
|
-
|
71
|
+
## Additional Options
|
72
|
+
|
73
|
+
Currently supported options only include `class` which allows you to specify
|
74
|
+
additional classes to be appended to the outermost div's classlist.
|
64
75
|
|
65
76
|
```erb
|
66
|
-
<%= show_message(
|
67
|
-
|
77
|
+
<%= show_message(class: 'my-special-class my-second-special-class') %>
|
78
|
+
<%= show_message(:create, class: 'my-special-class my-second-special-class') %>
|
68
79
|
```
|
69
80
|
|
70
81
|
## show_message - HTML Output
|
71
82
|
|
72
|
-
Below is HTML that show_message will output. You will need to create a few
|
73
|
-
|
83
|
+
Below is HTML that show_message will output. You will need to create a few
|
84
|
+
styles to make yours look nice. The type of message (success, error, etc) will
|
85
|
+
be appended to the outermost div's classlist.
|
74
86
|
|
75
87
|
```html
|
76
|
-
<div class="alert-box [
|
88
|
+
<div class="alert-box [success, info, error...]">
|
77
89
|
<div class="message">
|
78
90
|
Message gets outputed here.
|
79
91
|
</div>
|
@@ -1,10 +1,7 @@
|
|
1
1
|
<% data.each do |m| %>
|
2
|
-
<div class="alert-box <%= m[:class] %> <%= options[:
|
2
|
+
<div class="alert-box <%= m[:class] %> <%= options[:class] %>">
|
3
3
|
<div class="message">
|
4
4
|
<%= raw m[:message] %>
|
5
5
|
</div>
|
6
6
|
</div>
|
7
7
|
<% end %>
|
8
|
-
<% if options[:space].present? %>
|
9
|
-
<div style="margin-top:<%= options[:space] %>px;"></div>
|
10
|
-
<% end %>
|
data/lib/show_message.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'show_message/view_helpers'
|
2
|
+
|
2
3
|
if defined? Rails
|
3
4
|
require 'show_message/railtie'
|
4
5
|
require 'show_message/engine'
|
@@ -6,14 +7,26 @@ end
|
|
6
7
|
|
7
8
|
module ShowMessage
|
8
9
|
|
9
|
-
def show_message(type, message, id:
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
10
|
+
def show_message(type, message, id: nil)
|
11
|
+
id ||= 'all'
|
12
|
+
flash[type] ||= {}
|
13
|
+
flash[type][id.to_s] = message
|
14
|
+
end
|
15
|
+
|
16
|
+
def show_success(message)
|
17
|
+
show_message(:success, message)
|
18
|
+
end
|
19
|
+
|
20
|
+
def show_success_for(id, message)
|
21
|
+
show_message(:success, message, id: id)
|
22
|
+
end
|
23
|
+
|
24
|
+
def show_error(message)
|
25
|
+
show_message(:error, message)
|
26
|
+
end
|
27
|
+
|
28
|
+
def show_error_for(id, message)
|
29
|
+
show_message(:error, message, id: id)
|
17
30
|
end
|
18
31
|
|
19
32
|
end
|
data/lib/show_message/railtie.rb
CHANGED
@@ -2,8 +2,18 @@ require 'show_message/view_helpers'
|
|
2
2
|
|
3
3
|
module ShowMessage
|
4
4
|
class Railtie < Rails::Railtie
|
5
|
-
|
6
|
-
|
5
|
+
|
6
|
+
initializer 'show_message.setup_action_view' do
|
7
|
+
ActiveSupport.on_load :action_view do
|
8
|
+
include ShowMessage::ViewHelpers
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
initializer 'show_message.setup_action_controller' do
|
13
|
+
ActiveSupport.on_load :action_controller do
|
14
|
+
include ShowMessage
|
15
|
+
end
|
7
16
|
end
|
8
|
-
|
9
|
-
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
data/lib/show_message/version.rb
CHANGED
@@ -1,35 +1,42 @@
|
|
1
1
|
module ShowMessage
|
2
2
|
module ViewHelpers
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
4
|
+
# render the applicable messages
|
5
|
+
#
|
6
|
+
# @param options_or_ids options or the ids to target
|
7
|
+
# @param options options for the view
|
8
|
+
def show_message(options_or_ids = nil, options = nil)
|
9
|
+
if options_or_ids.is_a?(Hash)
|
10
|
+
display_ids = []
|
11
|
+
options = options_or_ids
|
12
|
+
else
|
13
|
+
display_ids = options_or_ids
|
14
|
+
options ||= {}
|
15
15
|
end
|
16
16
|
|
17
|
-
|
17
|
+
display_ids = display_ids.is_a?(Array) ? display_ids : [display_ids]
|
18
|
+
display_ids = display_ids.compact.map(&:to_s)
|
19
|
+
# target all messages if no target is specified
|
20
|
+
display_ids.push('all') if display_ids.empty?
|
18
21
|
|
19
|
-
|
20
|
-
|
21
|
-
next unless value
|
22
|
+
data = []
|
23
|
+
message_keys = %w(success error warning info notice alert)
|
22
24
|
|
23
|
-
|
24
|
-
|
25
|
+
flash.to_h.slice(*message_keys).each do |key, message_hash|
|
26
|
+
# support basic usage of flash[:success] or flash[:error] which
|
27
|
+
# would normally just return a string
|
28
|
+
if message_hash.is_a?(Hash)
|
29
|
+
message_hash.each do |id, messages|
|
30
|
+
next unless display_ids.include?('all') || display_ids.include?(id)
|
25
31
|
|
26
|
-
|
27
|
-
value.each do |message|
|
28
|
-
data.push(message: message, class: flash_type)
|
32
|
+
build_data(data, messages, key)
|
29
33
|
end
|
30
34
|
else
|
31
|
-
|
35
|
+
next unless display_ids.include?('all')
|
36
|
+
|
37
|
+
build_data(data, message_hash, key)
|
32
38
|
end
|
39
|
+
|
33
40
|
flash.discard(key)
|
34
41
|
end
|
35
42
|
|
@@ -38,5 +45,15 @@ module ShowMessage
|
|
38
45
|
}
|
39
46
|
end
|
40
47
|
|
48
|
+
private
|
49
|
+
|
50
|
+
# support for messages to be an array. this will add multiple items to the
|
51
|
+
# data array to be rendered.
|
52
|
+
def build_data(data, messages, key)
|
53
|
+
messages = messages.is_a?(Array) ? messages : [messages]
|
54
|
+
messages.each do |message|
|
55
|
+
data.push(message: message, class: key)
|
56
|
+
end
|
57
|
+
end
|
41
58
|
end
|
42
59
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: show_message
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jarrett Lusso
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-03-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -48,6 +48,7 @@ extra_rdoc_files: []
|
|
48
48
|
files:
|
49
49
|
- ".gitignore"
|
50
50
|
- ".travis.yml"
|
51
|
+
- CHANGELOG.md
|
51
52
|
- Gemfile
|
52
53
|
- LICENSE.txt
|
53
54
|
- README.md
|
@@ -78,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
78
79
|
- !ruby/object:Gem::Version
|
79
80
|
version: '0'
|
80
81
|
requirements: []
|
81
|
-
rubygems_version: 3.0.
|
82
|
+
rubygems_version: 3.0.6
|
82
83
|
signing_key:
|
83
84
|
specification_version: 4
|
84
85
|
summary: show_message makes it easy to output your flash[:success], flash[:error]
|