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.
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  class Pjax
3
- VERSION = "0.5.2"
3
+ VERSION = "0.5.3"
4
4
  end
5
5
  end
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, response = @app.call(env)
12
+ status, headers, body = @app.call(env)
13
13
  headers = HeaderHash.new(headers)
14
14
 
15
15
  if pjax?(env)
16
- body = ""
17
- response.each do |r|
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
- body << title.to_s << container.inner_html.strip
21
+ new_body << title.to_s << container.inner_html.strip
22
22
  else
23
- body << r
23
+ new_body << r
24
24
  end
25
25
  end
26
- response = [body]
27
26
 
28
- headers['Content-Length'] &&= bytesize(body).to_s
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, response]
32
+ [status, headers, body]
31
33
  end
32
34
 
33
35
  protected
@@ -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::Builder.app do
8
- use Rack::Pjax
9
- run lambda { |env|
10
- body = '<html><title>Hello</title><body><div data-pjax-container>World!</div></body></html>'
11
- headers = {"Content-Length" => Rack::Utils.bytesize(body).to_s}
12
- [200, headers, [body]]
13
- }
14
- end
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 "/", {}, {'HTTP_X_PJAX' => true}
24
+ get "/", {}, {"HTTP_X_PJAX" => "true"}
20
25
  body.should == "<title>Hello</title>World!"
21
26
  end
22
27
 
23
- it "should recalculate the Content Length" do
24
- get "/", {}, {'HTTP_X_PJAX' => true}
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: 15
4
+ hash: 13
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 5
9
- - 2
10
- version: 0.5.2
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-01 00:00:00 Z
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: