rack-pjax 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in rack-pjax.gemspec
4
+ gemspec
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,2 @@
1
+ require 'rack'
2
+ require "rack/pjax"
@@ -0,0 +1,42 @@
1
+ require 'nokogiri'
2
+
3
+ module Rack
4
+ class Pjax
5
+ include Rack::Utils
6
+
7
+ def initialize(app)
8
+ @app = app
9
+ end
10
+
11
+ def call(env)
12
+ status, headers, response = @app.call(env)
13
+ headers = HeaderHash.new(headers)
14
+
15
+ if pjax?(env)
16
+ body = ""
17
+ response.each do |r|
18
+ container = Nokogiri::HTML(r).at_css("[@data-pjax-container]")
19
+ if container
20
+ title = Nokogiri::HTML(r).at_css("title")
21
+ body << title.to_s << container.inner_html.strip
22
+ else
23
+ body << r
24
+ end
25
+ end
26
+ response = [body]
27
+
28
+ if headers['Content-Length']
29
+ length = response.to_ary.inject(0) { |len, part| len + bytesize(part) }
30
+ headers['Content-Length'] = length.to_s
31
+ end
32
+
33
+ end
34
+ [status, headers, response]
35
+ end
36
+
37
+ protected
38
+ def pjax?(env)
39
+ env['HTTP_X_PJAX']
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,5 @@
1
+ module Rack
2
+ class Pjax
3
+ VERSION = "0.5.0"
4
+ end
5
+ end
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "rack/pjax/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "rack-pjax"
7
+ s.version = Rack::Pjax::VERSION
8
+ s.authors = ["Gert Goet"]
9
+ s.email = ["gert@thinkcreate.nl"]
10
+ s.homepage = "https://github.com/eval/rack-pjax"
11
+ s.summary = %q{Serve pjax responses through rack middleware}
12
+ s.description = %q{Serve pjax responses through rack middleware}
13
+
14
+ s.rubyforge_project = "rack-pjax"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_dependency('rack', '>1.0')
22
+ s.add_dependency('nokogiri', '~>1.4.4')
23
+ end
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack-pjax
3
+ version: !ruby/object:Gem::Version
4
+ hash: 11
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 5
9
+ - 0
10
+ version: 0.5.0
11
+ platform: ruby
12
+ authors:
13
+ - Gert Goet
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-06-02 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rack
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">"
28
+ - !ruby/object:Gem::Version
29
+ hash: 15
30
+ segments:
31
+ - 1
32
+ - 0
33
+ version: "1.0"
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: nokogiri
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ hash: 15
45
+ segments:
46
+ - 1
47
+ - 4
48
+ - 4
49
+ version: 1.4.4
50
+ type: :runtime
51
+ version_requirements: *id002
52
+ description: Serve pjax responses through rack middleware
53
+ email:
54
+ - gert@thinkcreate.nl
55
+ executables: []
56
+
57
+ extensions: []
58
+
59
+ extra_rdoc_files: []
60
+
61
+ files:
62
+ - .gitignore
63
+ - Gemfile
64
+ - Rakefile
65
+ - lib/rack-pjax.rb
66
+ - lib/rack/pjax.rb
67
+ - lib/rack/pjax/version.rb
68
+ - rack-pjax.gemspec
69
+ has_rdoc: true
70
+ homepage: https://github.com/eval/rack-pjax
71
+ licenses: []
72
+
73
+ post_install_message:
74
+ rdoc_options: []
75
+
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ none: false
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ hash: 3
84
+ segments:
85
+ - 0
86
+ version: "0"
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ hash: 3
93
+ segments:
94
+ - 0
95
+ version: "0"
96
+ requirements: []
97
+
98
+ rubyforge_project: rack-pjax
99
+ rubygems_version: 1.6.2
100
+ signing_key:
101
+ specification_version: 3
102
+ summary: Serve pjax responses through rack middleware
103
+ test_files: []
104
+