gritter 1.0.3 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,9 +6,9 @@ Gem::Specification.new do |s|
6
6
  s.name = "gritter"
7
7
  s.version = Gritter::VERSION
8
8
  s.platform = Gem::Platform::RUBY
9
- s.authors = ["Robin Brouwer", "Daniël Zwijnenburg"]
10
- s.email = ["robin@45north.nl"]
11
- s.homepage = "http://www.45north.nl"
9
+ s.authors = ["Robin Brouwer"]
10
+ s.email = ["robin@montblanc.nl"]
11
+ s.homepage = "http://www.montblanc.nl"
12
12
  s.summary = %q{Growl notifications for your Rails application.}
13
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
 
@@ -10,6 +10,14 @@ en:
10
10
  error: "Error"
11
11
  progress: "Progress"
12
12
  #
13
+ # Add default gflash messages:
14
+ # defaults:
15
+ # success: "This is a notification"
16
+ # error: "Something went wrong"
17
+ # create:
18
+ # success: "Successfully created!"
19
+ # error: "Something went wrong. Please take a look at the form to see what went wrong."
20
+ #
13
21
  # Add gflash messages for controller actions:
14
22
  # products:
15
23
  # create:
@@ -4,6 +4,15 @@ require 'gritter/engine'
4
4
  require 'fileutils'
5
5
 
6
6
  module Gritter
7
+ @rails_flash_fallback = false
8
+
9
+ def self.rails_flash_fallback
10
+ @rails_flash_fallback
11
+ end
12
+ def self.rails_flash_fallback=(val)
13
+ @rails_flash_fallback = val
14
+ end
15
+
7
16
  def self.initialize
8
17
  return if @initialized
9
18
  raise "ActionController is not available yet." unless defined?(ActionController)
