gritter 1.0.3 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +5 -5
- data/README.md +440 -353
- data/gritter.gemspec +3 -3
- data/lib/generators/gritter/templates/gflash.en.yml +8 -0
- data/lib/gritter.rb +9 -0
- data/lib/gritter/gflash.rb +85 -50
- data/lib/gritter/helpers.rb +92 -90
- data/lib/gritter/version.rb +2 -2
- data/{app → vendor}/assets/images/error.png +0 -0
- data/{app → vendor}/assets/images/gritter-close.png +0 -0
- data/{app → vendor}/assets/images/gritter.png +0 -0
- data/{app → vendor}/assets/images/ie-spacer.gif +0 -0
- data/{app → vendor}/assets/images/notice.png +0 -0
- data/{app → vendor}/assets/images/progress.gif +0 -0
- data/{app → vendor}/assets/images/success.png +0 -0
- data/{app → vendor}/assets/images/warning.png +0 -0
- data/{app → vendor}/assets/javascripts/gritter.js +1 -1
- data/{app → vendor}/assets/stylesheets/gritter.css.scss +0 -0
- metadata +34 -58
checksums.yaml
ADDED
@@ -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
|
4
|
-
Robin Brouwer
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
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
|
-
- Added
|
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
|
-
|
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
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
gflash :
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
```
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
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/
|