bootstrap_flash_messages 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +189 -179
- data/lib/bootstrap_flash_messages/helpers.rb +2 -1
- data/lib/bootstrap_flash_messages/version.rb +1 -1
- metadata +4 -4
data/README.md
CHANGED
@@ -1,180 +1,190 @@
|
|
1
|
-
# bootstrap_flash_messages
|
2
|
-
|
3
|
-
version 0.0.
|
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.
|
26
|
-
|
27
|
-
- Added
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
#
|
39
|
-
admin:
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
Version 0.0.
|
48
|
-
|
49
|
-
-
|
50
|
-
|
51
|
-
Version 0.0.
|
52
|
-
|
53
|
-
- Changed
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
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
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
the
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
1
|
+
# bootstrap_flash_messages
|
2
|
+
|
3
|
+
version 0.0.6
|
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.6 changes (27/09/2012):
|
26
|
+
|
27
|
+
- Added pull request #5 by protolif. This adds the :fade option.
|
28
|
+
|
29
|
+
Version 0.0.5 changes (24/09/2012):
|
30
|
+
|
31
|
+
- Added HTML escape option for flash_messages helper (:html).
|
32
|
+
- Also added option to convert new-lines to br-tags (:convert_newlines).
|
33
|
+
|
34
|
+
Version 0.0.4 changes (03/09/2012):
|
35
|
+
|
36
|
+
- Namespaced Controllers can be accessed by nesting your locales.
|
37
|
+
|
38
|
+
# Old
|
39
|
+
"admin/products":
|
40
|
+
...
|
41
|
+
|
42
|
+
# New:
|
43
|
+
admin:
|
44
|
+
products:
|
45
|
+
...
|
46
|
+
|
47
|
+
Version 0.0.3 changes (14/08/2012):
|
48
|
+
|
49
|
+
- Added interpolation to the flash messages
|
50
|
+
|
51
|
+
Version 0.0.2 changes (10/08/2012):
|
52
|
+
|
53
|
+
- Changed the 'x' in close to & t i m e s ;
|
54
|
+
|
55
|
+
Version 0.0.1 changes (08/08/2012):
|
56
|
+
|
57
|
+
- Changed redirect_to method
|
58
|
+
- Added flash! and flash_now! methods
|
59
|
+
- Added flash_messages helper
|
60
|
+
- Made a gem out of it
|
61
|
+
|
62
|
+
|
63
|
+
## Usage
|
64
|
+
|
65
|
+
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).
|
66
|
+
|
67
|
+
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).
|
68
|
+
|
69
|
+
All flash messages are defined inside config/locales/flash.en.yml. They are nested like this:
|
70
|
+
|
71
|
+
en:
|
72
|
+
flash_messages:
|
73
|
+
controller_name:
|
74
|
+
action_name:
|
75
|
+
success: "It worked!"
|
76
|
+
info: "There's something you need to know..."
|
77
|
+
warning: "You should watch out now."
|
78
|
+
error: "Oh no! Something went wrong."
|
79
|
+
|
80
|
+
You have four keys:
|
81
|
+
|
82
|
+
:success
|
83
|
+
:info
|
84
|
+
:warning
|
85
|
+
:error
|
86
|
+
|
87
|
+
When you've defined the messages it's really easy to call them inside your Controller.
|
88
|
+
|
89
|
+
class PostsController
|
90
|
+
def create
|
91
|
+
@post = Post.new(params[:post])
|
92
|
+
if @post.save
|
93
|
+
redirect_to(@post, :flash => :success)
|
94
|
+
else
|
95
|
+
flash_now!(:error)
|
96
|
+
render("new")
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
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.
|
102
|
+
|
103
|
+
redirect_to(@post, :flash => [:success, :info])
|
104
|
+
|
105
|
+
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.
|
106
|
+
|
107
|
+
flash!(:success, :info)
|
108
|
+
redirect_to(@post)
|
109
|
+
|
110
|
+
When you need to use `flash.now` you can use the new `flash_now!` method.
|
111
|
+
|
112
|
+
flash_now!(:error, :warning)
|
113
|
+
|
114
|
+
You use `flash_now!` in combination with rendering a view instead of redirecting.
|
115
|
+
|
116
|
+
Now's the time to show these messages to the user. Inside the layout (or any other view), add the following:
|
117
|
+
|
118
|
+
<div id="flash_messages"><%= flash_messages %></div>
|
119
|
+
|
120
|
+
And that's it! To change the flash messages inside a `.js.erb` file, you can do the following:
|
121
|
+
|
122
|
+
$("#flash_messages").html("#{j(flash_messages)}");
|
123
|
+
|
124
|
+
The `flash_messages` helper shows a simple Bootstrap alert box. If you want to add a close button you can add the `:close` option.
|
125
|
+
|
126
|
+
<%= flash_messages(:close) %>
|
127
|
+
|
128
|
+
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.
|
129
|
+
|
130
|
+
<%= flash_messages(:close, :fade) %>
|
131
|
+
|
132
|
+
Want to use the `.alert-block` class? Just add `:block`.
|
133
|
+
|
134
|
+
<%= flash_messages(:close, :block) %>
|
135
|
+
|
136
|
+
Want a heading? Add `:heading`. The headings inside flash.en.yml are used for the headings.
|
137
|
+
|
138
|
+
<%= flash_messages(:close, :block, :heading) %>
|
139
|
+
|
140
|
+
Need to display HTML inside the flash messages? Use the `:html` option.
|
141
|
+
|
142
|
+
<%= flash_messages(:html) %>
|
143
|
+
|
144
|
+
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.
|
145
|
+
|
146
|
+
<%= flash_messages(:convert_newlines) %>
|
147
|
+
|
148
|
+
And that's it! Have fun. :)
|
149
|
+
|
150
|
+
## Interpolation
|
151
|
+
|
152
|
+
You can use i18n interpolation like this:
|
153
|
+
|
154
|
+
redirect_to :root, :flash => [:success, :info], :locals => { :name => @user.name, :email => @user.email }
|
155
|
+
flash! :success, :info, :locals => { :name => @user.name, :email => @user.email }
|
156
|
+
flash_now! :success, :info, :locals => { :name => @user.name, :email => @user.email }
|
157
|
+
|
158
|
+
Inside `flash.en.yml` you can do the following:
|
159
|
+
|
160
|
+
success: "Welcome, %{name}."
|
161
|
+
info: "Your e-mail address has been changed to: %{email}."
|
162
|
+
|
163
|
+
|
164
|
+
## Why I created this gem
|
165
|
+
|
166
|
+
I created the [gritter gem](https://github.com/RobinBrouwer/gritter) and used it in a lot of projects.
|
167
|
+
I started using Twitter Bootstrap and really liked the alerts. I loved the way gritter allowed you to set messages
|
168
|
+
and decided to do the same for the Bootstrap alerts. And this is the result!
|
169
|
+
|
170
|
+
## Copyright
|
171
|
+
|
172
|
+
Copyright (C) 2012 Robin Brouwer
|
173
|
+
|
174
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
175
|
+
this software and associated documentation files (the "Software"), to deal in
|
176
|
+
the Software without restriction, including without limitation the rights to
|
177
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
178
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
179
|
+
so, subject to the following conditions:
|
180
|
+
|
181
|
+
The above copyright notice and this permission notice shall be included in all
|
182
|
+
copies or substantial portions of the Software.
|
183
|
+
|
184
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
185
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
186
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
187
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
188
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
189
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
180
190
|
SOFTWARE.
|
@@ -7,6 +7,7 @@ module BootstrapFlashMessages
|
|
7
7
|
show_close = args.include?(:close)
|
8
8
|
unescape_html = args.include?(:html)
|
9
9
|
convert_newlines = args.include?(:convert_newlines)
|
10
|
+
fade = args.include?(:fade)
|
10
11
|
|
11
12
|
messages = []
|
12
13
|
flash.each do |key, value|
|
@@ -22,7 +23,7 @@ module BootstrapFlashMessages
|
|
22
23
|
|
23
24
|
value.gsub!("\n", "<br/>") if convert_newlines
|
24
25
|
|
25
|
-
messages << content_tag(:div, :class => "alert alert-#{key}
|
26
|
+
messages << content_tag(:div, :class => "alert alert-#{key}#{" alert-block" if block}#{" fade in" if fade}") do
|
26
27
|
close + heading + " " + (unescape_html || convert_newlines ? raw(value) : value)
|
27
28
|
end
|
28
29
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bootstrap_flash_messages
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 6
|
10
|
+
version: 0.0.6
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Robin Brouwer
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-09-
|
18
|
+
date: 2012-09-27 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|