@@ -1,51 +1,86 @@
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
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.size == 1 && args.first.is_a?(Array)
16
+ args = args.first
17
+ end
18
+
19
+ flash_now = args.include?(:now)
20
+ args.delete(:now) if flash_now
21
+
22
+ if args.present?
23
+ args.each do |key|
24
+ gflash_push(key, gflash_translation(key, options[:locals]), flash_now)
25
+ end
26
+ end
27
+
28
+ options.except(:locals).each do |key, value|
29
+ if value.is_a?(Hash)
30
+ if value.has_key?(:value)
31
+ value[:value] = gflash_text(key, value[:value], value[:locals])
32
+ else
33
+ value[:value] = gflash_translation(key, value[:locals])
34
+ end
35
+ else
36
+ value = gflash_text(key, value, options[:locals])
37
+ end
38
+ gflash_push(key, value, flash_now)
39
+ end
40
+ end
41
+
42
+ private
43
+
44
+ def gflash_text(key, value, options={})
45
+ value == true ? gflash_translation(key, options) : value
46
+ end
47
+
48
+ def gflash_push(key, value, now=false)
49
+ session[:gflash][key] ||= []
50
+ session[:gflash][key].push(value)
51
+
52
+ if Gritter.rails_flash_fallback
53
+ if now
54
+ flash.now[key] ||= []
55
+ flash.now[key].push(value.is_a?(Hash) ? value[:value] : value)
56
+ else
57
+ flash[key] ||= []
58
+ flash[key].push(value.is_a?(Hash) ? value[:value] : value)
59
+ end
60
+ end
61
+ end
62
+
63
+ def gflash_translation(key, options)
64
+ options ||= {}
65
+
66
+ i18n_default_key = "gflash.defaults.#{key}"
67
+ i18n_default_action_key = "gflash.defaults.#{params[:action]}.#{key}"
68
+ i18n_key = "gflash.#{params[:controller]}.#{params[:action]}.#{key}"
69
+ i18n_key.gsub!(/\//, ".")
70
+
71
+ begin
72
+ options[:raise] = true
73
+ translation = I18n.t(i18n_key, options)
74
+ rescue I18n::MissingTranslationData
75
+ begin
76
+ translation = I18n.t(i18n_default_action_key, options)
77
+ rescue I18n::MissingTranslationData
78
+ options.delete(:raise)
79
+ translation = I18n.t(i18n_default_key, options)
80
+ end
81
+ end
82
+
83
+ translation
84
+ end
85
+ end
51
86
  end
@@ -1,90 +1,92 @@
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 = Array.new
8
- notification.push("jQuery(function(){") if !options[:nodom_wrap].present?
9
- notification.push("jQuery.gritter.add({")
10
- notification.push("image:'#{options[:image]}',") if options[:image].present?
11
- notification.push("sticky:#{options[:sticky]},") if options[:sticky].present?
12
- notification.push("time:#{options[:time]},") if options[:time].present?
13
- notification.push("class_name:'#{options[:class_name]}',") if options[:class_name].present?
14
- notification.push("before_open:function(e){#{options[:before_open]}},") if options[:before_open].present?
15
- notification.push("after_open:function(e){#{options[:after_open]}},") if options[:after_open].present?
16
- notification.push("before_close:function(e){#{options[:before_close]}},") if options[:before_close].present?
17
- notification.push("after_close:function(e){#{options[:after_close]}},") if options[:after_close].present?
18
- notification.push("title:'#{escape_javascript(options[:title])}',")
19
- notification.push("text:'#{escape_javascript(text)}'")
20
- notification.push("});")
21
- notification.push("});") if !options[:nodom_wrap].present?
22
- text.present? ? notification.join.html_safe : nil
23
- end
24
-
25
- def remove_gritter *args
26
- options = args.extract_options!
27
- removed = ["jQuery.gritter.removeAll({"]
28
- removed.push("before_close:function(e){#{options[:before_close]}},") if options[:before_close].present?
29
- removed.push("after_close:function(e){#{options[:after_close]}},") if options[:after_close].present?
30
- removed.push("});")
31
- removed.join.html_safe
32
- end
33
-
34
- def extend_gritter *args
35
- options = args.extract_options!
36
- options[:fade_in_speed] = "'#{options[:fade_in_speed]}'" if options[:fade_in_speed].is_a?(String)
37
- options[:fade_out_speed] = "'#{options[:fade_out_speed]}'" if options[:fade_out_speed].is_a?(String)
38
- options[:position] = "'#{options[:position].to_s.gsub("_", "-")}'" if options[:position]
39
- extended = ["jQuery.extend($.gritter.options,{"]
40
- extended.push("fade_in_speed:#{options[:fade_in_speed]},") if options[:fade_in_speed].present?
41
- extended.push("fade_out_speed:#{options[:fade_out_speed]},") if options[:fade_out_speed].present?
42
- extended.push("time:#{options[:time]},") if options[:time].present?
43
- extended.push("position:#{options[:position]}") if options[:position].present?
44
- extended.push("});")
45
- extended.join.html_safe
46
- end
47
-
48
- def gflash *args
49
- if session[:gflash].present?
50
- options = args.extract_options!
51
- titles = gflash_titles(options)
52
- flashes = []
53
- session[:gflash].each do |key, value|
54
- value.each do |gflash_value|
55
- gritter_options = { :image => key, :title => titles[key] }
56
- if gflash_value.is_a?(Hash)
57
- text = gflash_value.has_key?(:value) ? (gflash_value[:value] and gflash_value.delete(:value)) : nil
58
- gritter_options.merge!(gflash_value)
59
- else
60
- text = gflash_value
61
- end
62
-
63
- flashes.push(add_gritter(text, gritter_options))
64
- end
65
- end
66
- session[:gflash] = nil
67
- options[:js] ? flashes.join("\n") : js(flashes).html_safe
68
- end
69
- end
70
-
71
- def js *args
72
- javascript_tag(args.join("\n"))
73
- end
74
-
75
- private
76
-
77
- def gflash_titles *args
78
- options = args.extract_options!
79
- titles = { :success => get_translation(:success), :warning => get_translation(:warning), :error => get_translation(:error), :notice => get_translation(:notice), :progress => get_translation(:progress) }
80
- options.each do |key, value|
81
- titles[key] = value if titles.has_key?(key)
82
- end
83
- titles
84
- end
85
-
86
- def get_translation translation
87
- I18n.t(translation, :scope => [:gflash, :titles])
88
- end
89
- end
90
- 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].to_s == 'progress' ? '.gif' : '.png'}") if %w(success warning error notice progress).include?(options[:image].to_s)
7
+ notification = Array.new
8
+ notification.push("jQuery(function(){") if options[:nodom_wrap].blank?
9
+ notification.push("jQuery.gritter.add({")
10
+ notification.push("image:'#{options[:image]}',") if options[:image].present?
11
+ notification.push("sticky:#{options[:sticky]},") if options[:sticky].present?
12
+ notification.push("time:#{options[:time]},") if options[:time].present?
13
+ notification.push("class_name:'#{options[:class_name]}',") if options[:class_name].present?
14
+ notification.push("before_open:function(e){#{options[:before_open]}},") if options[:before_open].present?
15
+ notification.push("after_open:function(e){#{options[:after_open]}},") if options[:after_open].present?
16
+ notification.push("before_close:function(e){#{options[:before_close]}},") if options[:before_close].present?
17
+ notification.push("after_close:function(e){#{options[:after_close]}},") if options[:after_close].present?
18
+ notification.push("title:'#{escape_javascript(options[:title])}',")
19
+ notification.push("text:'#{escape_javascript(text)}'")
20
+ notification.push("});")
21
+ notification.push("});") if options[:nodom_wrap].blank?
22
+ text.present? ? notification.join.html_safe : nil
23
+ end
24
+
25
+ def remove_gritter *args
26
+ options = args.extract_options!
27
+ removed = ["jQuery.gritter.removeAll({"]
28
+ removed.push("before_close:function(e){#{options[:before_close]}},") if options[:before_close].present?
29
+ removed.push("after_close:function(e){#{options[:after_close]}},") if options[:after_close].present?
30
+ removed.push("});")
31
+ removed.join.html_safe
32
+ end
33
+
34
+ def extend_gritter *args
35
+ options = args.extract_options!
36
+ options[:fade_in_speed] = "'#{options[:fade_in_speed]}'" if options[:fade_in_speed].is_a?(String)
37
+ options[:fade_out_speed] = "'#{options[:fade_out_speed]}'" if options[:fade_out_speed].is_a?(String)
38
+ options[:position] = "'#{options[:position].to_s.gsub("_", "-")}'" if options[:position]
39
+ extended = ["jQuery.extend($.gritter.options,{"]
40
+ extended.push("fade_in_speed:#{options[:fade_in_speed]},") if options[:fade_in_speed].present?
41
+ extended.push("fade_out_speed:#{options[:fade_out_speed]},") if options[:fade_out_speed].present?
42
+ extended.push("time:#{options[:time]},") if options[:time].present?
43
+ extended.push("position:#{options[:position]}") if options[:position].present?
44
+ extended.push("});")
45
+ extended.join.html_safe
46
+ end
47
+
48
+ def gflash *args
49
+ if session[:gflash].present?
50
+ options = args.extract_options!
51
+ nodom_wrap = options[:nodom_wrap]
52
+ options.delete(:nodom_wrap)
53
+
54
+ titles = gflash_titles(options)
55
+ flashes = []
56
+ session[:gflash].each do |key, value|
57
+ value.each do |gflash_value|
58
+ gritter_options = { :image => key, :title => titles[key], :nodom_wrap => nodom_wrap }
59
+ if gflash_value.is_a?(Hash)
60
+ text = gflash_value.has_key?(:value) ? (gflash_value[:value] and gflash_value.delete(:value)) : nil
61
+ gritter_options.merge!(gflash_value)
62
+ else
63
+ text = gflash_value
64
+ end
65
+ flashes.push(add_gritter(text, gritter_options))
66
+ end
67
+ end
68
+ session[:gflash] = nil
69
+ options[:js] ? flashes.join("\n") : js(flashes).html_safe
70
+ end
71
+ end
72
+
73
+ def js *args
74
+ javascript_tag(args.join("\n"))
75
+ end
76
+
77
+ private
78
+
79
+ def gflash_titles *args
80
+ options = args.extract_options!
81
+ titles = { :success => get_translation(:success), :warning => get_translation(:warning), :error => get_translation(:error), :notice => get_translation(:notice), :progress => get_translation(:progress) }
82
+ options.each do |key, value|
83
+ titles[key] = value if titles.has_key?(key)
84
+ end
85
+ titles
86
+ end
87
+
88
+ def get_translation translation
89
+ I18n.t(translation, :scope => [:gflash, :titles])
90
+ end
91
+ end
92
+ end
@@ -1,3 +1,3 @@
1
- module Gritter
2
- VERSION = "1.0.3"
1
+ module Gritter
2
+ VERSION = "1.1.0"
3
3
  end
