glow 0.0.12 → 0.0.13
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +43 -43
- data/README.md +39 -8
- data/lib/glow/filter.rb +15 -2
- data/lib/glow/version.rb +1 -1
- data/test/rails3/Gemfile +1 -1
- data/test/rails3/Gemfile.lock +2 -2
- data/test/rails3/app/controllers/flash_controller.rb +11 -6
- data/test/rails3/spec/controllers/flash_controller_spec.rb +18 -1
- data/test/rails31/Gemfile.lock +1 -1
- data/test/rails31/app/controllers/flash_controller.rb +10 -5
- data/test/rails31/spec/controllers/flash_controller_spec.rb +18 -1
- data/test/rails32/Gemfile.lock +1 -1
- data/test/rails32/app/controllers/flash_controller.rb +10 -5
- data/test/rails32/spec/controllers/flash_controller_spec.rb +18 -1
- metadata +4 -4
data/Gemfile.lock
CHANGED
@@ -1,39 +1,39 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
glow (0.0.
|
4
|
+
glow (0.0.13)
|
5
5
|
jquery-rails
|
6
6
|
rails (>= 3.0.0, < 4.0.0)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: http://rubygems.org/
|
10
10
|
specs:
|
11
|
-
actionmailer (3.2.
|
12
|
-
actionpack (= 3.2.
|
13
|
-
mail (~> 2.
|
14
|
-
actionpack (3.2.
|
15
|
-
activemodel (= 3.2.
|
16
|
-
activesupport (= 3.2.
|
11
|
+
actionmailer (3.2.13)
|
12
|
+
actionpack (= 3.2.13)
|
13
|
+
mail (~> 2.5.3)
|
14
|
+
actionpack (3.2.13)
|
15
|
+
activemodel (= 3.2.13)
|
16
|
+
activesupport (= 3.2.13)
|
17
17
|
builder (~> 3.0.0)
|
18
18
|
erubis (~> 2.7.0)
|
19
19
|
journey (~> 1.0.4)
|
20
|
-
rack (~> 1.4.
|
20
|
+
rack (~> 1.4.5)
|
21
21
|
rack-cache (~> 1.2)
|
22
22
|
rack-test (~> 0.6.1)
|
23
23
|
sprockets (~> 2.2.1)
|
24
|
-
activemodel (3.2.
|
25
|
-
activesupport (= 3.2.
|
24
|
+
activemodel (3.2.13)
|
25
|
+
activesupport (= 3.2.13)
|
26
26
|
builder (~> 3.0.0)
|
27
|
-
activerecord (3.2.
|
28
|
-
activemodel (= 3.2.
|
29
|
-
activesupport (= 3.2.
|
27
|
+
activerecord (3.2.13)
|
28
|
+
activemodel (= 3.2.13)
|
29
|
+
activesupport (= 3.2.13)
|
30
30
|
arel (~> 3.0.2)
|
31
31
|
tzinfo (~> 0.3.29)
|
32
|
-
activeresource (3.2.
|
33
|
-
activemodel (= 3.2.
|
34
|
-
activesupport (= 3.2.
|
35
|
-
activesupport (3.2.
|
36
|
-
i18n (
|
32
|
+
activeresource (3.2.13)
|
33
|
+
activemodel (= 3.2.13)
|
34
|
+
activesupport (= 3.2.13)
|
35
|
+
activesupport (3.2.13)
|
36
|
+
i18n (= 0.6.1)
|
37
37
|
multi_json (~> 1.0)
|
38
38
|
arel (3.0.2)
|
39
39
|
builder (3.0.4)
|
@@ -41,53 +41,53 @@ GEM
|
|
41
41
|
hike (1.2.1)
|
42
42
|
i18n (0.6.1)
|
43
43
|
journey (1.0.4)
|
44
|
-
jquery-rails (2.1.
|
45
|
-
railties (>= 3.
|
46
|
-
thor (
|
47
|
-
json (1.7.
|
48
|
-
mail (2.
|
44
|
+
jquery-rails (2.1.4)
|
45
|
+
railties (>= 3.0, < 5.0)
|
46
|
+
thor (>= 0.14, < 2.0)
|
47
|
+
json (1.7.7)
|
48
|
+
mail (2.5.3)
|
49
49
|
i18n (>= 0.4.0)
|
50
50
|
mime-types (~> 1.16)
|
51
51
|
treetop (~> 1.4.8)
|
52
|
-
mime-types (1.
|
53
|
-
multi_json (1.
|
52
|
+
mime-types (1.21)
|
53
|
+
multi_json (1.7.1)
|
54
54
|
polyglot (0.3.3)
|
55
|
-
rack (1.4.
|
55
|
+
rack (1.4.5)
|
56
56
|
rack-cache (1.2)
|
57
57
|
rack (>= 0.4)
|
58
|
-
rack-ssl (1.3.
|
58
|
+
rack-ssl (1.3.3)
|
59
59
|
rack
|
60
60
|
rack-test (0.6.2)
|
61
61
|
rack (>= 1.0)
|
62
|
-
rails (3.2.
|
63
|
-
actionmailer (= 3.2.
|
64
|
-
actionpack (= 3.2.
|
65
|
-
activerecord (= 3.2.
|
66
|
-
activeresource (= 3.2.
|
67
|
-
activesupport (= 3.2.
|
62
|
+
rails (3.2.13)
|
63
|
+
actionmailer (= 3.2.13)
|
64
|
+
actionpack (= 3.2.13)
|
65
|
+
activerecord (= 3.2.13)
|
66
|
+
activeresource (= 3.2.13)
|
67
|
+
activesupport (= 3.2.13)
|
68
68
|
bundler (~> 1.0)
|
69
|
-
railties (= 3.2.
|
70
|
-
railties (3.2.
|
71
|
-
actionpack (= 3.2.
|
72
|
-
activesupport (= 3.2.
|
69
|
+
railties (= 3.2.13)
|
70
|
+
railties (3.2.13)
|
71
|
+
actionpack (= 3.2.13)
|
72
|
+
activesupport (= 3.2.13)
|
73
73
|
rack-ssl (~> 1.3.2)
|
74
74
|
rake (>= 0.8.7)
|
75
75
|
rdoc (~> 3.4)
|
76
76
|
thor (>= 0.14.6, < 2.0)
|
77
|
-
rake (10.0.
|
78
|
-
rdoc (3.12)
|
77
|
+
rake (10.0.3)
|
78
|
+
rdoc (3.12.2)
|
79
79
|
json (~> 1.4)
|
80
|
-
sprockets (2.2.
|
80
|
+
sprockets (2.2.2)
|
81
81
|
hike (~> 1.2)
|
82
82
|
multi_json (~> 1.0)
|
83
83
|
rack (~> 1.0)
|
84
84
|
tilt (~> 1.1, != 1.3.0)
|
85
|
-
thor (0.
|
86
|
-
tilt (1.3.
|
85
|
+
thor (0.17.0)
|
86
|
+
tilt (1.3.6)
|
87
87
|
treetop (1.4.12)
|
88
88
|
polyglot
|
89
89
|
polyglot (>= 0.3.1)
|
90
|
-
tzinfo (0.3.
|
90
|
+
tzinfo (0.3.37)
|
91
91
|
|
92
92
|
PLATFORMS
|
93
93
|
ruby
|
data/README.md
CHANGED
@@ -8,17 +8,21 @@ Fash Hash in Javascript. Depends on jQuery.
|
|
8
8
|
Any flash messages set in ajax responses fire a `glow:flash`
|
9
9
|
event on `document`.
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
11
|
+
```ruby
|
12
|
+
flash[:notice] = 'Ajax man!'
|
13
|
+
respond_to do |format|
|
14
|
+
format.js { head :ok }
|
15
|
+
end
|
16
|
+
```
|
15
17
|
|
16
18
|
Handle it any way you want:
|
17
19
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
20
|
+
```javascript
|
21
|
+
$(document).bind('glow:flash', function(evt, flash) {
|
22
|
+
alert(flash.type);
|
23
|
+
alert(flash.message);
|
24
|
+
});
|
25
|
+
```
|
22
26
|
|
23
27
|
Also adds a `Flash` object that enables you to fire `glow:flash`.
|
24
28
|
|
@@ -37,6 +41,33 @@ responses).
|
|
37
41
|
|
38
42
|
If you want to skip the glow after_filter just set `flash[:skip_glow]`.
|
39
43
|
|
44
|
+
|
45
|
+
You can also use glow with APIs by using `headerize_flash_for` and passing
|
46
|
+
in the request formats you want the flash messages passed back.
|
47
|
+
|
48
|
+
``` ruby
|
49
|
+
class API::Base < ActionController::Base
|
50
|
+
headerize_flash_for :json
|
51
|
+
end
|
52
|
+
```
|
53
|
+
|
54
|
+
Controllers inheriting from a controller using `headerize_format_for` will
|
55
|
+
inherit the capability or it can be overridden.
|
56
|
+
|
57
|
+
``` ruby
|
58
|
+
class API::JSON < API::Base
|
59
|
+
# will headerize flash for JSON requests
|
60
|
+
end
|
61
|
+
|
62
|
+
class API::XML < API::Base
|
63
|
+
headerize_flash_for :xml
|
64
|
+
# will NOT headerize flash for JSON requests
|
65
|
+
# but will headerize flash for XML requests
|
66
|
+
end
|
67
|
+
```
|
68
|
+
|
69
|
+
|
70
|
+
|
40
71
|
## Installation
|
41
72
|
|
42
73
|
In your gemfile add
|
data/lib/glow/filter.rb
CHANGED
@@ -4,11 +4,12 @@ module Glow
|
|
4
4
|
module Filter
|
5
5
|
extend ActiveSupport::Concern
|
6
6
|
included do
|
7
|
-
after_filter
|
7
|
+
after_filter :flash_to_headers
|
8
|
+
class_attribute :glow_request_formats
|
8
9
|
end
|
9
10
|
|
10
11
|
def flash_to_headers
|
11
|
-
return unless flash.any? &&
|
12
|
+
return unless flash.any? && flash_to_headers?
|
12
13
|
return if flash[:skip_glow] and flash.delete(:skip_glow)
|
13
14
|
|
14
15
|
type, message = flash.first
|
@@ -17,5 +18,17 @@ module Glow
|
|
17
18
|
flash.discard # don't want the flash to appear when you reload page
|
18
19
|
end
|
19
20
|
|
21
|
+
def flash_to_headers?
|
22
|
+
request.xhr? ||
|
23
|
+
glow_request_formats? && glow_request_formats.include?(request.format.to_sym)
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
module ClassMethods
|
28
|
+
def headerize_flash_for *formats
|
29
|
+
self.glow_request_formats = formats
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
20
33
|
end
|
21
34
|
end
|
data/lib/glow/version.rb
CHANGED
data/test/rails3/Gemfile
CHANGED
data/test/rails3/Gemfile.lock
CHANGED
@@ -1,20 +1,25 @@
|
|
1
1
|
class FlashController < ApplicationController
|
2
|
+
|
3
|
+
headerize_flash_for :json
|
4
|
+
|
2
5
|
def show
|
3
6
|
# show.html.erb
|
4
7
|
end
|
5
8
|
|
6
9
|
def redirect
|
7
|
-
flash[params[:type]] = params[:message]
|
10
|
+
flash[params[:type].to_sym] = params[:message]
|
8
11
|
redirect_to action: 'show'
|
9
12
|
end
|
10
13
|
|
11
14
|
def ajax
|
12
15
|
respond_to do |wants|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
16
|
+
[:js, :json, :xml].each do |fmt|
|
17
|
+
wants.send(fmt) {
|
18
|
+
flash[params[:type].to_sym] = params[:message]
|
19
|
+
flash[:skip_glow] = params[:skip_glow].present?
|
20
|
+
head :ok
|
21
|
+
}
|
22
|
+
end
|
18
23
|
end
|
19
24
|
end
|
20
25
|
end
|
@@ -15,7 +15,7 @@ describe FlashController do
|
|
15
15
|
flash.keep?(:notice).should be true
|
16
16
|
end
|
17
17
|
|
18
|
-
it "should display flash message on xhr" do
|
18
|
+
it "should display flash message on xhr" do
|
19
19
|
xhr :get, :ajax, type: :notice, message: 'Glow!'
|
20
20
|
|
21
21
|
flash[:notice].should be == 'Glow!'
|
@@ -35,4 +35,21 @@ describe FlashController do
|
|
35
35
|
xhr :get, :ajax, type: :notice, message: 'utf8: ✓', skip_glow: true
|
36
36
|
@response.headers.should_not have_key 'X-Message-Type'
|
37
37
|
end
|
38
|
+
|
39
|
+
it "should pass flash message on JSON requests" do
|
40
|
+
get :ajax, type: :notice, message: 'Glow!', format: :json
|
41
|
+
|
42
|
+
flash[:notice].should be == 'Glow!'
|
43
|
+
flash.discard?(:notice).should be true
|
44
|
+
|
45
|
+
@response.headers['X-Message-Type'].should be == 'notice'
|
46
|
+
HTMLEntities.new.decode(@response.headers['X-Message']).should be == 'Glow!'
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should not pass flash message on XML requests" do
|
50
|
+
get :ajax, type: :notice, message: 'Glow!', format: :xml
|
51
|
+
|
52
|
+
@response.headers['X-Message-Type'].should be_nil
|
53
|
+
@response.headers['X-Message'].should be_nil
|
54
|
+
end
|
38
55
|
end
|
data/test/rails31/Gemfile.lock
CHANGED
@@ -1,4 +1,7 @@
|
|
1
1
|
class FlashController < ApplicationController
|
2
|
+
|
3
|
+
headerize_flash_for :json
|
4
|
+
|
2
5
|
def show
|
3
6
|
# show.html.erb
|
4
7
|
end
|
@@ -10,11 +13,13 @@ class FlashController < ApplicationController
|
|
10
13
|
|
11
14
|
def ajax
|
12
15
|
respond_to do |wants|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
16
|
+
[:js, :json, :xml].each do |fmt|
|
17
|
+
wants.send(fmt) {
|
18
|
+
flash[params[:type].to_sym] = params[:message]
|
19
|
+
flash[:skip_glow] = params[:skip_glow].present?
|
20
|
+
head :ok
|
21
|
+
}
|
22
|
+
end
|
18
23
|
end
|
19
24
|
end
|
20
25
|
end
|
@@ -15,7 +15,7 @@ describe FlashController do
|
|
15
15
|
flash.keep?(:notice).should be true
|
16
16
|
end
|
17
17
|
|
18
|
-
it "should display flash message on xhr" do
|
18
|
+
it "should display flash message on xhr" do
|
19
19
|
xhr :get, :ajax, type: :notice, message: 'Glow!'
|
20
20
|
|
21
21
|
flash[:notice].should be == 'Glow!'
|
@@ -35,4 +35,21 @@ describe FlashController do
|
|
35
35
|
xhr :get, :ajax, type: :notice, message: 'utf8: ✓', skip_glow: true
|
36
36
|
@response.headers.should_not have_key 'X-Message-Type'
|
37
37
|
end
|
38
|
+
|
39
|
+
it "should pass flash message on JSON requests" do
|
40
|
+
get :ajax, type: :notice, message: 'Glow!', format: :json
|
41
|
+
|
42
|
+
flash[:notice].should be == 'Glow!'
|
43
|
+
flash.discard?(:notice).should be true
|
44
|
+
|
45
|
+
@response.headers['X-Message-Type'].should be == 'notice'
|
46
|
+
HTMLEntities.new.decode(@response.headers['X-Message']).should be == 'Glow!'
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should not pass flash message on XML requests" do
|
50
|
+
get :ajax, type: :notice, message: 'Glow!', format: :xml
|
51
|
+
|
52
|
+
@response.headers['X-Message-Type'].should be_nil
|
53
|
+
@response.headers['X-Message'].should be_nil
|
54
|
+
end
|
38
55
|
end
|
data/test/rails32/Gemfile.lock
CHANGED
@@ -1,4 +1,7 @@
|
|
1
1
|
class FlashController < ApplicationController
|
2
|
+
|
3
|
+
headerize_flash_for :json
|
4
|
+
|
2
5
|
def show
|
3
6
|
# show.html.erb
|
4
7
|
end
|
@@ -10,11 +13,13 @@ class FlashController < ApplicationController
|
|
10
13
|
|
11
14
|
def ajax
|
12
15
|
respond_to do |wants|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
16
|
+
[:js, :json, :xml].each do |fmt|
|
17
|
+
wants.send(fmt) {
|
18
|
+
flash[params[:type].to_sym] = params[:message]
|
19
|
+
flash[:skip_glow] = params[:skip_glow].present?
|
20
|
+
head :ok
|
21
|
+
}
|
22
|
+
end
|
18
23
|
end
|
19
24
|
end
|
20
25
|
end
|
@@ -15,7 +15,7 @@ describe FlashController do
|
|
15
15
|
flash.keep?(:notice).should be true
|
16
16
|
end
|
17
17
|
|
18
|
-
it "should display flash message on xhr" do
|
18
|
+
it "should display flash message on xhr" do
|
19
19
|
xhr :get, :ajax, type: :notice, message: 'Glow!'
|
20
20
|
|
21
21
|
flash[:notice].should be == 'Glow!'
|
@@ -35,4 +35,21 @@ describe FlashController do
|
|
35
35
|
xhr :get, :ajax, type: :notice, message: 'utf8: ✓', skip_glow: true
|
36
36
|
@response.headers.should_not have_key 'X-Message-Type'
|
37
37
|
end
|
38
|
+
|
39
|
+
it "should pass flash message on JSON requests" do
|
40
|
+
get :ajax, type: :notice, message: 'Glow!', format: :json
|
41
|
+
|
42
|
+
flash[:notice].should be == 'Glow!'
|
43
|
+
flash.discard?(:notice).should be true
|
44
|
+
|
45
|
+
@response.headers['X-Message-Type'].should be == 'notice'
|
46
|
+
HTMLEntities.new.decode(@response.headers['X-Message']).should be == 'Glow!'
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should not pass flash message on XML requests" do
|
50
|
+
get :ajax, type: :notice, message: 'Glow!', format: :xml
|
51
|
+
|
52
|
+
@response.headers['X-Message-Type'].should be_nil
|
53
|
+
@response.headers['X-Message'].should be_nil
|
54
|
+
end
|
38
55
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: glow
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.13
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Daniel Kirsch
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2013-05-10 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -210,7 +210,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
210
210
|
version: '0'
|
211
211
|
segments:
|
212
212
|
- 0
|
213
|
-
hash:
|
213
|
+
hash: -1114898616114158001
|
214
214
|
none: false
|
215
215
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
216
216
|
requirements:
|
@@ -219,7 +219,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
219
219
|
version: '0'
|
220
220
|
segments:
|
221
221
|
- 0
|
222
|
-
hash:
|
222
|
+
hash: -1114898616114158001
|
223
223
|
none: false
|
224
224
|
requirements: []
|
225
225
|
rubyforge_project:
|