gritter 1.0.1 → 1.0.2

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,6 +1,6 @@
1
1
  # gritter
2
2
 
3
- version 1.0.1
3
+ version 1.0.2
4
4
  Robin Brouwer
5
5
  Daniël Zwijnenburg
6
6
  45north
@@ -17,7 +17,7 @@ Also check out that branch, because the newer version of gritter inside this gem
17
17
 
18
18
  You can use this gem by putting the following inside your Gemfile:
19
19
 
20
- gem "gritter", "1.0.1"
20
+ gem "gritter", "1.0.2"
21
21
 
22
22
  Now generate the locale for gritter:
23
23
 
@@ -35,6 +35,10 @@ And that's it!
35
35
 
36
36
  ## Changes
37
37
 
38
+ Version 1.0.2 changes (03/09/2012):
39
+
40
+ - Merged pull request #22 (namespaced controllers gflash fix).
41
+
38
42
  Version 1.0.1 changes (23/01/2012):
39
43
 
40
44
  - Fixed gflash(:js => true) in Ruby 1.9.2 and 1.9.3.
@@ -233,7 +237,20 @@ This is done inside the Controller and works like this:
233
237
  gflash :success => { :value => true, :time => 2000, :class_name => "my_class", :sticky => true }
234
238
  gflash :error => { :value => "Custom error", :time => 3000, :class_name => "my_error_class", :sticky => false }
235
239
 
236
- When you don't pass a `:value` it uses the locale. Same goes for when you pass `true` to `:value`.
240
+ 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:
241
+
242
+ def create
243
+ @user = User.new(params[:user])
244
+ if @user.save
245
+ gflash :success => { :value => "Account has been created!", :time => 5000 },
246
+ :notice => { :value => "You have received an e-mail notification.", :sticky => true }
247
+ redirect_to :root
248
+ else
249
+ gflash :error => { :value => "Something went wrong.", :time => 4000 },
250
+ :warning => { :value => "Some fields weren't filled in correctly.", :time => 7000 }
251
+ render :new
252
+ end
253
+ end
237
254
 
238
255
  You can also use gflash directly inside the `redirect_to` method.
239
256
 
@@ -251,6 +268,27 @@ You can also use gflash directly inside the `redirect_to` method.
251
268
 
252
269
  And that's how you add gflash to your Rails application!
253
270
 
271
+ ## Copyright
272
+
273
+ Copyright (C) 2010 Robin Brouwer
274
+
275
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
276
+ this software and associated documentation files (the "Software"), to deal in
277
+ the Software without restriction, including without limitation the rights to
278
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
279
+ of the Software, and to permit persons to whom the Software is furnished to do
280
+ so, subject to the following conditions:
281
+
282
+ The above copyright notice and this permission notice shall be included in all
283
+ copies or substantial portions of the Software.
284
+
285
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
286
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
287
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
288
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
289
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
290
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
291
+ SOFTWARE.
254
292
 
255
293
  ## Special Thanks
256
294
 