File without changes
File without changes
@@ -374,7 +374,7 @@ window.Modernizr = function (a, b, c) {
374
374
  */
375
375
  _runSetup: function(){
376
376
 
377
- for(opt in $.gritter.options){
377
+ for(var opt in $.gritter.options){
378
378
  this[opt] = $.gritter.options[opt];
379
379
  }
380
380
  this._is_setup = 1;
metadata CHANGED
@@ -1,49 +1,27 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: gritter
3
- version: !ruby/object:Gem::Version
4
- hash: 17
5
- prerelease: false
6
- segments:
7
- - 1
8
- - 0
9
- - 3
10
- version: 1.0.3
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.0
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - Robin Brouwer
14
- - "Dani\xC3\xABl Zwijnenburg"
15
8
  autorequire:
16
9
  bindir: bin
17
10
  cert_chain: []
18
-
19
- date: 2013-01-26 00:00:00 +01:00
20
- default_executable:
11
+ date: 2014-01-31 00:00:00.000000000 Z
21
12
  dependencies: []
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:
25
- - robin@45north.nl
13
+ description: This Ruby on Rails gem allows you to easily add Growl-like notifications
14
+ to your application using a jQuery plugin called 'gritter'.
15
+ email:
16
+ - robin@montblanc.nl
26
17
  executables: []
27
-
28
18
  extensions: []
29
-
30
19
  extra_rdoc_files: []
31
-
32
- files:
33
- - .gitignore
20
+ files:
21
+ - ".gitignore"
34
22
  - Gemfile
35
23
  - README.md
36
24
  - Rakefile
37
- - app/assets/images/error.png
38
- - app/assets/images/gritter-close.png
39
- - app/assets/images/gritter.png
40
- - app/assets/images/ie-spacer.gif
41
- - app/assets/images/notice.png
42
- - app/assets/images/progress.gif
43
- - app/assets/images/success.png
44
- - app/assets/images/warning.png
45
- - app/assets/javascripts/gritter.js
46
- - app/assets/stylesheets/gritter.css.scss
47
25
  - gritter.gemspec
48
26
  - init.rb
49
27
  - lib/generators/gritter/USAGE
@@ -55,39 +33,37 @@ files:
55
33
  - lib/gritter/helpers.rb
56
34
  - lib/gritter/railtie.rb
57
35
  - lib/gritter/version.rb
58
- has_rdoc: true
59
- homepage: http://www.45north.nl
36
+ - vendor/assets/images/error.png
37
+ - vendor/assets/images/gritter-close.png
38
+ - vendor/assets/images/gritter.png
39
+ - vendor/assets/images/ie-spacer.gif
40
+ - vendor/assets/images/notice.png
41
+ - vendor/assets/images/progress.gif
42
+ - vendor/assets/images/success.png
43
+ - vendor/assets/images/warning.png
44
+ - vendor/assets/javascripts/gritter.js
45
+ - vendor/assets/stylesheets/gritter.css.scss
46
+ homepage: http://www.montblanc.nl
60
47
  licenses: []
61
-
48
+ metadata: {}
62
49
  post_install_message:
63
50
  rdoc_options: []
64
-
65
- require_paths:
51
+ require_paths:
66
52
  - lib
67
- required_ruby_version: !ruby/object:Gem::Requirement
68
- none: false
69
- requirements:
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ requirements:
70
55
  - - ">="
71
- - !ruby/object:Gem::Version
72
- hash: 3
73
- segments:
74
- - 0
75
- version: "0"
76
- required_rubygems_version: !ruby/object:Gem::Requirement
77
- none: false
78
- requirements:
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ requirements:
79
60
  - - ">="
80
- - !ruby/object:Gem::Version
81
- hash: 3
82
- segments:
83
- - 0
84
- version: "0"
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
85
63
  requirements: []
86
-
87
64
  rubyforge_project: nowarning
88
- rubygems_version: 1.3.7
65
+ rubygems_version: 2.2.1
89
66
  signing_key:
90
- specification_version: 3
67
+ specification_version: 4
91
68
  summary: Growl notifications for your Rails application.
92
69
  test_files: []
93
-