growlyflash 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MTk4OGQ3ZGM2Y2JlNzZiNTE5MDY2ODQzODc4ODRjMjBjN2Q5YzdhMA==
4
+ NGNhYTdjMDY2NzNiMTQ0OTg2NDg2ZTg2NmNmZWNkN2NiNmMwODc2MA==
5
5
  data.tar.gz: !binary |-
6
- MTZmNTliNjdmM2IxMjY2MzkzODEyMzQ0MzgxNDM4ODEwYWRkOGY5ZA==
6
+ ZTEzN2IyNDY0YTE3NDI0NjJjNWI2ZmY0YmEwYzdiYWQzMmQ5ODgzNA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- N2U4ODA2MDczYTQ0ZDE5NDE1MDMxNzAxMmNlOTEwMDkzZDgzMTk3NWQxOTJk
10
- ZjRhNjc4NDc4YmEzMWY3M2M4NmZmNzkwMjgyODhiZjJhMzM1NTY2OWFlMzU3
11
- NWViM2RhMzg1ODM5Zjg0OTQzM2MxM2RmMGU0OGE3ODVmOTVjOTM=
9
+ OGIyMDQ5YmJkM2FlZmI0YTAzZTc3ZWU1MDMwNzA3ODYzYmFlNzYwN2ZhZTE5
10
+ OGZlY2ZmMjdjMTliODAzYWJjZWI3NjMxNmUxOTM4NzNiNTIzM2ZiMGZmZTM5
11
+ NGNjMTQ3YzQyZTJkOTcwOTE0MjU0NWQ4ZjI5NDQ1MWZhZDdlYzY=
12
12
  data.tar.gz: !binary |-
13
- ZDRmNTk4ZDdhMDY0MTk0MzU3NjRkN2Q5ZjQ2OWVkZTRlMmZiZGRhZjA4ZTFm
14
- N2JlOGIzODE2NDhhNzc3MDM5OTVkOTY3ZDRlZjY1NjgxOTYzZjgzOTI2NjNk
15
- MDVmNjVmMTRiNDA2Yzk2MTY0NDRjNjgwMWFlNWUzNGNhYmIzNzM=
13
+ Y2Y0Zjk5MzVhZTdkZGY1OGQwMThhODZjY2JiZDNlYTIyNDVjY2RiYTBkMWVj
14
+ MjY3Y2RmMjM2OGFmYWI5ZDcyNTJiYzA3NDFiNDk5Yzc5YjE2NWYyOWM3MmY5
15
+ MzlmM2YwZWJmY2QwYWI2ZTgzY2EzOWIyNjBjNzFjMDU0MWYwOTA=
@@ -6,11 +6,11 @@ require 'growlyflash/version'
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "growlyflash"
8
8
  spec.version = Growlyflash::VERSION
9
- spec.authors = ["Tõnis Simo"]
9
+ spec.authors = ["Tõnis Simo"]
10
10
  spec.email = ["anton.estum@gmail.com"]
11
11
  spec.homepage = "https://github.com/tonissimo/growlyflash"
12
12
  spec.summary = %q{Tiny gem which provides growl-styled flash messages for Ruby on Rails with Bootstrap.}
13
- spec.description = %q{For XHR requests flash messages are transfering in 'X-Messages' headers, otherwise they are storing in js variables.}
13
+ spec.description = %q{Tiny gem which provides growl-styled flash messages for Ruby on Rails with Bootstrap. For XHR requests flash messages are transfering in 'X-Messages' headers, otherwise they are storing in js variables.}
14
14
 
15
15
  spec.files = `git ls-files`.split($/)
16
16
  spec.require_paths = %w(lib vendor)
@@ -21,4 +21,4 @@ Gem::Specification.new do |spec|
21
21
  spec.add_development_dependency "rails", '>= 3.2.0'
22
22
  spec.add_development_dependency 'coffee-rails', '~> 3.2.1'
23
23
  spec.add_development_dependency "bundler", "~> 1.3"
24
- end
24
+ end
@@ -4,19 +4,9 @@ require "growlyflash/version"
4
4
  require "uri"
5
5
 
6
6
  module Growlyflash
7
- # class << self
8
- # def logger
9
- # @@logger ||= nil
10
- # end
11
- #
12
- # def logger=(logger)
13
- # @@logger = logger
14
- # end
15
- # end
16
7
 
17
8
  module XMessageHeaders
18
9
  def flash_to_headers
19
- # logger.info(response.headers)
20
10
  xmessage = URI.escape(Hash[flash].to_json) # URI escape to fix strange things with headers encoding
