gritter 1.0.3 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 45a4d70ada18b99410d0f29cb2616f6dadefa0f8
4
+ data.tar.gz: 0623da1810fb180cd63be4c65de5848a45eb36c5
5
+ SHA512:
6
+ metadata.gz: 46f1ab7a732ebe9eadadaad6df43df5a362166b687a0221f9a092eb8979a3cc4b99c46de9317578340e4b8b2c99247d37c032adea9935f719b55e26106ae9a86
7
+ data.tar.gz: 40b1829f0b6607b46038825ac5effb30aa71885005bb503e8d6a1afa1778c7f7bccd78d7c630cd35a8a72030ee234f06320547b3566dcaebf7ea294b1dcda2a5
data/.gitignore CHANGED
@@ -1,5 +1,5 @@
1
- .DS_Store
2
- gritter*.gem
3
- .bundle
4
- pkg
5
- .project
1
+ .DS_Store
2
+ gritter*.gem
3
+ .bundle
4
+ pkg
5
+ .project
data/README.md CHANGED
@@ -1,354 +1,441 @@
1
- # gritter
2
-
3
- version 1.0.3
4
- Robin Brouwer
5
- Daniël Zwijnenburg
6
- 45north
7
-
8
- This Ruby on Rails gem allows you to easily add Growl-like notifications to your application using a jQuery plugin called 'gritter'. [Check out the demo for this plugin](http://boedesign.com/demos/gritter/).
9
-
10
- ## Note
11
-
12
- This is a Rails 3.1 gem. Are you using Rails 3.0 or lower? Check out [the 'old' branch on Github](https://github.com/RobinBrouwer/gritter/tree/old). Want support for IE6?
13
- Also check out that branch, because the newer version of gritter inside this gem dropped support for it.
14
-
15
-
16
- ## Installation
17
-
18
- You can use this gem by putting the following inside your Gemfile:
19
-
20
- gem "gritter", "1.0.3"
21
-
22
- Now generate the locale for gritter:
23
-
24
- rails g gritter:locale
25
-
26
- Add the following to `/app/assets/javascripts/application.js`:
27
-
28
- //= require gritter
29
-
30
- And the following to `/app/assets/stylesheets/application.css`:
31
-
32
- *= require gritter
33
-
34
- And that's it!
35
-
36
- ## Changes
37
-
38
- Version 1.0.3 changes (26/01/2013):
39
-
40
- - :nodom_wrap added by indykish
41
-
42
- Version 1.0.2 changes (03/09/2012):
43
-
44
- - Merged pull request #22 (namespaced controllers gflash fix).
45
-
46
- Version 1.0.1 changes (23/01/2012):
47
-
48
- - Fixed gflash(:js => true) in Ruby 1.9.2 and 1.9.3.
49
-
50
- Version 1.0.0 changes (17/11/2011):
51
-
52
- - Gritter now only works in Rails 3.1. You should check out the 'old' branch for other Rails versions.
53
- - Removed everything that isn't needed for Rails 3.1.
54
- - Added new version for the gritter jQuery plugin (1.7.1).
55
- - Added position option for your gritter messages.
56
- - Locale isn't automatically generated. You need to use the gritter:locale generator.
57
- - Adding locale-based gflash messages got a bit easier.
58
- - You can now use a :gflash option inside the redirect_to method.
59
- - Using SCSS image_path instead of ERB image_path inside the CSS.
60
- - Added CSS3 support for gritter.
61
- - Refactored some parts of the gem.
62
- - Changed the README quite a bit.
63
-
64
-
65
- ## Usage
66
-
67
- There are several helpers you can use with gritter. All of them print out Javascript code without script-tags.
68
-
69
- add_gritter
70
- remove_gritter
71
- extend_gritter
72
-
73
- To add the script-tags we added another function called `js`. It allows you to easily add script-tags around your javascript.
74
- It can be used in combination with gritter, but also other Javascript you want to run.
75
-
76
- The most popular feature of this gem is `gflash`. This replaces the regular flash messages in Rails and
77
- automatically puts these in gritter boxes. Read further to learn more about gflash.
78
-
79
-
80
- ### add_gritter
81
-
82
- The `add_gritter` helper allows you to add a gritter notification to your application.
83
- It outputs Javascript directly into your template. It works like this inside a `js.erb` file:
84
-
85
- <%= add_gritter("This is a notification just for you!") %>
86
-
87
- The `add_gritter` helper allows you to easily set the text for the notification.
88
- When you want to change the title, just pass the `:title` argument to the helper:
89
-
90
- <%= add_gritter("This is a notification just for you!", :title => "Please pay attention!") %>
91
-
92
- There are many more arguments you can pass to the helper:
93
-
94
- :title => "This is a title" # => Allows you to set the title for the notification.
95
- :image => "/images/rails.png" # => Allows you to add an image to the notification.
96
- :sticky => true # => Allows you to make the notification sticky.
97
- :time => 4000 # => Allows you to set the time when the notification disappears (in ms).
98
- :class_name => "gritter" # => Allows you to set a different classname.
99
- :before_open => "alert('Opening!');" # => Execute javascript before opening.
100
- :after_open => "alert('Opened!');" # => Execute javascript after opening.
101
- :before_close => "alert('Closing!');" # => Execute javascript before closing.
102
- :after_close => "alert('Closed!');" # => Execute javascript after closing.
103
- :nodom_wrap => true # => Removes the DOM wrap on the produced JQuery code. Default, this argument
104
- is false or not present, hence you always get a DOM wrap.
105
-
106
- The `:image` argument also allows you to easily set five different images:
107
-
108
- :success
109
- :warning
110
- :notice
111
- :error
112
- :progress
113
-
114
- It works like this in combination with flash[:notice] and the `js` helper:
115
-
116
- <%= js add_gritter(flash[:notice], :image => :notice, :title => "Pay attention!", :sticky => true) %>
117
-
118
- The js helper is almost the same as the javascript_tag helper. The difference is that you can pass several scripts at once.
119
- You don't need to pass these scripts as an Array. The helper also adds a linebreak (\n) after each script.
120
-
121
- <%= js add_gritter("See my notification"), add_gritter("Another one") %>
122
-
123
- It puts all the scripts inside a single script-tag.
124
-
125
- And that's it! You just added Growl-like notifications to your Rails application.
126
- It's great for all kinds of notifications, including the flash notifications you want to show to your users.
127
-
128
-
129
- ### remove_gritter
130
-
131
- The `remove_gritter` helper removes all gritter notifications from the screen. You can use it inside a `js.erb` file:
132
-
133
- <%= remove_gritter %>
134
-
135
- You can pass two extra arguments to this helper.
136
-
137
- :before_close => "alert('Closing!');" # => Execute javascript before closing.
138
- :after_close => "alert('Closed!');" # => Execute javascript after closing.
139
-
140
- You can also use the `js` helper to add script-tags around this helper.
141
-
142
-
143
- ### extend_gritter
144
-
145
- The `extend_gritter` helper allows you to set the default gritter options.
146
-
147
- <%= extend_gritter :time => 1000 %>
148
-
149
- These are the options you can pass to `extend_gritter`:
150
-
151
- :fade_in_speed => "medium" # => Allows you to set the fade-in-speed. Can be String or Integer (in ms).
152
- :fade_out_speed => 1000 # => Allows you to set the fade-out-speed. Can be String or Integer (in ms).
153
- :time => 8000 # => Allows you to set the time the notification stays. Must be an Integer (in ms).
154
- :position => :bottom_left # => Allows you to set the position for all gritter messages.
155
-
156
- The :fade_in_speed and :fade_out_speed options accept the following Strings:
157
-
158
- "slow"
159
- "medium"
160
- "fast"
161
-
162
- The :position option accepts four different Symbols:
163
-
164
- :top_left
165
- :top_right # Default
166
- :bottom_left
167
- :bottom_right
168
-
169
- You can also use the `js` helper , add_gritter("Another one") to add script-tags around this helper.
170
-
171
-
172
- ### gflash
173
-
174
- The `gflash` helper is a different kind of `flash[:notice]` message. It uses the `add_gritter` helper and the default images used in this plugin.
175
- It uses a session to remember the flash messages. Add the following inside your controller action:
176
-
177
- def create
178
- gflash :success => "The product has been created successfully!"
179
- end
180
-
181
- Now you can add the following to your layout view inside the body-tag:
182
-
183
- <%= gflash %>
184
-
185
- The flash-message will be shown with 'success.png' as the image and 'Success' as the title.
186
- To change the title you can add the following to the `gflash` helper inside the layout:
187
-
188
- <%= gflash :success => "It has been successful!" %>
189
-
190
- Now the default title will be overwritten. You can also use gflash inside `js.erb` files:
191
-
192
- <%= gflash :js => true %>
193
-
194
- The :success key isn't the only option supported by gflash. You can use the following gflash options:
195
-
196
- :success
197
- :warning
198
- :notice
199
- :error
200
- :progress
201
-
202
- Each uses the corresponding image and title. You can also add multiple gritter notifications at once:
203
-
204
- def create
205
- gflash :success => "The product has been created successfully!", :notice => "This product doesn't have a category."
206
- end
207
-
208
- Besides passing the exact text inside the controller, gflash also supports locales (both for messages and titles).
209
- When you start your server a new locale file will be added to /config/locales called `gflash.en.yml`.
210
- Here you can set the locales for all your gflash messages and the titles. It works like this:
211
-
212
- en:
213
- gflash:
214
- titles:
215
- notice: "Custom notice title"
216
- success: "Success"
217
- warning: "Warning"
218
- error: "Error"
219
- progress: "Progress"
220
- products: # => Controller name
221
- create: # => Action name
222
- notice: "Custom notice message"
223
-
224
- Now you can do the following inside your Controller:
225
-
226
- def create
227
- gflash :notice => true
228
- end
229
-
230
- The locales for the `:notice` title and message will now be used. You can still pass a `String` to override a locale.
231
- Since gritter version 1.0 you can also do the following to add the gritter messages:
232
-
233
- def create
234
- gflash :notice, :success, :error
235
- end
236
-
237
- No need to pass `true` to each key.
238
-
239
- You can change the default time, sticky and class_name options for each gritter message.
240
- This is done inside the Controller and works like this:
241
-
242
- gflash :success => { :time => 2000, :class_name => "my_class", :sticky => true }
243
- gflash :success => { :value => true, :time => 2000, :class_name => "my_class", :sticky => true }
244
- gflash :error => { :value => "Custom error", :time => 3000, :class_name => "my_error_class", :sticky => false }
245
-
246
- When you don't pass a `:value` it uses the locale. Same goes for when you pass `true` to `:value`. When you give `:value` a String, that String will be used to display the message. Here's another example:
247
-
248
- def create
249
- @user = User.new(params[:user])
250
- if @user.save
251
- gflash :success => { :value => "Account has been created!", :time => 5000 },
252
- :notice => { :value => "You have received an e-mail notification.", :sticky => true }
253
- redirect_to :root
254
- else
255
- gflash :error => { :value => "Something went wrong.", :time => 4000 },
256
- :warning => { :value => "Some fields weren't filled in correctly.", :time => 7000 }
257
- render :new
258
- end
259
- end
260
-
261
- You can also use gflash directly inside the `redirect_to` method.
262
-
263
- def create
264
- redirect_to @post, :gflash => [:notice, :success]
265
- end
266
-
267
- def destroy
268
- redirect_to :posts, :gflash => { :warning => "You just deleted something important." }
269
- end
270
-
271
- def logged_in?
272
- redirect_to :login, :gflash => { :error => { :value => "You are not logged in!", :sticky => true } }
273
- end
274
-
275
- And that's how you add gflash to your Rails application!
276
-
277
-
278
- ### Using `nodom_wrap` to change the JQuery code produced
279
-
280
- ##### Default. (when nodom_wrap is not present)
281
- The `add_gritter` helper produces JQuery code as shown below.
282
-
283
- ```ruby
284
- <%= add_gritter(:success, "See my notification")%>
285
- ```
286
-
287
- ```js
288
- jQuery(function() {
289
- jQuery.gritter.add({image:'/assets/success.png',title:'Success',text:'See my notification'})
290
- });
291
- ```
292
-
293
- ##### nodom_wrap
294
-
295
- If you don't want to wrap `jQuery.gritter.add({` inside a `jQuery(function()` then include the argument `:nodom_wrap`
296
-
297
- The modified `add_gritter` helper with `nodom_wrap` looks like this:
298
-
299
- ```ruby
300
- <%= add_gritter(:success, "See my notification", :nodom_wrap => true )%>
301
- ```
302
-
303
- With `:nodom_wrap` included, the following JQuery code will be produced.
304
-
305
- ```js
306
- jQuery.gritter.add({
307
- image: '/assets/success.png',
308
- title: 'Success',
309
- text: 'The product has been created successfully!'
310
- });
311
- ```
312
-
313
- The argument can be included in `gflash` helper as well.
314
-
315
- ```ruby
316
- gflash :success => { :value => "Account has been created!", :time => 5000, :nodom_wrap => true }
317
-
318
- redirect_to signin_path(@user), :gflash =>
319
- { :success => { :value => "Welcome back #{@user.first_name}.
320
- Your email #{@user.email} is verified. Thank you.", :sticky => false, :nodom_wrap => true } }
321
- ```
322
-
323
-
324
- ## Copyright
325
-
326
- Copyright (C) 2010 Robin Brouwer
327
-
328
- Permission is hereby granted, free of charge, to any person obtaining a copy of
329
- this software and associated documentation files (the "Software"), to deal in
330
- the Software without restriction, including without limitation the rights to
331
- use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
332
- of the Software, and to permit persons to whom the Software is furnished to do
333
- so, subject to the following conditions:
334
-
335
- The above copyright notice and this permission notice shall be included in all
336
- copies or substantial portions of the Software.
337
-
338
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
339
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
340
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
341
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
342
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
343
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
344
- SOFTWARE.
345
-
346
- ## Special Thanks
347
-
348
- We'd like to express our gratitude to the following people:
349
-
350
- Many thanks to Jordan Boesch, creator of the AWESOME jQuery plugin gritter.
351
- http://boedesign.com/blog/2009/07/11/growl-for-jquery-gritter/
352
-
353
- Also special thanks to Liam McKay for creating the awesome icons!
1
+ # gritter
2
+
3
+ version 1.1.0
4
+ Robin Brouwer
5
+ montblanc
6
+
7
+ This Ruby on Rails gem allows you to easily add Growl-like notifications to your application using a jQuery plugin called 'gritter'. [Check out the demo for this plugin](http://boedesign.com/demos/gritter/).
8
+
9
+ ## Note
10
+
11
+ Are you using Rails 3.0 or lower? Check out [the 'old' branch on Github](https://github.com/RobinBrouwer/gritter/tree/old). Want support for IE6?
12
+ Also check out that branch, because the newer version of gritter inside this gem dropped support for it.
13
+
14
+
15
+ ## Installation
16
+
17
+ You can use this gem by putting the following inside your Gemfile:
18
+
19
+ gem "gritter", "1.1.0"
20
+
21
+ Now generate the locale for gritter:
22
+
23
+ rails g gritter:locale
24
+
25
+ Add the following to `/app/assets/javascripts/application.js`:
26
+
27
+ //= require gritter
28
+
29
+ And the following to `/app/assets/stylesheets/application.css`:
30
+
31
+ *= require gritter
32
+
33
+ And that's it!
34
+
35
+ ## Changes
36
+
37
+ Version 1.1.0 changes (31/01/2013):
38
+
39
+ - All gflash messages are also stored in the Rails flash messages.
40
+ - Added i18n interpolation for gflash messages.
41
+ - Added default values for the gflash messages.
42
+ - Fixed several other issues.
43
+
44
+ Version 1.0.3 changes (26/01/2013):
45
+
46
+ - :nodom_wrap added by indykish
47
+
48
+ Version 1.0.2 changes (03/09/2012):
49
+
50
+ - Merged pull request #22 (namespaced controllers gflash fix).
51
+
52
+ Version 1.0.1 changes (23/01/2012):
53
+
54
+ - Fixed gflash(:js => true) in Ruby 1.9.2 and 1.9.3.
55
+
56
+ Version 1.0.0 changes (17/11/2011):
57
+
58
+ - Gritter now only works in Rails 3.1. You should check out the 'old' branch for other Rails versions.
59
+ - Removed everything that isn't needed for Rails 3.1.
60
+ - Added new version for the gritter jQuery plugin (1.7.1).
61
+ - Added position option for your gritter messages.
62
+ - Locale isn't automatically generated. You need to use the gritter:locale generator.
63
+ - Adding locale-based gflash messages got a bit easier.
64
+ - You can now use a :gflash option inside the redirect_to method.
65
+ - Using SCSS image_path instead of ERB image_path inside the CSS.
66
+ - Added CSS3 support for gritter.
67
+ - Refactored some parts of the gem.
68
+ - Changed the README quite a bit.
69
+
70
+
71
+ ## Usage
72
+
73
+ There are several helpers you can use with gritter. All of them print out Javascript code without script-tags.
74
+
75
+ ```ruby
76
+ add_gritter
77
+ remove_gritter
78
+ extend_gritter
79
+ ```
80
+
81
+ To add the script-tags we added another function called `js`. It allows you to easily add script-tags around your javascript.
82
+ It can be used in combination with gritter, but also other Javascript you want to run.
83
+
84
+ The most popular feature of this gem is `gflash`. This replaces the regular flash messages in Rails and
85
+ automatically puts these in gritter boxes. Read further to learn more about gflash.
86
+
87
+
88
+ ### add_gritter
89
+
90
+ The `add_gritter` helper allows you to add a gritter notification to your application.
91
+ It outputs Javascript directly into your template. It works like this inside a `js.erb` file:
92
+
93
+ ```ruby
94
+ <%= add_gritter("This is a notification just for you!") %>
95
+ ```
96
+
97
+ The `add_gritter` helper allows you to easily set the text for the notification.
98
+ When you want to change the title, just pass the `:title` argument to the helper:
99
+
100
+ ```ruby
101
+ <%= add_gritter("This is a notification just for you!", :title => "Please pay attention!") %>
102
+ ```
103
+
104
+ There are many more arguments you can pass to the helper:
105
+
106
+ ```ruby
107
+ :title => "This is a title" # => Allows you to set the title for the notification.
108
+ :image => "/images/rails.png" # => Allows you to add an image to the notification.
109
+ :sticky => true # => Allows you to make the notification sticky.
110
+ :time => 4000 # => Allows you to set the time when the notification disappears (in ms).
111
+ :class_name => "gritter" # => Allows you to set a different classname.
112
+ :before_open => "alert('Opening!');" # => Execute javascript before opening.
113
+ :after_open => "alert('Opened!');" # => Execute javascript after opening.
114
+ :before_close => "alert('Closing!');" # => Execute javascript before closing.
115
+ :after_close => "alert('Closed!');" # => Execute javascript after closing.
116
+ :nodom_wrap => true # => Removes the DOM wrap on the produced JQuery code. Default, this argument
117
+ # is false or not present, hence you always get a DOM wrap.
118
+ ```
119
+
120
+ The `:image` argument also allows you to easily set five different images:
121
+
122
+ ```ruby
123
+ :success
124
+ :warning
125
+ :notice
126
+ :error
127
+ :progress
128
+ ```
129
+
130
+ It works like this in combination with flash[:notice] and the `js` helper:
131
+
132
+ ```ruby
133
+ <%= js add_gritter(flash[:notice], :image => :notice, :title => "Pay attention!", :sticky => true) %>
134
+ ```
135
+
136
+ The js helper is almost the same as the javascript_tag helper. The difference is that you can pass several scripts at once.
137
+ You don't need to pass these scripts as an Array. The helper also adds a linebreak (\n) after each script.
138
+
139
+ ```ruby
140
+ <%= js add_gritter("See my notification"), add_gritter("Another one") %>
141
+ ```
142
+
143
+ It puts all the scripts inside a single script-tag.
144
+
145
+ And that's it! You just added Growl-like notifications to your Rails application.
146
+ It's great for all kinds of notifications, including the flash notifications you want to show to your users.
147
+
148
+
149
+ ### remove_gritter
150
+
151
+ The `remove_gritter` helper removes all gritter notifications from the screen. You can use it inside a `js.erb` file:
152
+
153
+ ```ruby
154
+ <%= remove_gritter %>
155
+ ```
156
+
157
+ You can pass two extra arguments to this helper.
158
+
159
+ ```ruby
160
+ :before_close => "alert('Closing!');" # => Execute javascript before closing.
161
+ :after_close => "alert('Closed!');" # => Execute javascript after closing.
162
+ ```
163
+
164
+ You can also use the `js` helper to add script-tags around this helper.
165
+
166
+
167
+ ### extend_gritter
168
+
169
+ The `extend_gritter` helper allows you to set the default gritter options.
170
+
171
+ ```ruby
172
+ <%= extend_gritter :time => 1000 %>
173
+ ```
174
+
175
+ These are the options you can pass to `extend_gritter`:
176
+
177
+ ```ruby
178
+ :fade_in_speed => "medium" # => Allows you to set the fade-in-speed. Can be String or Integer (in ms).
179
+ :fade_out_speed => 1000 # => Allows you to set the fade-out-speed. Can be String or Integer (in ms).
180
+ :time => 8000 # => Allows you to set the time the notification stays. Must be an Integer (in ms).
181
+ :position => :bottom_left # => Allows you to set the position for all gritter messages.
182
+ ```
183
+
184
+ The :fade_in_speed and :fade_out_speed options accept the following Strings:
185
+
186
+ ```ruby
187
+ "slow"
188
+ "medium"
189
+ "fast"
190
+ ```
191
+
192
+ The :position option accepts four different Symbols:
193
+
194
+ ```ruby
195
+ :top_left
196
+ :top_right # Default
197
+ :bottom_left
198
+ :bottom_right
199
+ ```
200
+
201
+ You can also use the `js` helper , add_gritter("Another one") to add script-tags around this helper.
202
+
203
+
204
+ ### gflash
205
+
206
+ The `gflash` helper is a different kind of `flash[:notice]` message. It uses the `add_gritter` helper and the default images used in this gem.
207
+ It saves the messages in `session[:gflash]`. It can also save the messages inside the default Rails flash messages (`flash` and `flash.now`).
208
+ To do this, you have to add the following to an initializer: `Gritter.rails_flash_fallback = true`.
209
+
210
+ Add the following inside your controller action:
211
+
212
+ ```ruby
213
+ def create
214
+ @product = Product.new(product_params)
215
+ if @product.save
216
+ gflash :success => "The product has been created successfully!"
217
+ redirect_to(@product)
218
+ else
219
+ gflash :now, :error => "Something went wrong."
220
+ render("new")
221
+ end
222
+ end
223
+ ```
224
+
225
+ You can add `:now` to add the flash message to `flash.now` as well.
226
+
227
+ Now you can add the following to your layout view inside the body-tag:
228
+
229
+ ```ruby
230
+ <%= gflash %>
231
+ ```
232
+
233
+ The flash-message will be shown with 'success.png' as the image and 'Success' as the title when the product is saved.
234
+ To change the title you can add the following to the `gflash` helper inside the layout:
235
+
236
+ ```ruby
237
+ <%= gflash :success => "It has been successful!" %>
238
+ ```
239
+
240
+ Now the default title will be overwritten. You can also use gflash inside `js.erb` files:
241
+
242
+ ```ruby
243
+ <%= gflash :js => true %>
244
+ ```
245
+
246
+ The :success key isn't the only option supported by gflash. You can use the following gflash options:
247
+
248
+ ```ruby
249
+ :success
250
+ :warning
251
+ :notice
252
+ :error
253
+ :progress
254
+ ```
255
+
256
+ Each uses the corresponding image and title. You can also add multiple gritter notifications at once:
257
+
258
+ ```ruby
259
+ def create
260
+ gflash :success => "The product has been created successfully!", :notice => "This product doesn't have a category."
261
+ end
262
+ ```
263
+
264
+ Besides passing the exact text inside the controller, gflash also supports locales (both for messages and titles).
265
+ You can generate `gflash.en.yml` by using the following command: `rails g gritter:locale`.
266
+ Here you can set the locales for all your gflash messages and the titles. It works like this:
267
+
268
+ en:
269
+ gflash:
270
+ titles:
271
+ notice: "Custom notice title"
272
+ success: "Success"
273
+ warning: "Warning"
274
+ error: "Error"
275
+ progress: "Progress"
276
+ products: # => Controller name
277
+ create: # => Action name
278
+ notice: "Custom notice message"
279
+
280
+ It's also possible to add default gflash messages.
281
+
282
+ en:
283
+ gflash:
284
+ defaults:
285
+ success: "This is a notification"
286
+ error: "Something went wrong"
287
+ create:
288
+ success: "Successfully created!"
289
+ error: "Something went wrong. Please take a look at the form to see what went wrong."
290
+
291
+ Now you can do the following inside your Controller:
292
+
293
+ ```ruby
294
+ def create
295
+ gflash :notice => true
296
+ end
297
+ ```
298
+
299
+ The locales for the `:notice` title and message will now be used. You can still pass a `String` to override a locale.
300
+ Since gritter version 1.0 you can also do the following to add the gritter messages:
301
+
302
+ ```ruby
303
+ def create
304
+ gflash :notice, :success, :error
305
+ end
306
+ ```
307
+
308
+ No need to pass `true` to each key.
309
+
310
+ You can change the default time, sticky and class_name options for each gritter message.
311
+ This is done inside the Controller and works like this:
312
+
313
+ ```ruby
314
+ gflash :success => { :time => 2000, :class_name => "my_class", :sticky => true }
315
+ gflash :success => { :value => true, :time => 2000, :class_name => "my_class", :sticky => true }
316
+ gflash :error => { :value => "Custom error", :time => 3000, :class_name => "my_error_class", :sticky => false }
317
+ ```
318
+
319
+ When you don't pass a `:value` it uses the locale. Same goes for when you pass `true` to `:value`. When you give `:value` a String, that String will be used to display the message. Here's another example:
320
+
321
+ ```ruby
322
+ def create
323
+ @user = User.new(params[:user])
324
+ if @user.save
325
+ gflash :success => { :value => "Account has been created!", :time => 5000 },
326
+ :notice => { :value => "You have received an e-mail notification.", :sticky => true }
327
+ redirect_to :root
328
+ else
329
+ gflash :error => { :value => "Something went wrong.", :time => 4000 },
330
+ :warning => { :value => "Some fields weren't filled in correctly.", :time => 7000 }
331
+ render :new
332
+ end
333
+ end
334
+ ```ruby
335
+
336
+ You can also use gflash directly inside the `redirect_to` method.
337
+
338
+ ```ruby
339
+ def create
340
+ redirect_to @post, :gflash => [:notice, :success]
341
+ end
342
+
343
+ def destroy
344
+ redirect_to :posts, :gflash => { :warning => "You just deleted something important." }
345
+ end
346
+
347
+ def logged_in?
348
+ redirect_to :login, :gflash => { :error => { :value => "You are not logged in!", :sticky => true } }
349
+ end
350
+ ```
351
+
352
+ You can use i18n interpolation like this:
353
+
354
+ ```ruby
355
+ redirect_to :root, :flash => { :success => true, :locals => { :name => @user.name, :email => @user.email } }
356
+ gflash :success, :info, :locals => { :name => @user.name, :email => @user.email }
357
+ gflash :success, :info => { :locals => { :name => @user.name, :email => @user.email } }
358
+ ```
359
+
360
+ Inside `gflash.en.yml` you can do the following:
361
+
362
+ ```ruby
363
+ success: "Welcome, %{name}."
364
+ info: "Your e-mail address has been changed to: %{email}."
365
+ ```
366
+
367
+ And that's how you add gflash to your Rails application!
368
+
369
+
370
+ ### Using `nodom_wrap` to change the jQuery code produced
371
+
372
+ ##### Default (when nodom_wrap is not present)
373
+ The `add_gritter` helper produces JQuery code as shown below.
374
+
375
+ ```ruby
376
+ <%= add_gritter(:success, "See my notification") %>
377
+ ```
378
+
379
+ ```js
380
+ jQuery(function() {
381
+ jQuery.gritter.add({ image: '/assets/success.png', title: 'Success', text: 'See my notification' });
382
+ });
383
+ ```
384
+
385
+ ##### nodom_wrap
386
+
387
+ If you don't want to wrap `jQuery.gritter.add({` inside a `jQuery(function()` then include the argument `:nodom_wrap`
388
+
389
+ The modified `add_gritter` helper with `nodom_wrap` looks like this:
390
+
391
+ ```ruby
392
+ <%= add_gritter(:success, "See my notification", :nodom_wrap => true )%>
393
+ ```
394
+
395
+ With `:nodom_wrap` included, the following JQuery code will be produced.
396
+
397
+ ```js
398
+ jQuery.gritter.add({
399
+ image: '/assets/success.png',
400
+ title: 'Success',
401
+ text: 'The product has been created successfully!'
402
+ });
403
+ ```
404
+
405
+ The argument can be included in `gflash` helper as well.
406
+
407
+ ```ruby
408
+ gflash :nodom_wrap => true
409
+ ```
410
+
411
+ ## Copyright
412
+
413
+ Copyright (C) 2010 Robin Brouwer
414
+
415
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
416
+ this software and associated documentation files (the "Software"), to deal in
417
+ the Software without restriction, including without limitation the rights to
418
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
419
+ of the Software, and to permit persons to whom the Software is furnished to do
420
+ so, subject to the following conditions:
421
+
422
+ The above copyright notice and this permission notice shall be included in all
423
+ copies or substantial portions of the Software.
424
+
425
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
426
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
427
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
428
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
429
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
430
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
431
+ SOFTWARE.
432
+
433
+ ## Special Thanks
434
+
435
+ We'd like to express our gratitude to the following people:
436
+
437
+ Many thanks to Jordan Boesch, creator of the AWESOME jQuery plugin gritter.
438
+ http://boedesign.com/blog/2009/07/11/growl-for-jquery-gritter/
439
+
440
+ Also special thanks to Liam McKay for creating the awesome icons!
354
441
  http://wefunction.com/2008/07/function-free-icon-set/