@@ -1,50 +1,51 @@
1
- module Gritter
2
- module Gflash
3
- def redirect_to(options = {}, response_status_and_flash = {})
4
- if response_status_and_flash.has_key?(:gflash)
5
- gflash(response_status_and_flash[:gflash])
6
- response_status_and_flash.delete(:gflash)
7
- end
8
- super(options, response_status_and_flash)
9
- end
10
-
11
- def gflash *args
12
- session[:gflash] ||= {}
13
- options = args.extract_options!
14
-
15
- if args.present?
16
- args.each do |key|
17
- gflash_push(key, gflash_translation(key))
18
- end
19
- end
20
-
21
- options.each do |key, value|
22
- if value.is_a?(Hash)
23
- if value.has_key?(:value)
24
- value[:value] = gflash_text(key, value[:value])
25
- else
26
- value[:value] = gflash_translation(key)
27
- end
28
- else
29
- value = gflash_text(key, value)
30
- end
31
- gflash_push(key, value)
32
- end
33
- end
34
-
35
- private
36
-
37
- def gflash_text(key, value)
38
- value == true ? gflash_translation(key) : value
39
- end
40
-
41
- def gflash_push(key, value)
42
- session[:gflash][key] ||= []
43
- session[:gflash][key].push(value)
44
- end
45
-
46
- def gflash_translation(key)
47
- I18n.t("gflash.#{params[:controller]}.#{params[:action]}.#{key}")
48
- end
49
- end
1
+ module Gritter
2
+ module Gflash
3
+ def redirect_to(options = {}, response_status_and_flash = {})
4
+ if response_status_and_flash.has_key?(:gflash)
5
+ gflash(response_status_and_flash[:gflash])
6
+ response_status_and_flash.delete(:gflash)
7
+ end
8
+ super(options, response_status_and_flash)
9
+ end
10
+
11
+ def gflash *args
12
+ session[:gflash] ||= {}
13
+ options = args.extract_options!
14
+
15
+ if args.present?
16
+ args.each do |key|
17
+ gflash_push(key, gflash_translation(key))
18
+ end
19
+ end
20
+
21
+ options.each do |key, value|
22
+ if value.is_a?(Hash)
23
+ if value.has_key?(:value)
24
+ value[:value] = gflash_text(key, value[:value])
25
+ else
26
+ value[:value] = gflash_translation(key)
27
+ end
28
+ else
29
+ value = gflash_text(key, value)
30
+ end
31
+ gflash_push(key, value)
32
+ end
33
+ end
34
+
35
+ private
36
+
37
+ def gflash_text(key, value)
38
+ value == true ? gflash_translation(key) : value
39
+ end
40
+
41
+ def gflash_push(key, value)
42
+ session[:gflash][key] ||= []
43
+ session[:gflash][key].push(value)
44
+ end
45
+
46
+ def gflash_translation(key)
47
+ i18n_key = "gflash.#{params[:controller]}.#{params[:action]}.#{key}"
48
+ I18n.t(i18n_key.gsub(/\//, "."), :default => i18n_key.to_sym)
49
+ end
50
+ end
50
51
  end
@@ -1,89 +1,89 @@
1
- module Gritter
2
- module Helpers
3
- def add_gritter text, *args
4
- options = args.extract_options!
5
- options[:title] = "Notification" if options[:title].blank?
6
- options[:image] = ::Rails.version < "3.1" ? "/images/gritter/#{options[:image]}.png" : asset_path("#{options[:image]}.png") if %w(success warning error notice progress).include?(options[:image].to_s)
7
- notification = ["jQuery(function(){"]
8
- notification.push("jQuery.gritter.add({")
9
- notification.push("image:'#{options[:image]}',") if options[:image].present?
10
- notification.push("sticky:#{options[:sticky]},") if options[:sticky].present?
11
- notification.push("time:#{options[:time]},") if options[:time].present?
12
- notification.push("class_name:'#{options[:class_name]}',") if options[:class_name].present?
13
- notification.push("before_open:function(e){#{options[:before_open]}},") if options[:before_open].present?
14
- notification.push("after_open:function(e){#{options[:after_open]}},") if options[:after_open].present?
15
- notification.push("before_close:function(e){#{options[:before_close]}},") if options[:before_close].present?
16
- notification.push("after_close:function(e){#{options[:after_close]}},") if options[:after_close].present?
17
- notification.push("title:'#{escape_javascript(options[:title])}',")
18
- notification.push("text:'#{escape_javascript(text)}'")
19
- notification.push("});")
20
- notification.push("});")
21
- text.present? ? notification.join.html_safe : nil
22
- end
23
-
24
- def remove_gritter *args
25
- options = args.extract_options!
26
- removed = ["jQuery.gritter.removeAll({"]
27
- removed.push("before_close:function(e){#{options[:before_close]}},") if options[:before_close].present?
28
- removed.push("after_close:function(e){#{options[:after_close]}},") if options[:after_close].present?
29
- removed.push("});")
30
- removed.join.html_safe
31
- end
32
-
33
- def extend_gritter *args
34
- options = args.extract_options!
35
- options[:fade_in_speed] = "'#{options[:fade_in_speed]}'" if options[:fade_in_speed].is_a?(String)
36
- options[:fade_out_speed] = "'#{options[:fade_out_speed]}'" if options[:fade_out_speed].is_a?(String)
37
- options[:position] = "'#{options[:position].to_s.gsub("_", "-")}'" if options[:position]
38
- extended = ["jQuery.extend($.gritter.options,{"]
39
- extended.push("fade_in_speed:#{options[:fade_in_speed]},") if options[:fade_in_speed].present?
40
- extended.push("fade_out_speed:#{options[:fade_out_speed]},") if options[:fade_out_speed].present?
41
- extended.push("time:#{options[:time]},") if options[:time].present?
42
- extended.push("position:#{options[:position]}") if options[:position].present?
43
- extended.push("});")
44
- extended.join.html_safe
45
- end
46
-
47
- def gflash *args
48
- if session[:gflash].present?
49
- options = args.extract_options!
50
- titles = gflash_titles(options)
51
- flashes = []
52
- session[:gflash].each do |key, value|
53
- value.each do |gflash_value|
54
- gritter_options = { :image => key, :title => titles[key] }
55
- if gflash_value.is_a?(Hash)
56
- text = gflash_value.has_key?(:value) ? (gflash_value[:value] and gflash_value.delete(:value)) : nil
57
- gritter_options.merge!(gflash_value)
58
- else
59
- text = gflash_value
60
- end
61
-
62
- flashes.push(add_gritter(text, gritter_options))
63
- end
64
- end
65
- session[:gflash] = nil
66
- options[:js] ? flashes.join("\n") : js(flashes).html_safe
67
- end
68
- end
69
-
70
- def js *args
71
- javascript_tag(args.join("\n"))
72
- end
73
-
74
- private
75
-
76
- def gflash_titles *args
77
- options = args.extract_options!
78
- titles = { :success => get_translation(:success), :warning => get_translation(:warning), :error => get_translation(:error), :notice => get_translation(:notice), :progress => get_translation(:progress) }
79
- options.each do |key, value|
80
- titles[key] = value if titles.has_key?(key)
81
- end
82
- titles
83
- end
84
-
85
- def get_translation translation
86
- I18n.t(translation, :scope => [:gflash, :titles])
87
- end
88
- end
89
- end
1
+ module Gritter
2
+ module Helpers
3
+ def add_gritter text, *args
4
+ options = args.extract_options!
5
+ options[:title] = "Notification" if options[:title].blank?
6
+ options[:image] = asset_path("#{options[:image]}#{options[:image] == 'progress' ? '.gif' : '.png'}") if %w(success warning error notice progress).include?(options[:image].to_s)
7
+ notification = ["jQuery(function(){"]
8
+ notification.push("jQuery.gritter.add({")
9
+ notification.push("image:'#{options[:image]}',") if options[:image].present?
10
+ notification.push("sticky:#{options[:sticky]},") if options[:sticky].present?
11
+ notification.push("time:#{options[:time]},") if options[:time].present?
12
+ notification.push("class_name:'#{options[:class_name]}',") if options[:class_name].present?
13
+ notification.push("before_open:function(e){#{options[:before_open]}},") if options[:before_open].present?
14
+ notification.push("after_open:function(e){#{options[:after_open]}},") if options[:after_open].present?
15
+ notification.push("before_close:function(e){#{options[:before_close]}},") if options[:before_close].present?
16
+ notification.push("after_close:function(e){#{options[:after_close]}},") if options[:after_close].present?
17
+ notification.push("title:'#{escape_javascript(options[:title])}',")
18
+ notification.push("text:'#{escape_javascript(text)}'")
19
+ notification.push("});")
20
+ notification.push("});")
21
+ text.present? ? notification.join.html_safe : nil
22
+ end
23
+
24
+ def remove_gritter *args
25
+ options = args.extract_options!
26
+ removed = ["jQuery.gritter.removeAll({"]
27
+ removed.push("before_close:function(e){#{options[:before_close]}},") if options[:before_close].present?
28
+ removed.push("after_close:function(e){#{options[:after_close]}},") if options[:after_close].present?
29
+ removed.push("});")
30
+ removed.join.html_safe
31
+ end
32
+
33
+ def extend_gritter *args
34
+ options = args.extract_options!
35
+ options[:fade_in_speed] = "'#{options[:fade_in_speed]}'" if options[:fade_in_speed].is_a?(String)
36
+ options[:fade_out_speed] = "'#{options[:fade_out_speed]}'" if options[:fade_out_speed].is_a?(String)
37
+ options[:position] = "'#{options[:position].to_s.gsub("_", "-")}'" if options[:position]
38
+ extended = ["jQuery.extend($.gritter.options,{"]
39
+ extended.push("fade_in_speed:#{options[:fade_in_speed]},") if options[:fade_in_speed].present?
40
+ extended.push("fade_out_speed:#{options[:fade_out_speed]},") if options[:fade_out_speed].present?
41
+ extended.push("time:#{options[:time]},") if options[:time].present?
42
+ extended.push("position:#{options[:position]}") if options[:position].present?
43
+ extended.push("});")
44
+ extended.join.html_safe
45
+ end
46
+
47
+ def gflash *args
48
+ if session[:gflash].present?
49
+ options = args.extract_options!
50
+ titles = gflash_titles(options)
51
+ flashes = []
52
+ session[:gflash].each do |key, value|
53
+ value.each do |gflash_value|
54
+ gritter_options = { :image => key, :title => titles[key] }
55
+ if gflash_value.is_a?(Hash)
56
+ text = gflash_value.has_key?(:value) ? (gflash_value[:value] and gflash_value.delete(:value)) : nil
57
+ gritter_options.merge!(gflash_value)
58
+ else
59
+ text = gflash_value
60
+ end
61
+
62
+ flashes.push(add_gritter(text, gritter_options))
63
+ end
64
+ end
65
+ session[:gflash] = nil
66
+ options[:js] ? flashes.join("\n") : js(flashes).html_safe
67
+ end
68
+ end
69
+
70
+ def js *args
71
+ javascript_tag(args.join("\n"))
72
+ end
73
+
74
+ private
75
+
76
+ def gflash_titles *args
77
+ options = args.extract_options!
78
+ titles = { :success => get_translation(:success), :warning => get_translation(:warning), :error => get_translation(:error), :notice => get_translation(:notice), :progress => get_translation(:progress) }
79
+ options.each do |key, value|
80
+ titles[key] = value if titles.has_key?(key)
81
+ end
82
+ titles
83
+ end
84
+
85
+ def get_translation translation
86
+ I18n.t(translation, :scope => [:gflash, :titles])
87
+ end
88
+ end
89
+ end
@@ -1,3 +1,3 @@
1
1
  module Gritter
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
metadata CHANGED
@@ -1,25 +1,35 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: gritter
3
- version: !ruby/object:Gem::Version
4
- version: 1.0.1
5
- prerelease:
3
+ version: !ruby/object:Gem::Version
4
+ hash: 19
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 2
10
+ version: 1.0.2
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - Robin Brouwer
9
- - Daniël Zwijnenburg
14
+ - "Dani\xC3\xABl Zwijnenburg"
10
15
  autorequire:
11
16
  bindir: bin
12
17
  cert_chain: []
13
- date: 2012-01-23 00:00:00.000000000Z
18
+
19
+ date: 2012-09-03 00:00:00 +02:00
20
+ default_executable:
14
21
  dependencies: []
15
- description: This Ruby on Rails gem allows you to easily add Growl-like notifications
16
- to your application using a jQuery plugin called 'gritter'.
17
- email:
22
+
23
+ description: This Ruby on Rails gem allows you to easily add Growl-like notifications to your application using a jQuery plugin called 'gritter'.
24
+ email:
18
25
  - robin@45north.nl
19
26
  executables: []
27
+
20
28
  extensions: []
29
+
21
30
  extra_rdoc_files: []
22
- files:
31
+
32
+ files:
23
33
  - .gitignore
24
34
  - Gemfile
25
35
  - README.md
@@ -45,28 +55,39 @@ files:
45
55
  - lib/gritter/helpers.rb
46
56
  - lib/gritter/railtie.rb
47
57
  - lib/gritter/version.rb
58
+ has_rdoc: true
48
59
  homepage: http://www.45north.nl
49
60
  licenses: []
61
+
50
62
  post_install_message:
51
63
  rdoc_options: []
52
- require_paths:
64
+
65
+ require_paths:
53
66
  - lib
54
- required_ruby_version: !ruby/object:Gem::Requirement
67
+ required_ruby_version: !ruby/object:Gem::Requirement
55
68
  none: false
56
- requirements:
57
- - - ! '>='
58
- - !ruby/object:Gem::Version
59
- version: '0'
60
- required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ hash: 3
73
+ segments:
74
+ - 0
75
+ version: "0"
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
77
  none: false
62
- requirements:
63
- - - ! '>='
64
- - !ruby/object:Gem::Version
65
- version: '0'
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ hash: 3
82
+ segments:
83
+ - 0
84
+ version: "0"
66
85
  requirements: []
86
+
67
87
  rubyforge_project: nowarning
68
- rubygems_version: 1.8.10
88
+ rubygems_version: 1.3.7
69
89
  signing_key:
70
90
  specification_version: 3
71
91
  summary: Growl notifications for your Rails application.
72
92
  test_files: []
93
+