rack-pjax 0.5.9 → 0.6.0.beta
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -1
- data/lib/rack/pjax/version.rb +1 -1
- data/lib/rack/pjax.rb +19 -16
- data/rack-pjax.gemspec +1 -1
- data/spec/rack/pjax_spec.rb +9 -1
- metadata +12 -15
data/README.md
CHANGED
data/lib/rack/pjax/version.rb
CHANGED
data/lib/rack/pjax.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'nokogiri'
|
2
2
|
|
3
3
|
module Rack
|
4
4
|
class Pjax
|
@@ -10,31 +10,34 @@ module Rack
|
|
10
10
|
|
11
11
|
def call(env)
|
12
12
|
status, headers, body = @app.call(env)
|
13
|
+
return [status, headers, body] unless pjax?(env)
|
14
|
+
|
13
15
|
headers = HeaderHash.new(headers)
|
14
16
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
new_body = ""
|
18
|
+
body.each do |b|
|
19
|
+
b.force_encoding('UTF-8') if RUBY_VERSION > '1.9.0'
|
20
|
+
|
21
|
+
parsed_body = Nokogiri::HTML(b)
|
22
|
+
container = parsed_body.at("[@data-pjax-container]")
|
23
|
+
|
24
|
+
new_body << begin
|
20
25
|
if container
|
21
|
-
children = container.children
|
22
26
|
title = parsed_body.at("title")
|
23
27
|
|
24
|
-
|
25
|
-
new_body << container.inner_html
|
28
|
+
"%s%s" % [title, container.inner_html]
|
26
29
|
else
|
27
|
-
|
30
|
+
b
|
28
31
|
end
|
29
32
|
end
|
33
|
+
end
|
30
34
|
|
31
|
-
|
32
|
-
body = [new_body]
|
35
|
+
body.close if body.respond_to?(:close)
|
33
36
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
[status, headers,
|
37
|
+
headers['Content-Length'] &&= bytesize(new_body).to_s
|
38
|
+
headers['X-PJAX-URL'] = Rack::Request.new(env).fullpath
|
39
|
+
|
40
|
+
[status, headers, [new_body]]
|
38
41
|
end
|
39
42
|
|
40
43
|
protected
|
data/rack-pjax.gemspec
CHANGED
data/spec/rack/pjax_spec.rb
CHANGED
@@ -41,7 +41,7 @@ describe Rack::Pjax do
|
|
41
41
|
|
42
42
|
get "/", {}, {"HTTP_X_PJAX" => "true"}
|
43
43
|
|
44
|
-
body.should == '<article>World!<img src="test.jpg"
|
44
|
+
body.should == '<article>World!<img src="test.jpg"></article>'
|
45
45
|
end
|
46
46
|
|
47
47
|
it "should handle nesting of elements inside anchor tags" do
|
@@ -52,6 +52,14 @@ describe Rack::Pjax do
|
|
52
52
|
body.should == '<a href="#"><h1>World!</h1></a>'
|
53
53
|
end
|
54
54
|
|
55
|
+
it "should handle html5 br tags correctly" do
|
56
|
+
self.class.app = generate_app(:body => '<html><body><div data-pjax-container><p>foo<br>bar</p></div></body></html>')
|
57
|
+
|
58
|
+
get "/", {}, {"HTTP_X_PJAX" => "true"}
|
59
|
+
|
60
|
+
body.should == '<p>foo<br>bar</p>'
|
61
|
+
end
|
62
|
+
|
55
63
|
it "should return the correct Content Length" do
|
56
64
|
get "/", {}, {"HTTP_X_PJAX" => "true"}
|
57
65
|
headers['Content-Length'].should == Rack::Utils.bytesize(body).to_s
|
metadata
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-pjax
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.6.0.beta
|
5
|
+
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Gert Goet
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-08-28 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rack
|
16
|
-
requirement: &
|
16
|
+
requirement: &70109943306240 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,18 +21,18 @@ dependencies:
|
|
21
21
|
version: '1.3'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70109943306240
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
|
-
name:
|
27
|
-
requirement: &
|
26
|
+
name: nokogiri
|
27
|
+
requirement: &70109943305480 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version:
|
32
|
+
version: '1.5'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70109943305480
|
36
36
|
description: Serve pjax responses through rack middleware
|
37
37
|
email:
|
38
38
|
- gert@thinkcreate.nl
|
@@ -67,16 +67,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
67
67
|
version: '0'
|
68
68
|
segments:
|
69
69
|
- 0
|
70
|
-
hash: -
|
70
|
+
hash: -1905601241101123919
|
71
71
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
|
-
- - ! '
|
74
|
+
- - ! '>'
|
75
75
|
- !ruby/object:Gem::Version
|
76
|
-
version:
|
77
|
-
segments:
|
78
|
-
- 0
|
79
|
-
hash: -4041926408283273529
|
76
|
+
version: 1.3.1
|
80
77
|
requirements: []
|
81
78
|
rubyforge_project: rack-pjax
|
82
79
|
rubygems_version: 1.8.10
|