bootstrap_flash_messages 0.0.7 → 1.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 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.7
4
- Robin Brouwer
5
- 45north
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
- Now you need flash.en.yml for the flash messages.
17
-
18
- rails g bootstrap_flash_messages:locale
19
-
20
- And that's it!
21
-
22
-
23
- ## Changes
24
-
25
- Version 0.0.7 changes (26/01/2013):
26
-
27
- - Added alert_class_mapping (documentation below).
28
-
29
- Version 0.0.6 changes (27/09/2012):
30
-
31
- - Added pull request #5 by protolif. This adds the :fade option.
32
-
33
- Version 0.0.5 changes (24/09/2012):
34
-
35
- - Added HTML escape option for flash_messages helper (:html).
36
- - Also added option to convert new-lines to br-tags (:convert_newlines).
37
-
38
- Version 0.0.4 changes (03/09/2012):
39
-
40
- - Namespaced Controllers can be accessed by nesting your locales.
41
-
42
- # Old
43
- "admin/products":
44
- ...
45
-
46
- # New:
47
- admin:
48
- products:
49
- ...
50
-
51
- Version 0.0.3 changes (14/08/2012):
52
-
53
- - Added interpolation to the flash messages
54
-
55
- Version 0.0.2 changes (10/08/2012):
56
-
57
- - Changed the 'x' in close to & t i m e s ;
58
-
59
- Version 0.0.1 changes (08/08/2012):
60
-
61
- - Changed redirect_to method
62
- - Added flash! and flash_now! methods
63
- - Added flash_messages helper
64
- - Made a gem out of it
65
-
66
-
67
- ## Usage
68
-
69
- You need [Twitter Bootstrap](http://twitter.github.com/bootstrap) 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://twitter.github.com/bootstrap/components.html#alerts).
70
-
71
- If you're [customizing Bootstrap](http://twitter.github.com/bootstrap/customize.html), make sure to grab the "Alert Messages", "Component Animations", and "Transitions" (the latter two are optional, unless you want the fade-out animation on close).
72
-
73
- All flash messages are defined inside config/locales/flash.en.yml. They are nested like this:
74
-
75
- en:
76
- flash_messages:
77
- controller_name:
78
- action_name:
79
- success: "It worked!"
80
- info: "There's something you need to know..."
81
- warning: "You should watch out now."
82
- error: "Oh no! Something went wrong."
83
-
84
- You have four keys:
85
-
86
- :success
87
- :info
88
- :warning
89
- :error
90
-
91
- When you've defined the messages it's really easy to call them inside your Controller.
92
-
93
- class PostsController
94
- def create
95
- @post = Post.new(params[:post])
96
- if @post.save
97
- redirect_to(@post, :flash => :success)
98
- else
99
- flash_now!(:error)
100
- render("new")
101
- end
102
- end
103
- end
104
-
105
- 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.
106
-
107
- redirect_to(@post, :flash => [:success, :info])
108
-
109
- You can still use a Hash to use the default `redirect_to` behavior. When you don't want to use the `redirect_to` method to set the flash messages, you can use the `flash!` method.
110
-
111
- flash!(:success, :info)
112
- redirect_to(@post)
113
-
114
- When you need to use `flash.now` you can use the new `flash_now!` method.
115
-
116
- flash_now!(:error, :warning)
117
-
118
- You use `flash_now!` in combination with rendering a view instead of redirecting.
119
-
120
- Now's the time to show these messages to the user. Inside the layout (or any other view), add the following:
121
-
122
- <div id="flash_messages"><%= flash_messages %></div>
123
-
124
- And that's it! To change the flash messages inside a `.js.erb` file, you can do the following:
125
-
126
- $("#flash_messages").html("#{j(flash_messages)}");
127
-
128
- The `flash_messages` helper shows a simple Bootstrap alert box. If you want to add a close button you can add the `:close` option.
129
-
130
- <%= flash_messages(:close) %>
131
-
132
- 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.
133
-
134
- <%= flash_messages(:close, :fade) %>
135
-
136
- Want to use the `.alert-block` class? Just add `:block`.
137
-
138
- <%= flash_messages(:close, :block) %>
139
-
140
- Want a heading? Add `:heading`. The headings inside flash.en.yml are used for the headings.
141
-
142
- <%= flash_messages(:close, :block, :heading) %>
143
-
144
- Need to display HTML inside the flash messages? Use the `:html` option.
145
-
146
- <%= flash_messages(:html) %>
147
-
148
- It's also possible to convert new-lines (\n) into br-tags using the `:convert_newlines` option. This option also unescapes all other HTML, so use it with care.
149
-
150
- <%= flash_messages(:convert_newlines) %>
151
-
152
- And that's it! Have fun. :)
153
-
154
- ## Interpolation
155
-
156
- You can use i18n interpolation like this:
157
-
158
- redirect_to :root, :flash => [:success, :info], :locals => { :name => @user.name, :email => @user.email }
159
- flash! :success, :info, :locals => { :name => @user.name, :email => @user.email }
160
- flash_now! :success, :info, :locals => { :name => @user.name, :email => @user.email }
161
-
162
- Inside `flash.en.yml` you can do the following:
163
-
164
- success: "Welcome, %{name}."
165
- info: "Your e-mail address has been changed to: %{email}."
166
-
167
- ## alert_class_mapping
168
-
169
- 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:
170
-
171
- alert-success
172
- alert-info
173
- alert-warning
174
- alert-error
175
-
176
- When you use `:notice` the alert class is mapped (by default) to `alert-success`. So it looks like this:
177
-
178
- :notice maps to "alert-success"
179
- :success maps to "alert-success"
180
- :info maps to "alert-info"
181
- :warning maps to "alert-warning"
182
- :error maps to "alert-error"
183
-
184
- Changing the mapping is quite easy. Create an initializer (config/initializers/bootstrap_flash_messages.rb) and add the following:
185
-
186
- module BootstrapFlashMessages
187
- @alert_class_mapping = {
188
- :notice => :error,
189
- :success => :success,
190
- :info => :info,
191
- :warning => :warning,
192
- :error => :error
193
- }
194
- end
195
-
196
- Now you can map whatever alert class you want to the different keys.
197
-
198
- ## Why I created this gem
199
-
200
- I created the [gritter gem](https://github.com/RobinBrouwer/gritter) and used it in a lot of projects.
201
- I started using Twitter Bootstrap and really liked the alerts. I loved the way gritter allowed you to set messages
202
- and decided to do the same for the Bootstrap alerts. And this is the result!
203
-
204
- ## Copyright
205
-
206
- Copyright (C) 2012 Robin Brouwer
207
-
208
- Permission is hereby granted, free of charge, to any person obtaining a copy of
209
- this software and associated documentation files (the "Software"), to deal in
210
- the Software without restriction, including without limitation the rights to
211
- use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
212
- of the Software, and to permit persons to whom the Software is furnished to do
213
- so, subject to the following conditions:
214
-
215
- The above copyright notice and this permission notice shall be included in all
216
- copies or substantial portions of the Software.
217
-
218
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
219
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
220
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
221
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
222
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
223
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
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@45north.nl"]
11
- s.homepage = "http://www.45north.nl"
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
- end
29
-
30
- def flash_now!(*args)
31
- options = args.extract_options!
32
- args.each do |key|
33
- flash.now[key] = flash_messages(key, options[:locals])
34
- end
35
- end
36
-
37
- def flash_messages(key, *args)
38
- i18n_key = "flash_messages.#{params[:controller]}.#{params[:action]}.#{key}"
39
- options = args.extract_options!
40
- options[:default] = i18n_key.to_sym
41
- I18n.t(i18n_key.gsub(/\//, "."), options).html_safe
42
- end
43
- end
44
- end
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
- convert_newlines = args.include?(:convert_newlines)
10
- fade = args.include?(:fade)
11
-
12
- messages = []
13
- flash.each do |key, value|
14
- heading = ""
15
- if show_heading
16
- heading_text = I18n.t("flash_messages.headings.#{key}")
17
- heading = (block ? content_tag(:h4, heading_text, :class => "alert-heading") : content_tag(:strong, heading_text))
18
- end
19
- close = ""
20
- if show_close
21
- close = link_to(raw("&times;"), "#", :class => "close", :data => { :dismiss => "alert" })
22
- end
23
-
24
- value.gsub!("\n", "<br/>") if convert_newlines
25
-
26
- messages << content_tag(:div, :class => "alert alert-#{BootstrapFlashMessages.alert_class_mapping(key)}#{" alert-block" if block}#{" fade in" if fade}") do
27
- close + heading + " " + (unescape_html || convert_newlines ? raw(value) : value)
28
- end
29
- end
30
- raw(messages.join)
31
- end
32
- end
33
- end
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("&times;"), :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.7"
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 => :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
- hash: 17
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
- description: Bootstrap alerts and Rails flash messages combined in one easy-to-use gem.
23
- email:
24
- - robin@45north.nl
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
- files:
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
- has_rdoc: true
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
- none: false
57
- requirements:
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ requirements:
58
44
  - - ">="
59
- - !ruby/object:Gem::Version
60
- hash: 3
61
- segments:
62
- - 0
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
- hash: 3
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: 1.3.7
54
+ rubygems_version: 2.2.1
77
55
  signing_key:
78
- specification_version: 3
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
-