growlyflash 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/growlyflash.gemspec +1 -1
- data/lib/growlyflash.rb +46 -16
- data/lib/growlyflash/version.rb +1 -1
- data/vendor/assets/javascripts/growlyflash/bootstrap-growl.js.coffee +0 -2
- data/vendor/assets/javascripts/growlyflash/growlyflash.js.coffee +15 -26
- metadata +3 -6
- data/lib/growlyflash/controller.rb +0 -22
- data/lib/growlyflash/engine.rb +0 -6
- data/lib/growlyflash/helpers.rb +0 -11
- data/lib/growlyflash/railtie.rb +0 -14
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MTk4OGQ3ZGM2Y2JlNzZiNTE5MDY2ODQzODc4ODRjMjBjN2Q5YzdhMA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MTZmNTliNjdmM2IxMjY2MzkzODEyMzQ0MzgxNDM4ODEwYWRkOGY5ZA==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
N2U4ODA2MDczYTQ0ZDE5NDE1MDMxNzAxMmNlOTEwMDkzZDgzMTk3NWQxOTJk
|
10
|
+
ZjRhNjc4NDc4YmEzMWY3M2M4NmZmNzkwMjgyODhiZjJhMzM1NTY2OWFlMzU3
|
11
|
+
NWViM2RhMzg1ODM5Zjg0OTQzM2MxM2RmMGU0OGE3ODVmOTVjOTM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZDRmNTk4ZDdhMDY0MTk0MzU3NjRkN2Q5ZjQ2OWVkZTRlMmZiZGRhZjA4ZTFm
|
14
|
+
N2JlOGIzODE2NDhhNzc3MDM5OTVkOTY3ZDRlZjY1NjgxOTYzZjgzOTI2NjNk
|
15
|
+
MDVmNjVmMTRiNDA2Yzk2MTY0NDRjNjgwMWFlNWUzNGNhYmIzNzM=
|
data/growlyflash.gemspec
CHANGED
data/lib/growlyflash.rb
CHANGED
@@ -1,22 +1,52 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
require "growlyflash/version"
|
2
|
-
require "
|
3
|
-
require "growlyflash/helpers"
|
4
|
+
require "uri"
|
4
5
|
|
5
6
|
module Growlyflash
|
6
|
-
#
|
7
|
-
def
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
7
|
+
# class << self
|
8
|
+
# def logger
|
9
|
+
# @@logger ||= nil
|
10
|
+
# end
|
11
|
+
#
|
12
|
+
# def logger=(logger)
|
13
|
+
# @@logger = logger
|
14
|
+
# end
|
15
|
+
# end
|
16
|
+
|
17
|
+
module XMessageHeaders
|
18
|
+
def flash_to_headers
|
19
|
+
# logger.info(response.headers)
|
20
|
+
xmessage = URI.escape(Hash[flash].to_json) # URI escape to fix strange things with headers encoding
|
21
|
+
response.headers['X-Message'] = xmessage
|
22
|
+
flash.discard # discard flash to prevent it appear again after refreshing page
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
def is_xhr_request?
|
27
|
+
request.xhr?
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
module NoticeHelpers
|
32
|
+
def growlyflash_static_notices
|
33
|
+
return nil unless flash.any?
|
34
|
+
javascript_tag("window.flashes = #{ raw(Hash[ flash ].to_json) };", defer: 'defer')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
class Engine < ::Rails::Engine
|
39
|
+
initializer :growlyflash_xmessage_headers do |config|
|
40
|
+
# Growlyflash.logger = ::Rails.logger
|
41
|
+
|
42
|
+
ActionController::Base.class_eval do
|
43
|
+
include XMessageHeaders
|
44
|
+
helper NoticeHelpers
|
45
|
+
|
46
|
+
after_filter :flash_to_headers, if: :is_xhr_request?
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
13
50
|
end
|
14
|
-
end
|
15
|
-
|
16
|
-
if defined?(Rails)
|
17
|
-
require 'growlyflash/engine'
|
18
|
-
end
|
19
51
|
|
20
|
-
if defined?(Rails::Railtie)
|
21
|
-
require 'growlyflash/railtie'
|
22
52
|
end
|
data/lib/growlyflash/version.rb
CHANGED
@@ -11,41 +11,30 @@ class Growlyflash
|
|
11
11
|
notice : 'info'
|
12
12
|
success: 'success'
|
13
13
|
|
14
|
-
constructor: () ->
|
15
|
-
@flashes_log = []
|
14
|
+
constructor: (@context) ->
|
16
15
|
@growl(window.flashes) if window.flashes?
|
17
|
-
$(
|
18
|
-
$(document).ajaxComplete @ajax_complete
|
16
|
+
$(@context).on 'ajax:complete ajaxComplete', @ajax_complete
|
19
17
|
|
20
18
|
growl: (flashes) ->
|
21
19
|
for type, msg of flashes when msg?
|
22
|
-
|
23
|
-
$.bootstrapGrowl msg,
|
24
|
-
type: TYPE_MAPPING[type]
|
20
|
+
$.bootstrapGrowl msg, type: TYPE_MAPPING[type]
|
25
21
|
|
26
22
|
messages: (flashes) ->
|
27
23
|
{ type:type, msg:msg } for type, msg of flashes
|
28
|
-
|
29
|
-
ajax_complete: (e,
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
if @flashes_log.length > 0
|
36
|
-
last_log = @flashes_log.slice( - messages.length )
|
37
|
-
not_matches = 0
|
38
|
-
not_matches++ for id, f of messages when (last_log[id].type isnt f.type) and (last_log[id].msg isnt f.msg)
|
39
|
-
unless not_matches > 0
|
40
|
-
@flashes_log = []
|
41
|
-
return true
|
42
|
-
|
43
|
-
$.merge @flashes_log, messages
|
44
|
-
@growl flashes
|
24
|
+
|
25
|
+
ajax_complete: (e, response, settings) =>
|
26
|
+
xmessage = @get_x_message.call response
|
27
|
+
if xmessage?
|
28
|
+
flashes = $.parseJSON xmessage
|
29
|
+
@growl flashes
|
45
30
|
true
|
31
|
+
|
32
|
+
get_x_message: ->
|
33
|
+
encoded = @getResponseHeader('X-Message')
|
34
|
+
decodeURIComponent encoded
|
35
|
+
|
46
36
|
|
47
37
|
root.Growlyflash = Growlyflash
|
48
38
|
|
49
39
|
jQuery ->
|
50
|
-
|
51
|
-
new Growlyflash()
|
40
|
+
growlyflash = new Growlyflash document
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: growlyflash
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tõnis Simo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-05-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -94,10 +94,6 @@ files:
|
|
94
94
|
- Rakefile
|
95
95
|
- growlyflash.gemspec
|
96
96
|
- lib/growlyflash.rb
|
97
|
-
- lib/growlyflash/controller.rb
|
98
|
-
- lib/growlyflash/engine.rb
|
99
|
-
- lib/growlyflash/helpers.rb
|
100
|
-
- lib/growlyflash/railtie.rb
|
101
97
|
- lib/growlyflash/version.rb
|
102
98
|
- vendor/assets/javascripts/growlyflash/bootstrap-growl.js.coffee
|
103
99
|
- vendor/assets/javascripts/growlyflash/growlyflash.js.coffee
|
@@ -127,3 +123,4 @@ specification_version: 4
|
|
127
123
|
summary: Tiny gem which provides growl-styled flash messages for Ruby on Rails with
|
128
124
|
Bootstrap.
|
129
125
|
test_files: []
|
126
|
+
has_rdoc:
|
@@ -1,22 +0,0 @@
|
|
1
|
-
require 'active_support/concern'
|
2
|
-
|
3
|
-
module Growlyflash
|
4
|
-
module Controller
|
5
|
-
extend ActiveSupport::Concern
|
6
|
-
|
7
|
-
included do
|
8
|
-
after_filter :flash_to_headers, if: :is_xhr_request?
|
9
|
-
|
10
|
-
def flash_to_headers
|
11
|
-
flash_json = Hash[ flash.map { |type, msg| [type, msg] } ].to_json
|
12
|
-
response.headers['X-Message'] = flash_json.clone
|
13
|
-
flash.discard # don't want the flash to appear when you reload page
|
14
|
-
end
|
15
|
-
|
16
|
-
private
|
17
|
-
def is_xhr_request?
|
18
|
-
request.xhr?
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
data/lib/growlyflash/engine.rb
DELETED
data/lib/growlyflash/helpers.rb
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
module Growlyflash
|
2
|
-
module Helpers
|
3
|
-
|
4
|
-
# Insert in head tag in your layout before any js.
|
5
|
-
def growlyflash_static_notices
|
6
|
-
if flash.any?
|
7
|
-
javascript_tag "window.flashes = #{ raw(Hash[ flash.map { |type, msg| [type, msg] } ].to_json) };", defer: 'defer'
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
data/lib/growlyflash/railtie.rb
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
if defined?(Rails::Railtie)
|
2
|
-
module Growlyflash
|
3
|
-
|
4
|
-
class Railtie < ::Rails::Railtie
|
5
|
-
# initializer 'growlyflash.active_controller' do
|
6
|
-
initializer :growlyflash do
|
7
|
-
Growlyflash.initialize
|
8
|
-
# ActiveSupport.on_load(:action_controller) do
|
9
|
-
# include Growlyflash::Controller
|
10
|
-
# end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|