bootstrap_flash_messages 0.0.5 → 0.0.6

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