21
11
  response.headers['X-Message'] = xmessage
22
12
  flash.discard # discard flash to prevent it appear again after refreshing page
@@ -28,6 +18,7 @@ module Growlyflash
28
18
  end
29
19
  end
30
20
 
21
+
31
22
  module NoticeHelpers
32
23
  def growlyflash_static_notices
33
24
  return nil unless flash.any?
@@ -35,10 +26,10 @@ module Growlyflash
35
26
  end
36
27
  end
37
28
 
38
- class Engine < ::Rails::Engine
29
+
30
+ class Engine < ::Rails::Engine
39
31
  initializer :growlyflash_xmessage_headers do |config|
40
- # Growlyflash.logger = ::Rails.logger
41
-
32
+
42
33
  ActionController::Base.class_eval do
43
34
  include XMessageHeaders
44
35
  helper NoticeHelpers
@@ -48,5 +39,4 @@ module Growlyflash
48
39
 
49
40
  end
50
41
  end
51
-
52
42
  end
@@ -1,3 +1,3 @@
1
1
  module Growlyflash
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -1,8 +1,6 @@
1
1
  #= require growlyflash/bootstrap-growl
2
2
 
3
- # unless $.Growlyflash then $.Growlyflash = $.bootstrapGrowl
4
-
5
- root = global ? window
3
+ root = window ? this
6
4
 
7
5
  class Growlyflash
8
6
  TYPE_MAPPING =
@@ -10,31 +8,49 @@ class Growlyflash
10
8
  error : 'error'
11
9
  notice : 'info'
12
10
  success: 'success'
13
-
11
+
14
12
  constructor: (@context) ->
15
- @growl(window.flashes) if window.flashes?
13
+ @flash_log = []
14
+ @growl window.flashes if window.flashes?
16
15
  $(@context).on 'ajax:complete ajaxComplete', @ajax_complete
17
16
 
18
17
  growl: (flashes) ->
19
18
  for type, msg of flashes when msg?
19
+ @log type:type, msg:msg
20
20
  $.bootstrapGrowl msg, type: TYPE_MAPPING[type]
21
21
 
22
+ log: (xmessage) -> @flash_log.push(xmessage)
23
+ log_is_not_empty: -> @flash_log.length > 0
24
+ purge_log: ->
25
+ @flash_log = []
26
+ true
27
+
22
28
  messages: (flashes) ->
23
29
  { type:type, msg:msg } for type, msg of flashes
24
30
 
25
31
  ajax_complete: (e, response, settings) =>
26
- xmessage = @get_x_message.call response
27
- if xmessage?
28
- flashes = $.parseJSON xmessage
29
- @growl flashes
30
- true
32
+ if flashes = @get_x_message.call response
33
+ messages = @messages flashes
34
+ @reduce_duplicates messages, => @growl flashes
35
+ true
31
36
 
32
37
  get_x_message: ->
33
- encoded = @getResponseHeader('X-Message')
34
- decodeURIComponent encoded
35
-
38
+ encoded = @getResponseHeader 'X-Message'
39
+ decoded = decodeURIComponent encoded
40
+ $.parseJSON decoded if decoded?
41
+
42
+ reduce_duplicates: (messages, callback) ->
43
+ if @log_is_not_empty()
44
+ return @purge_log unless @get_log_matches messages
45
+ do callback
46
+
47
+ get_log_matches: (messages) ->
48
+ last_log = @flashes_log.slice -messages.length
49
+ not_matches = 0
50
+ not_matches++ for id, f of messages when (last_log[id].type isnt f.type) and (last_log[id].msg isnt f.msg)
51
+ not_matches > 0
36
52
 
37
53
  root.Growlyflash = Growlyflash
38
54
 
39
55
  jQuery ->
40
- growlyflash = new Growlyflash document
56
+ new Growlyflash document
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: growlyflash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
- - Tõnis Simo
7
+ - Tõnis Simo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
@@ -80,8 +80,9 @@ dependencies:
80
80
  - - ~>
81
81
  - !ruby/object:Gem::Version
82
82
  version: '1.3'
83
- description: For XHR requests flash messages are transfering in 'X-Messages' headers,
84
- otherwise they are storing in js variables.
83
+ description: Tiny gem which provides growl-styled flash messages for Ruby on Rails
84
+ with Bootstrap. For XHR requests flash messages are transfering in 'X-Messages'
85
+ headers, otherwise they are storing in js variables.
85
86
  email:
86
87
  - anton.estum@gmail.com
87
88
  executables: []