bootstrap_flash_messages 0.0.7 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +251 -223
- data/bootstrap_flash_messages.gemspec +2 -2
- data/lib/bootstrap_flash_messages/flash_messages.rb +65 -44
- data/lib/bootstrap_flash_messages/helpers.rb +36 -34
- data/lib/bootstrap_flash_messages/version.rb +2 -2
- data/lib/bootstrap_flash_messages.rb +1 -1
- data/lib/generators/bootstrap_flash_messages/templates/flash.en.yml +8 -0
- metadata +24 -47
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f366f23e74319dee69123d53e1986bf41f3b4031
|
4
|
+
data.tar.gz: 10c2b230c89ec5ac9fdd4445dbbff9b6a2d98104
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: de4b83d0dd14725bd27aec9f33f1b6ed96cd51479443d8326c6708d57332c0817a049407179d721a373ba3213634aa574441c2eead426f4dcaec0c33223eb38b
|
7
|
+
data.tar.gz: 130c9f96deb7ee5b3bf279d6ab9ebfb48494f0284cb60bf1b9b55cddc86b1887e4df03e59d0ebb32baff5e1a015f070c46c1ff9d22e3c82810f17e44b254009a
|
data/README.md
CHANGED
@@ -1,224 +1,252 @@
|
|
1
|
-
# bootstrap_flash_messages
|
2
|
-
|
3
|
-
version 0.0
|
4
|
-
Robin Brouwer
|
5
|
-
|
6
|
-
|
7
|
-
Bootstrap alerts and Rails flash messages combined in one easy-to-use gem.
|
8
|
-
|
9
|
-
|
10
|
-
## Installation
|
11
|
-
|
12
|
-
You can use this gem by putting the following inside your Gemfile:
|
13
|
-
|
14
|
-
gem "bootstrap_flash_messages"
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
- Added
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
And that's it!
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
:
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
1
|
+
# bootstrap_flash_messages
|
2
|
+
|
3
|
+
version 1.0.0
|
4
|
+
Robin Brouwer
|
5
|
+
montblanc
|
6
|
+
|
7
|
+
Bootstrap alerts and Rails flash messages combined in one easy-to-use gem.
|
8
|
+
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
You can use this gem by putting the following inside your Gemfile:
|
13
|
+
|
14
|
+
gem "bootstrap_flash_messages", "~> 1.0.0"
|
15
|
+
|
16
|
+
When you're using Bootstrap 2, you can use version 0.0.7.
|
17
|
+
|
18
|
+
Now you need flash.en.yml for the flash messages.
|
19
|
+
|
20
|
+
rails g bootstrap_flash_messages:locale
|
21
|
+
|
22
|
+
And that's it!
|
23
|
+
|
24
|
+
|
25
|
+
## Changes
|
26
|
+
|
27
|
+
Version 1.0.0 changes (31/01/2014):
|
28
|
+
|
29
|
+
- Added Boostrap 3 support.
|
30
|
+
- Added default locales for the flash messages.
|
31
|
+
- Removed the 'convert_newlines' option and added 'simple_format'.
|
32
|
+
- Added option to set flash values directly inside 'flash!' and 'flash_now!'.
|
33
|
+
- Changed the documentation.
|
34
|
+
|
35
|
+
Version 0.0.7 changes (26/01/2013):
|
36
|
+
|
37
|
+
- Added alert_class_mapping (documentation below).
|
38
|
+
|
39
|
+
Version 0.0.6 changes (27/09/2012):
|
40
|
+
|
41
|
+
- Added pull request #5 by protolif. This adds the :fade option.
|
42
|
+
|
43
|
+
Version 0.0.5 changes (24/09/2012):
|
44
|
+
|
45
|
+
- Added HTML escape option for flash_messages helper (:html).
|
46
|
+
- Also added option to convert new-lines to br-tags (:convert_newlines).
|
47
|
+
|
48
|
+
Version 0.0.4 changes (03/09/2012):
|
49
|
+
|
50
|
+
- Namespaced Controllers can be accessed by nesting your locales.
|
51
|
+
|
52
|
+
# Old
|
53
|
+
"admin/products":
|
54
|
+
...
|
55
|
+
|
56
|
+
# New:
|
57
|
+
admin:
|
58
|
+
products:
|
59
|
+
...
|
60
|
+
|
61
|
+
Version 0.0.3 changes (14/08/2012):
|
62
|
+
|
63
|
+
- Added interpolation to the flash messages
|
64
|
+
|
65
|
+
Version 0.0.2 changes (10/08/2012):
|
66
|
+
|
67
|
+
- Changed the 'x' in close to & t i m e s ;
|
68
|
+
|
69
|
+
Version 0.0.1 changes (08/08/2012):
|
70
|
+
|
71
|
+
- Changed redirect_to method
|
72
|
+
- Added flash! and flash_now! methods
|
73
|
+
- Added flash_messages helper
|
74
|
+
- Made a gem out of it
|
75
|
+
|
76
|
+
|
77
|
+
## Usage
|
78
|
+
|
79
|
+
You need [Bootstrap 3](http://getbootstrap.com/) for the styling and close button. You can still use it without Bootstrap, but you need to style it yourself. This gem uses the [Bootstrap alerts](http://getbootstrap.com/components/#alerts).
|
80
|
+
|
81
|
+
If you're [customizing Bootstrap](http://getbootstrap.com/customize/), make sure to grab the "Alert" and "Component Animations" (the latter one is optional, unless you want the fade-out animation on close).
|
82
|
+
|
83
|
+
All flash messages are defined inside config/locales/flash.en.yml. They are nested like this:
|
84
|
+
|
85
|
+
en:
|
86
|
+
flash_messages:
|
87
|
+
controller_name:
|
88
|
+
action_name:
|
89
|
+
success: "It worked!"
|
90
|
+
info: "There's something you need to know..."
|
91
|
+
warning: "You should watch out now."
|
92
|
+
error: "Oh no! Something went wrong."
|
93
|
+
|
94
|
+
You have four keys:
|
95
|
+
|
96
|
+
:success
|
97
|
+
:info
|
98
|
+
:warning
|
99
|
+
:error
|
100
|
+
|
101
|
+
It is also possible to add default locales globally or per action:
|
102
|
+
|
103
|
+
en:
|
104
|
+
flash_messages:
|
105
|
+
defaults:
|
106
|
+
success: "It really worked!"
|
107
|
+
create:
|
108
|
+
success: "Created successfully!"
|
109
|
+
|
110
|
+
When you've defined the messages it's very easy to call them inside your Controller.
|
111
|
+
|
112
|
+
class PostsController
|
113
|
+
def create
|
114
|
+
@post = Post.new(params[:post])
|
115
|
+
if @post.save
|
116
|
+
redirect_to(@post, :flash => :success)
|
117
|
+
else
|
118
|
+
flash_now!(:error)
|
119
|
+
render("new")
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
You can use the `:flash` parameter inside the `redirect_to` method (note: this gem changes the redirect_to method!) to set the flash messages. You only need to pass the corresponding key and the gem will automatically set `flash[:success]` to `t("flash_messages.posts.create.success")`. The `:flash` parameter also accepts an Array.
|
125
|
+
|
126
|
+
redirect_to(@post, :flash => [:success, :info])
|
127
|
+
|
128
|
+
You can still use a Hash to use the default `redirect_to` behavior.
|
129
|
+
|
130
|
+
redirect_to(:root, :flash => { :error => I18n.t("flash_messages.authorize_admin") })
|
131
|
+
|
132
|
+
When you don't want to use the `redirect_to` method to set the flash messages, you can use the `flash!` method.
|
133
|
+
|
134
|
+
flash!(:success, :info)
|
135
|
+
redirect_to(@post)
|
136
|
+
|
137
|
+
When you need to use `flash.now` you can use the `flash_now!` method.
|
138
|
+
|
139
|
+
flash_now!(:error, :warning)
|
140
|
+
|
141
|
+
You use `flash_now!` in combination with rendering a view instead of redirecting.
|
142
|
+
|
143
|
+
You can also pass options to `flash!` and `flash_now!` to set the flash values directly.
|
144
|
+
|
145
|
+
flash!(:error => I18n.t("flash_messages.authorize_admin"))
|
146
|
+
flash_now!(:error => I18n.t("flash_messages.authorize_admin"))
|
147
|
+
|
148
|
+
Now's the time to show these messages to the user. Inside the layout (or any other view), add the following:
|
149
|
+
|
150
|
+
<div id="flash_messages"><%= flash_messages %></div>
|
151
|
+
|
152
|
+
And that's it! To change the flash messages inside a `.js.erb` file, you can do the following:
|
153
|
+
|
154
|
+
$("#flash_messages").html("<%= j(flash_messages) %>");
|
155
|
+
|
156
|
+
The `flash_messages` helper shows a simple Bootstrap alert box. If you want to add a close button you can add the `:close` option.
|
157
|
+
|
158
|
+
<%= flash_messages(:close) %>
|
159
|
+
|
160
|
+
If you'd like for the flash message to fade out when you click on the close icon, you can pass in the `:fade` option. This requires `:close` to work, obviously.
|
161
|
+
|
162
|
+
<%= flash_messages(:close, :fade) %>
|
163
|
+
|
164
|
+
Want a heading? Add `:heading`. The headings inside flash.en.yml are used for the headings.
|
165
|
+
|
166
|
+
<%= flash_messages(:close, :heading) %>
|
167
|
+
|
168
|
+
Want to put the heading inside a `<h4>` tag? Just add `:block`.
|
169
|
+
|
170
|
+
<%= flash_messages(:close, :heading, :block) %>
|
171
|
+
|
172
|
+
Need to display HTML inside the flash messages? Use the `:html` option.
|
173
|
+
|
174
|
+
<%= flash_messages(:html) %>
|
175
|
+
|
176
|
+
It's also possible to use simple_format on the flash message using the `:simple_format` option.
|
177
|
+
|
178
|
+
<%= flash_messages(:simple_format) %>
|
179
|
+
|
180
|
+
And that's it! Have fun. :)
|
181
|
+
|
182
|
+
## Interpolation
|
183
|
+
|
184
|
+
You can use i18n interpolation like this:
|
185
|
+
|
186
|
+
redirect_to :root, :flash => [:success, :info], :locals => { :name => @user.name, :email => @user.email }
|
187
|
+
flash! :success, :info, :locals => { :name => @user.name, :email => @user.email }
|
188
|
+
flash_now! :success, :info, :locals => { :name => @user.name, :email => @user.email }
|
189
|
+
|
190
|
+
Inside `flash.en.yml` you can do the following:
|
191
|
+
|
192
|
+
success: "Welcome, %{name}."
|
193
|
+
info: "Your e-mail address has been changed to: %{email}."
|
194
|
+
|
195
|
+
## alert_class_mapping
|
196
|
+
|
197
|
+
You can map the keys used inside the flash messages to a different alert class. There are 4 different classes for the alert messages inside bootstrap:
|
198
|
+
|
199
|
+
alert-success
|
200
|
+
alert-info
|
201
|
+
alert-warning
|
202
|
+
alert-danger
|
203
|
+
|
204
|
+
When you use `:notice` the alert class is mapped (by default) to `alert-success`. So it looks like this:
|
205
|
+
|
206
|
+
:notice maps to "alert-success"
|
207
|
+
:success maps to "alert-success"
|
208
|
+
:info maps to "alert-info"
|
209
|
+
:warning maps to "alert-warning"
|
210
|
+
:error maps to "alert-danger"
|
211
|
+
|
212
|
+
Changing the mapping is quite easy. Create an initializer (config/initializers/bootstrap_flash_messages.rb) and add the following:
|
213
|
+
|
214
|
+
module BootstrapFlashMessages
|
215
|
+
@alert_class_mapping = {
|
216
|
+
:notice => :danger,
|
217
|
+
:success => :success,
|
218
|
+
:info => :info,
|
219
|
+
:warning => :warning,
|
220
|
+
:error => :danger
|
221
|
+
}
|
222
|
+
end
|
223
|
+
|
224
|
+
Now you can map whatever alert class you want to the different keys.
|
225
|
+
|
226
|
+
## Why I created this gem
|
227
|
+
|
228
|
+
I created the [gritter gem](https://github.com/RobinBrouwer/gritter) and used it in a lot of projects.
|
229
|
+
I started using Bootstrap and really liked the alerts. I loved the way gritter allowed you to set messages
|
230
|
+
and decided to do the same for the Bootstrap alerts. And this is the result!
|
231
|
+
|
232
|
+
## Copyright
|
233
|
+
|
234
|
+
Copyright (C) 2012 Robin Brouwer
|
235
|
+
|
236
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
237
|
+
this software and associated documentation files (the "Software"), to deal in
|
238
|
+
the Software without restriction, including without limitation the rights to
|
239
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
240
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
241
|
+
so, subject to the following conditions:
|
242
|
+
|
243
|
+
The above copyright notice and this permission notice shall be included in all
|
244
|
+
copies or substantial portions of the Software.
|
245
|
+
|
246
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
247
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
248
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
249
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
250
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
251
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
224
252
|
SOFTWARE.
|
@@ -7,8 +7,8 @@ Gem::Specification.new do |s|
|
|
7
7
|
s.version = BootstrapFlashMessages::VERSION
|
8
8
|
s.platform = Gem::Platform::RUBY
|
9
9
|
s.authors = ["Robin Brouwer"]
|
10
|
-
s.email = ["robin@
|
11
|
-
s.homepage = "http://www.
|
10
|
+
s.email = ["robin@montblanc.nl"]
|
11
|
+
s.homepage = "http://www.montblanc.nl"
|
12
12
|
s.summary = %q{Bootstrap alerts and Rails flash messages combined in one easy-to-use gem.}
|
13
13
|
s.description = %q{Bootstrap alerts and Rails flash messages combined in one easy-to-use gem.}
|
14
14
|
|
@@ -1,44 +1,65 @@
|
|
1
|
-
module BootstrapFlashMessages
|
2
|
-
module FlashMessages
|
3
|
-
def redirect_to(options = {}, response_status_and_flash = {})
|
4
|
-
messages = response_status_and_flash[:flash]
|
5
|
-
if messages && (messages.is_a?(Symbol) || messages.is_a?(Array))
|
6
|
-
flashes = {}
|
7
|
-
locals = response_status_and_flash[:locals]
|
8
|
-
if messages.is_a?(Array)
|
9
|
-
messages.each do |key|
|
10
|
-
flashes[key] = flash_messages(key, locals)
|
11
|
-
end
|
12
|
-
else
|
13
|
-
flashes[messages] = flash_messages(messages, locals)
|
14
|
-
end
|
15
|
-
response_status_and_flash.delete(:locals)
|
16
|
-
response_status_and_flash[:flash] = flashes
|
17
|
-
end
|
18
|
-
super(options, response_status_and_flash)
|
19
|
-
end
|
20
|
-
|
21
|
-
private
|
22
|
-
|
23
|
-
def flash!(*args)
|
24
|
-
options = args.extract_options!
|
25
|
-
args.each do |key|
|
26
|
-
flash[key] = flash_messages(key, options[:locals])
|
27
|
-
end
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
1
|
+
module BootstrapFlashMessages
|
2
|
+
module FlashMessages
|
3
|
+
def redirect_to(options = {}, response_status_and_flash = {})
|
4
|
+
messages = response_status_and_flash[:flash]
|
5
|
+
if messages && (messages.is_a?(Symbol) || messages.is_a?(Array))
|
6
|
+
flashes = {}
|
7
|
+
locals = response_status_and_flash[:locals]
|
8
|
+
if messages.is_a?(Array)
|
9
|
+
messages.each do |key|
|
10
|
+
flashes[key] = flash_messages(key, locals)
|
11
|
+
end
|
12
|
+
else
|
13
|
+
flashes[messages] = flash_messages(messages, locals)
|
14
|
+
end
|
15
|
+
response_status_and_flash.delete(:locals)
|
16
|
+
response_status_and_flash[:flash] = flashes
|
17
|
+
end
|
18
|
+
super(options, response_status_and_flash)
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def flash!(*args)
|
24
|
+
options = args.extract_options!
|
25
|
+
args.each do |key|
|
26
|
+
flash[key] = flash_messages(key, options[:locals])
|
27
|
+
end
|
28
|
+
options.except(:locals).each do |key, value|
|
29
|
+
flash[key] = value
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def flash_now!(*args)
|
34
|
+
options = args.extract_options!
|
35
|
+
args.each do |key|
|
36
|
+
flash.now[key] = flash_messages(key, options[:locals])
|
37
|
+
end
|
38
|
+
options.except(:locals).each do |key, value|
|
39
|
+
flash.now[key] = value
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def flash_messages(key, *args)
|
44
|
+
i18n_key = "flash_messages.#{params[:controller]}.#{params[:action]}.#{key}"
|
45
|
+
i18n_default_key = "flash_messages.defaults.#{key}"
|
46
|
+
i18n_default_action_key = "flash_messages.defaults.#{params[:action]}.#{key}"
|
47
|
+
i18n_key.gsub!(/\//, ".")
|
48
|
+
options = args.extract_options!
|
49
|
+
|
50
|
+
begin
|
51
|
+
options[:raise] = true
|
52
|
+
translation = I18n.t(i18n_key, options)
|
53
|
+
rescue I18n::MissingTranslationData
|
54
|
+
begin
|
55
|
+
translation = I18n.t(i18n_default_action_key, options)
|
56
|
+
rescue I18n::MissingTranslationData
|
57
|
+
options[:raise] = false
|
58
|
+
translation = I18n.t(i18n_default_key, options)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
translation
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -1,34 +1,36 @@
|
|
1
|
-
module BootstrapFlashMessages
|
2
|
-
module Helpers
|
3
|
-
def flash_messages(*args)
|
4
|
-
if flash.present?
|
5
|
-
block = args.include?(:block)
|
6
|
-
show_heading = args.include?(:heading)
|
7
|
-
show_close = args.include?(:close)
|
8
|
-
unescape_html = args.include?(:html)
|
9
|
-
|
10
|
-
fade = args.include?(:fade)
|
11
|
-
|
12
|
-
messages = []
|
13
|
-
flash.each do |key, value|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
end
|
1
|
+
module BootstrapFlashMessages
|
2
|
+
module Helpers
|
3
|
+
def flash_messages(*args)
|
4
|
+
if flash.present?
|
5
|
+
block = args.include?(:block)
|
6
|
+
show_heading = args.include?(:heading)
|
7
|
+
show_close = args.include?(:close)
|
8
|
+
unescape_html = args.include?(:html)
|
9
|
+
simple_format = args.include?(:simple_format)
|
10
|
+
fade = args.include?(:fade)
|
11
|
+
|
12
|
+
messages = []
|
13
|
+
flash.each do |key, value|
|
14
|
+
next if key == :timedout
|
15
|
+
|
16
|
+
heading = ""
|
17
|
+
if show_heading
|
18
|
+
heading_text = I18n.t("flash_messages.headings.#{key}")
|
19
|
+
heading = (block ? content_tag(:h4, heading_text, :class => "alert-heading") : content_tag(:strong, heading_text))
|
20
|
+
end
|
21
|
+
close = ""
|
22
|
+
if show_close
|
23
|
+
close = content_tag(:button, raw("×"), :type => "button", :class => "close", "data-dismiss" => "alert", "aria-hidden" => "true")
|
24
|
+
end
|
25
|
+
|
26
|
+
value = simple_format(value) if simple_format
|
27
|
+
value = raw(value) if unescape_html
|
28
|
+
|
29
|
+
messages << content_tag(:div, close + heading + " " + value, :class => "alert alert-#{BootstrapFlashMessages.alert_class_mapping(key)}#{' alert-dismissable' if show_close}#{" fade in" if fade}")
|
30
|
+
end
|
31
|
+
|
32
|
+
raw(messages.join)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -1,3 +1,3 @@
|
|
1
1
|
module BootstrapFlashMessages
|
2
|
-
VERSION = "0.0
|
3
|
-
end
|
2
|
+
VERSION = "1.0.0"
|
3
|
+
end
|
@@ -2,7 +2,7 @@ require 'bootstrap_flash_messages/helpers'
|
|
2
2
|
require 'bootstrap_flash_messages/flash_messages'
|
3
3
|
|
4
4
|
module BootstrapFlashMessages
|
5
|
-
@alert_class_mapping = { :notice => :success, :success => :success, :info => :info, :warning => :warning, :error => :
|
5
|
+
@alert_class_mapping = { :notice => :success, :success => :success, :info => :info, :warning => :warning, :error => :danger }
|
6
6
|
|
7
7
|
def self.alert_class_mapping(key)
|
8
8
|
@alert_class_mapping[key.to_sym]
|
@@ -9,6 +9,14 @@ en:
|
|
9
9
|
warning: "Warning!"
|
10
10
|
error: "Error!"
|
11
11
|
#
|
12
|
+
# Add default flash messages:
|
13
|
+
# defaults:
|
14
|
+
# success: "This is a notification"
|
15
|
+
# error: "Something went wrong"
|
16
|
+
# create:
|
17
|
+
# success: "Successfully created!"
|
18
|
+
# error: "Something went wrong. Please take a look at the form to see what went wrong."
|
19
|
+
#
|
12
20
|
# Add flash messages for controller actions:
|
13
21
|
# products:
|
14
22
|
# create:
|
metadata
CHANGED
@@ -1,35 +1,24 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: bootstrap_flash_messages
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease: false
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 0
|
9
|
-
- 7
|
10
|
-
version: 0.0.7
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
11
5
|
platform: ruby
|
12
|
-
authors:
|
6
|
+
authors:
|
13
7
|
- Robin Brouwer
|
14
8
|
autorequire:
|
15
9
|
bindir: bin
|
16
10
|
cert_chain: []
|
17
|
-
|
18
|
-
date: 2013-01-26 00:00:00 +01:00
|
19
|
-
default_executable:
|
11
|
+
date: 2014-01-31 00:00:00.000000000 Z
|
20
12
|
dependencies: []
|
21
|
-
|
22
|
-
|
23
|
-
email:
|
24
|
-
- robin@
|
13
|
+
description: Bootstrap alerts and Rails flash messages combined in one easy-to-use
|
14
|
+
gem.
|
15
|
+
email:
|
16
|
+
- robin@montblanc.nl
|
25
17
|
executables: []
|
26
|
-
|
27
18
|
extensions: []
|
28
|
-
|
29
19
|
extra_rdoc_files: []
|
30
|
-
|
31
|
-
|
32
|
-
- .gitignore
|
20
|
+
files:
|
21
|
+
- ".gitignore"
|
33
22
|
- Gemfile
|
34
23
|
- README.md
|
35
24
|
- Rakefile
|
@@ -43,39 +32,27 @@ files:
|
|
43
32
|
- lib/generators/bootstrap_flash_messages/USAGE
|
44
33
|
- lib/generators/bootstrap_flash_messages/locale_generator.rb
|
45
34
|
- lib/generators/bootstrap_flash_messages/templates/flash.en.yml
|
46
|
-
|
47
|
-
homepage: http://www.45north.nl
|
35
|
+
homepage: http://www.montblanc.nl
|
48
36
|
licenses: []
|
49
|
-
|
37
|
+
metadata: {}
|
50
38
|
post_install_message:
|
51
39
|
rdoc_options: []
|
52
|
-
|
53
|
-
require_paths:
|
40
|
+
require_paths:
|
54
41
|
- lib
|
55
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
-
|
57
|
-
requirements:
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
58
44
|
- - ">="
|
59
|
-
- !ruby/object:Gem::Version
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
version: "0"
|
64
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
|
-
requirements:
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
67
49
|
- - ">="
|
68
|
-
- !ruby/object:Gem::Version
|
69
|
-
|
70
|
-
segments:
|
71
|
-
- 0
|
72
|
-
version: "0"
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
73
52
|
requirements: []
|
74
|
-
|
75
53
|
rubyforge_project: nowarning
|
76
|
-
rubygems_version:
|
54
|
+
rubygems_version: 2.2.1
|
77
55
|
signing_key:
|
78
|
-
specification_version:
|
56
|
+
specification_version: 4
|
79
57
|
summary: Bootstrap alerts and Rails flash messages combined in one easy-to-use gem.
|
80
58
|
test_files: []
|
81
|
-
|