gritter 0.5.1 → 0.6.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.
- data/README.markdown +42 -18
- data/gritter.gemspec +1 -1
- data/lib/gritter.rb +4 -0
- data/lib/gritter/assets/gflash.en.yml +21 -0
- data/lib/gritter/gflash.rb +1 -1
- data/lib/gritter/helpers.rb +5 -1
- data/lib/gritter/version.rb +1 -1
- metadata +5 -4
data/README.markdown
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# gritter
|
2
2
|
|
3
|
-
version 0.
|
3
|
+
version 0.6.0
|
4
4
|
Robin Brouwer
|
5
5
|
Daniël Zwijnenburg
|
6
6
|
45north
|
@@ -43,11 +43,19 @@ The :fade_in_speed and :fade_out_speed options accept the following Strings:
|
|
43
43
|
"slow"
|
44
44
|
"medium"
|
45
45
|
"fast"
|
46
|
-
|
47
46
|
|
48
|
-
|
47
|
+
Now you can use gritter inside your Rails application.
|
48
|
+
You should really check out the gflash helper. It's really handy!
|
49
|
+
|
50
|
+
|
51
|
+
## Changes
|
49
52
|
|
50
|
-
|
53
|
+
Version 0.6 changes:
|
54
|
+
|
55
|
+
- Added locales support for gflash (see README);
|
56
|
+
- README changes.
|
57
|
+
|
58
|
+
Version 0.5 changes:
|
51
59
|
|
52
60
|
- Works with Ruby 1.9 now (the Array.to_s was causing problems);
|
53
61
|
- Refactored a lot of code to make everything a bit more logical;
|
@@ -59,12 +67,6 @@ I have made several changes in version 0.5:
|
|
59
67
|
- Changed the README.
|
60
68
|
|
61
69
|
|
62
|
-
## Upcoming changes
|
63
|
-
|
64
|
-
One of the features I have in mind for the following release will be locales support for gflash.
|
65
|
-
The only thing you need to add in the Controller is what error should be shown and the locales will do the rest.
|
66
|
-
|
67
|
-
|
68
70
|
## Usage
|
69
71
|
|
70
72
|
There are several helpers you can use with gritter. All of them print out Javascript code without script-tags.
|
@@ -76,7 +78,7 @@ There are several helpers you can use with gritter. All of them print out Javasc
|
|
76
78
|
To add the script-tags we added another function called 'js'. It allows you to easily add script-tags around your javascript.
|
77
79
|
It can be used in combination with gritter, but also other Javascript you want to run.
|
78
80
|
|
79
|
-
Since version 0.3 we also added a gflash helper. You can read more about this helper below.
|
81
|
+
Since version 0.3 we also added a gflash helper. This helper supports locales since version 0.6. You can read more about this helper below.
|
80
82
|
|
81
83
|
|
82
84
|
### add_gritter
|
@@ -154,9 +156,7 @@ The gflash helper is a different kind of flash[:notice] message. It uses the add
|
|
154
156
|
It uses a session to remember the flash messages. Add the following inside your controller action:
|
155
157
|
|
156
158
|
def create
|
157
|
-
...
|
158
159
|
gflash :success => "The product has been created successfully!"
|
159
|
-
...
|
160
160
|
end
|
161
161
|
|
162
162
|
Now you can add the following to your layout view inside the body-tag:
|
@@ -179,13 +179,37 @@ Now the default title will be overwritten. You can use the following gflash opti
|
|
179
179
|
Each uses the corresponding image and title. You can also add multiple gritter notifications at once:
|
180
180
|
|
181
181
|
def create
|
182
|
-
|
183
|
-
|
184
|
-
|
182
|
+
gflash :success => "The product has been created successfully!", :notice => "This product doesn't have a category."
|
183
|
+
end
|
184
|
+
|
185
|
+
Besides passing the exact text inside the controller, gflash also supports locales (both for messages and titles).
|
186
|
+
When you start your server a new locale file will be added to /config/locales called 'gflash.en.yml'.
|
187
|
+
Here you can set the locales for all your gflash messages and the titles. It works like this:
|
188
|
+
|
189
|
+
en:
|
190
|
+
gflash:
|
191
|
+
titles:
|
192
|
+
notice: "Custom notice title"
|
193
|
+
success: "Success"
|
194
|
+
warning: "Warning"
|
195
|
+
error: "Error"
|
196
|
+
progress: "Progress"
|
197
|
+
products: # => Controller name
|
198
|
+
create: # => Action name
|
199
|
+
notice: "Custom notice message"
|
200
|
+
|
201
|
+
Now you can do the following inside your Controller:
|
202
|
+
|
203
|
+
def create
|
204
|
+
gflash :notice => true
|
185
205
|
end
|
186
206
|
|
187
|
-
|
188
|
-
|
207
|
+
The locales for the :notice title and message will now be used. You can still pass a String to overwrite a locale.
|
208
|
+
|
209
|
+
And that's how you add gflash to your Rails application.
|
210
|
+
Just remember that you can only set which gflash message you want shown inside the controller.
|
211
|
+
The gflash helper inside the views will show the notification and change the title when you pass extra arguments.
|
212
|
+
It will not change the message.
|
189
213
|
|
190
214
|
|
191
215
|
## Special Thanks
|
data/gritter.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.email = ["robin@45north.nl"]
|
11
11
|
s.homepage = "http://www.45north.nl"
|
12
12
|
s.summary = %q{Growl notifications for your Rails application.}
|
13
|
-
s.description = %q{This Ruby on Rails gem allows you to easily add Growl-like notifications to your application using a
|
13
|
+
s.description = %q{This Ruby on Rails gem allows you to easily add Growl-like notifications to your application using a jQuery plugin called 'gritter'.}
|
14
14
|
|
15
15
|
s.rubyforge_project = "nowarning"
|
16
16
|
|
data/lib/gritter.rb
CHANGED
@@ -16,9 +16,11 @@ module Gritter
|
|
16
16
|
orig_javascripts = File.join(File.dirname(__FILE__), 'gritter', 'assets', 'javascripts')
|
17
17
|
orig_stylesheets = File.join(File.dirname(__FILE__), 'gritter', 'assets', 'stylesheets')
|
18
18
|
orig_images = File.join(File.dirname(__FILE__), 'gritter', 'assets', 'images')
|
19
|
+
orig_lang = File.join(File.dirname(__FILE__), 'gritter', 'assets', 'gflash.en.yml')
|
19
20
|
dest_javascripts = File.join(Rails.root, 'public', 'javascripts', 'gritter')
|
20
21
|
dest_stylesheets = File.join(Rails.root, 'public', 'stylesheets', 'gritter')
|
21
22
|
dest_images = File.join(Rails.root, 'public', 'images', 'gritter')
|
23
|
+
dest_lang = File.join(Rails.root, 'config', 'locales', 'gflash.en.yml')
|
22
24
|
|
23
25
|
gritter = File.join(dest_javascripts, 'jquery.gritter.min.js')
|
24
26
|
|
@@ -36,6 +38,8 @@ module Gritter
|
|
36
38
|
FileUtils.cp_r "#{orig_stylesheets}/.", dest_stylesheets
|
37
39
|
puts "Copying gritter to #{dest_images}..."
|
38
40
|
FileUtils.cp_r "#{orig_images}/.", dest_images
|
41
|
+
puts "Copying language file to #{dest_lang}..."
|
42
|
+
FileUtils.cp_r orig_lang, dest_lang
|
39
43
|
puts "Successfully installed gritter."
|
40
44
|
rescue
|
41
45
|
puts "ERROR: Problem installing gritter. Please copy the files manually."
|
@@ -0,0 +1,21 @@
|
|
1
|
+
en:
|
2
|
+
gflash:
|
3
|
+
#
|
4
|
+
# These are the translations for the different titles.
|
5
|
+
#
|
6
|
+
titles:
|
7
|
+
notice: "Notice"
|
8
|
+
success: "Success"
|
9
|
+
warning: "Warning"
|
10
|
+
error: "Error"
|
11
|
+
progress: "Progress"
|
12
|
+
#
|
13
|
+
# Add gflash messages for controller actions:
|
14
|
+
# products:
|
15
|
+
# create:
|
16
|
+
# notice: "This is a notification"
|
17
|
+
# error: "Something went wrong"
|
18
|
+
#
|
19
|
+
# Inside controller:
|
20
|
+
# gflash :notice => true, :error => true
|
21
|
+
#
|
data/lib/gritter/gflash.rb
CHANGED
@@ -4,7 +4,7 @@ module Gritter
|
|
4
4
|
session[:gflash] ||= {}
|
5
5
|
options = args.extract_options!
|
6
6
|
options.each do |key, value|
|
7
|
-
session[:gflash][key] = value
|
7
|
+
session[:gflash][key] = value == true ? I18n.t("gflash.#{params[:controller]}.#{params[:action]}.#{key}") : value
|
8
8
|
end
|
9
9
|
end
|
10
10
|
end
|
data/lib/gritter/helpers.rb
CHANGED
@@ -70,11 +70,15 @@ module Gritter
|
|
70
70
|
|
71
71
|
def gflash_titles *args
|
72
72
|
options = args.extract_options!
|
73
|
-
titles = { :success =>
|
73
|
+
titles = { :success => get_translation(:success), :warning => get_translation(:warning), :error => get_translation(:error), :notice => get_translation(:notice), :progress => get_translation(:progress) }
|
74
74
|
options.each do |key, value|
|
75
75
|
titles[key] = value if titles.has_key?(key)
|
76
76
|
end
|
77
77
|
titles
|
78
78
|
end
|
79
|
+
|
80
|
+
def get_translation translation
|
81
|
+
I18n.t(translation, :scope => [:gflash, :titles])
|
82
|
+
end
|
79
83
|
end
|
80
84
|
end
|
data/lib/gritter/version.rb
CHANGED
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
7
|
+
- 6
|
8
|
+
- 0
|
9
|
+
version: 0.6.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Robin Brouwer
|
@@ -19,7 +19,7 @@ date: 2011-02-02 00:00:00 +01:00
|
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|
22
|
-
description: This Ruby on Rails gem allows you to easily add Growl-like notifications to your application using a
|
22
|
+
description: This Ruby on Rails gem allows you to easily add Growl-like notifications to your application using a jQuery plugin called 'gritter'.
|
23
23
|
email:
|
24
24
|
- robin@45north.nl
|
25
25
|
executables: []
|
@@ -36,6 +36,7 @@ files:
|
|
36
36
|
- gritter.gemspec
|
37
37
|
- init.rb
|
38
38
|
- lib/gritter.rb
|
39
|
+
- lib/gritter/assets/gflash.en.yml
|
39
40
|
- lib/gritter/assets/images/error.png
|
40
41
|
- lib/gritter/assets/images/gritter-close-ie6.gif
|
41
42
|
- lib/gritter/assets/images/gritter-long.png
|