rack-pjax 0.5.2 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rack/pjax/version.rb +1 -1
- data/lib/rack/pjax.rb +10 -8
- data/spec/rack/pjax_spec.rb +16 -11
- metadata +5 -4
data/lib/rack/pjax/version.rb
CHANGED
data/lib/rack/pjax.rb
CHANGED
@@ -9,25 +9,27 @@ module Rack
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def call(env)
|
12
|
-
status, headers,
|
12
|
+
status, headers, body = @app.call(env)
|
13
13
|
headers = HeaderHash.new(headers)
|
14
14
|
|
15
15
|
if pjax?(env)
|
16
|
-
|
17
|
-
|
16
|
+
new_body = ""
|
17
|
+
body.each do |r|
|
18
18
|
container = Nokogiri::HTML(r).at_css("[@data-pjax-container]")
|
19
19
|
if container
|
20
20
|
title = Nokogiri::HTML(r).at_css("title")
|
21
|
-
|
21
|
+
new_body << title.to_s << container.inner_html.strip
|
22
22
|
else
|
23
|
-
|
23
|
+
new_body << r
|
24
24
|
end
|
25
25
|
end
|
26
|
-
response = [body]
|
27
26
|
|
28
|
-
|
27
|
+
body.close if body.respond_to?(:close)
|
28
|
+
body = [new_body]
|
29
|
+
|
30
|
+
headers['Content-Length'] &&= bytesize(new_body).to_s
|
29
31
|
end
|
30
|
-
[status, headers,
|
32
|
+
[status, headers, body]
|
31
33
|
end
|
32
34
|
|
33
35
|
protected
|
data/spec/rack/pjax_spec.rb
CHANGED
@@ -4,24 +4,29 @@ describe Rack::Pjax do
|
|
4
4
|
include Rack::Test::Methods # can be moved to config
|
5
5
|
|
6
6
|
def app
|
7
|
-
Rack::
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
7
|
+
Rack::Lint.new(
|
8
|
+
Rack::Builder.app do
|
9
|
+
use Rack::Pjax
|
10
|
+
run lambda { |env|
|
11
|
+
body = '<html><title>Hello</title><body><div data-pjax-container>World!</div></body></html>'
|
12
|
+
headers = {
|
13
|
+
"Content-Length" => Rack::Utils.bytesize(body).to_s,
|
14
|
+
"Content-Type" => 'text/plain'
|
15
|
+
}
|
16
|
+
[200, headers, [body]]
|
17
|
+
}
|
18
|
+
end
|
19
|
+
)
|
15
20
|
end
|
16
21
|
|
17
22
|
context "when receiving a pjax-request" do
|
18
23
|
it "should return title-tag and inner-html of the pjax-container" do
|
19
|
-
get "/", {}, {
|
24
|
+
get "/", {}, {"HTTP_X_PJAX" => "true"}
|
20
25
|
body.should == "<title>Hello</title>World!"
|
21
26
|
end
|
22
27
|
|
23
|
-
it "should
|
24
|
-
get "/", {}, {
|
28
|
+
it "should have the correct Content Length" do
|
29
|
+
get "/", {}, {"HTTP_X_PJAX" => "true"}
|
25
30
|
headers['Content-Length'].should == Rack::Utils.bytesize(body).to_s
|
26
31
|
end
|
27
32
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-pjax
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 13
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 5
|
9
|
-
-
|
10
|
-
version: 0.5.
|
9
|
+
- 3
|
10
|
+
version: 0.5.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Gert Goet
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-11-
|
18
|
+
date: 2011-11-02 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: rack
|
@@ -107,3 +107,4 @@ test_files:
|
|
107
107
|
- spec/rack/pjax_spec.rb
|
108
108
|
- spec/spec.opts
|
109
109
|
- spec/spec_helper.rb
|
110
|
+
has_rdoc:
|