pax_global_header 0000666 0000000 0000000 00000000064 12116363452 0014515 g ustar 00root root 0000000 0000000 52 comment=e8ff938adc74078fcdf205e2731904cefbeb7cd6
ruby-rack-pjax-0.7.0/ 0000775 0000000 0000000 00000000000 12116363452 0014360 5 ustar 00root root 0000000 0000000 ruby-rack-pjax-0.7.0/.gitignore 0000664 0000000 0000000 00000000070 12116363452 0016345 0 ustar 00root root 0000000 0000000 *.gem
.bundle
Gemfile.lock
pkg/*
.rvmrc
.rbenv-version
ruby-rack-pjax-0.7.0/.travis.yml 0000664 0000000 0000000 00000000114 12116363452 0016465 0 ustar 00root root 0000000 0000000 rvm:
- 1.8.7
- 1.9.2
- 1.9.3
- jruby
branches:
only:
- master
ruby-rack-pjax-0.7.0/Gemfile 0000664 0000000 0000000 00000000205 12116363452 0015650 0 ustar 00root root 0000000 0000000 source "http://rubygems.org"
gem 'rake'
gemspec
group :test do
gem "rspec", ">2"
gem "rack-test", :require => "rack/test"
end
ruby-rack-pjax-0.7.0/LICENSE 0000664 0000000 0000000 00000002052 12116363452 0015364 0 ustar 00root root 0000000 0000000 Copyright (c) 2011 Gert Goet, ThinkCreate
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
ruby-rack-pjax-0.7.0/README.md 0000664 0000000 0000000 00000004671 12116363452 0015647 0 ustar 00root root 0000000 0000000 Rack-pjax [](https://secure.travis-ci.org/#!/eval/rack-pjax)
========
Rack-pjax is middleware that lets you serve 'chrome-less' pages in respond to [pjax-requests](https://github.com/defunkt/jquery-pjax).
It does this by stripping the generated body; only the title and inner-html of the pjax-container are sent to the client.
While this won't save you any time rendering the page, it gives you more flexibility where and how to define the pjax-container.
Ryan Bates featured [rack-pjax on Railscasts](http://railscasts.com/episodes/294-playing-with-pjax) and explains how this gem compares to [pjax_rails](https://github.com/rails/pjax_rails).
[](http://railscasts.com/)
Installation
------------
Check out the [Railscasts' notes](http://railscasts.com/episodes/294-playing-with-pjax) how to integrate rack-pjax in your Rails 3.1 application.
You can find the source from the screencast over [here](https://github.com/ryanb/railscasts-episodes/tree/master/episode-294).
Another sample-app: the original [pjax-demo](http://pjax.heroku.com/) but with rack-pjax onboard can be found in the [sample-app](https://github.com/eval/rack-pjax/tree/sample-app) branch.
The more generic installation comes down to:
I. Add the gem to your Gemfile
```ruby
# Gemfile
gem "rack-pjax"
```
II. Include **rack-pjax** as middleware to your application(-stack)
```ruby
# config.ru
require ::File.expand_path('../config/environment', __FILE__)
use Rack::Pjax
run RackApp::Application
```
III. Install [jquery-pjax](https://github.com/defunkt/jquery-pjax). Make sure to add the 'data-pjax-container'-attribute to the container.
```html
...
...
...
```
IV. Fire up your [pushState-enabled browser](http://caniuse.com/#search=pushstate) and enjoy!
Requirements
------------
- Nokogiri
Contributors
------
[The contributors](https://github.com/eval/rack-pjax/graphs/contributors).
ruby-rack-pjax-0.7.0/Rakefile 0000664 0000000 0000000 00000000527 12116363452 0016031 0 ustar 00root root 0000000 0000000 require 'bundler/gem_tasks'
require "rspec/core/rake_task"
RSpec::Core::RakeTask.new do |t|
t.rspec_opts = ['--options', "\"#{File.dirname(__FILE__)}/spec/spec.opts\""]
end
desc "Run the specs"
task :default => :spec
desc 'Removes trailing whitespace'
task :whitespace do
sh %{find . -name '*.rb' -exec sed -i '' 's/ *$//g' {} \\;}
end
ruby-rack-pjax-0.7.0/lib/ 0000775 0000000 0000000 00000000000 12116363452 0015126 5 ustar 00root root 0000000 0000000 ruby-rack-pjax-0.7.0/lib/rack-pjax.rb 0000664 0000000 0000000 00000000043 12116363452 0017330 0 ustar 00root root 0000000 0000000 require 'rack'
require "rack/pjax"
ruby-rack-pjax-0.7.0/lib/rack/ 0000775 0000000 0000000 00000000000 12116363452 0016046 5 ustar 00root root 0000000 0000000 ruby-rack-pjax-0.7.0/lib/rack/pjax.rb 0000664 0000000 0000000 00000002116 12116363452 0017335 0 ustar 00root root 0000000 0000000 require 'nokogiri'
module Rack
class Pjax
include Rack::Utils
def initialize(app)
@app = app
end
def call(env)
status, headers, body = @app.call(env)
return [status, headers, body] unless pjax?(env)
headers = HeaderHash.new(headers)
new_body = ""
body.each do |b|
b.force_encoding('UTF-8') if RUBY_VERSION > '1.9.0'
parsed_body = Nokogiri::HTML(b)
container = parsed_body.at(container_selector(env))
new_body << begin
if container
title = parsed_body.at("title")
"%s%s" % [title, container.inner_html]
else
b
end
end
end
body.close if body.respond_to?(:close)
headers['Content-Length'] &&= bytesize(new_body).to_s
headers['X-PJAX-URL'] = Rack::Request.new(env).fullpath
[status, headers, [new_body]]
end
protected
def pjax?(env)
env['HTTP_X_PJAX']
end
def container_selector(env)
env['HTTP_X_PJAX_CONTAINER'] || "[@data-pjax-container]"
end
end
end
ruby-rack-pjax-0.7.0/lib/rack/pjax/ 0000775 0000000 0000000 00000000000 12116363452 0017010 5 ustar 00root root 0000000 0000000 ruby-rack-pjax-0.7.0/lib/rack/pjax/version.rb 0000664 0000000 0000000 00000000071 12116363452 0021020 0 ustar 00root root 0000000 0000000 module Rack
class Pjax
VERSION = "0.7.0"
end
end
ruby-rack-pjax-0.7.0/metadata.yml 0000664 0000000 0000000 00000004155 12116363452 0016670 0 ustar 00root root 0000000 0000000 --- !ruby/object:Gem::Specification
name: rack-pjax
version: !ruby/object:Gem::Version
version: 0.7.0
prerelease:
platform: ruby
authors:
- Gert Goet
autorequire:
bindir: bin
cert_chain: []
date: 2013-01-08 00:00:00.000000000 Z
dependencies:
- !ruby/object:Gem::Dependency
name: rack
requirement: !ruby/object:Gem::Requirement
none: false
requirements:
- - ~>
- !ruby/object:Gem::Version
version: '1.3'
type: :runtime
prerelease: false
version_requirements: !ruby/object:Gem::Requirement
none: false
requirements:
- - ~>
- !ruby/object:Gem::Version
version: '1.3'
- !ruby/object:Gem::Dependency
name: nokogiri
requirement: !ruby/object:Gem::Requirement
none: false
requirements:
- - ~>
- !ruby/object:Gem::Version
version: '1.5'
type: :runtime
prerelease: false
version_requirements: !ruby/object:Gem::Requirement
none: false
requirements:
- - ~>
- !ruby/object:Gem::Version
version: '1.5'
description: Serve pjax responses through rack middleware
email:
- gert@thinkcreate.nl
executables: []
extensions: []
extra_rdoc_files: []
files:
- .gitignore
- .travis.yml
- Gemfile
- LICENSE
- README.md
- Rakefile
- lib/rack-pjax.rb
- lib/rack/pjax.rb
- lib/rack/pjax/version.rb
- rack-pjax.gemspec
- spec/rack/pjax_spec.rb
- spec/spec.opts
- spec/spec_helper.rb
homepage: https://github.com/eval/rack-pjax
licenses: []
post_install_message:
rdoc_options: []
require_paths:
- lib
required_ruby_version: !ruby/object:Gem::Requirement
none: false
requirements:
- - ! '>='
- !ruby/object:Gem::Version
version: '0'
segments:
- 0
hash: 2691976653533347282
required_rubygems_version: !ruby/object:Gem::Requirement
none: false
requirements:
- - ! '>='
- !ruby/object:Gem::Version
version: '0'
segments:
- 0
hash: 2691976653533347282
requirements: []
rubyforge_project: rack-pjax
rubygems_version: 1.8.23
signing_key:
specification_version: 3
summary: Serve pjax responses through rack middleware
test_files:
- spec/rack/pjax_spec.rb
- spec/spec.opts
- spec/spec_helper.rb
ruby-rack-pjax-0.7.0/rack-pjax.gemspec 0000664 0000000 0000000 00000001453 12116363452 0017610 0 ustar 00root root 0000000 0000000 # -*- encoding: utf-8 -*-
$:.push File.expand_path("../lib", __FILE__)
require "rack/pjax/version"
Gem::Specification.new do |s|
s.name = "rack-pjax"
s.version = Rack::Pjax::VERSION
s.authors = ["Gert Goet"]
s.email = ["gert@thinkcreate.nl"]
s.homepage = "https://github.com/eval/rack-pjax"
s.summary = %q{Serve pjax responses through rack middleware}
s.description = %q{Serve pjax responses through rack middleware}
s.rubyforge_project = "rack-pjax"
s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]
s.add_dependency('rack', '~>1.3')
s.add_dependency('nokogiri', '~>1.5')
end
ruby-rack-pjax-0.7.0/spec/ 0000775 0000000 0000000 00000000000 12116363452 0015312 5 ustar 00root root 0000000 0000000 ruby-rack-pjax-0.7.0/spec/rack/ 0000775 0000000 0000000 00000000000 12116363452 0016232 5 ustar 00root root 0000000 0000000 ruby-rack-pjax-0.7.0/spec/rack/pjax_spec.rb 0000664 0000000 0000000 00000007216 12116363452 0020541 0 ustar 00root root 0000000 0000000 require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe Rack::Pjax do
include Rack::Test::Methods # can be moved to config
def generate_app(options={})
body = options[:body]
Rack::Lint.new(
Rack::Pjax.new(
lambda do |env|
[
200,
{'Content-Type' => 'text/plain', 'Content-Length' => Rack::Utils.bytesize(body).to_s},
[body]
]
end
)
)
end
context "a pjaxified app, upon receiving a pjax-request" do
before do
self.class.app = generate_app(:body => 'HelloWorld!
')
end
it "should return the title-tag in the body" do
get "/", {}, {"HTTP_X_PJAX" => "true"}
body.should == "HelloWorld!"
end
it "should return the inner-html of the pjax-container in the body" do
self.class.app = generate_app(:body => 'World!
')
get "/", {}, {"HTTP_X_PJAX" => "true"}
body.should == "World!"
end
it "should return the inner-html of the custom pjax-container in the body" do
self.class.app = generate_app(:body => 'World!
')
get "/", {}, {"HTTP_X_PJAX" => "true", "HTTP_X_PJAX_CONTAINER" => "#container"}
body.should == "World!"
end
it "should handle self closing tags with HTML5 elements" do
self.class.app = generate_app(:body => 'World!
')
get "/", {}, {"HTTP_X_PJAX" => "true"}
body.should == 'World!
'
end
it "should handle nesting of elements inside anchor tags" do
self.class.app = generate_app(:body => '')
get "/", {}, {"HTTP_X_PJAX" => "true"}
body.should == 'World!
'
end
it "should handle html5 br tags correctly" do
self.class.app = generate_app(:body => '')
get "/", {}, {"HTTP_X_PJAX" => "true"}
body.should == 'foo
bar
'
end
it "should return the correct Content Length" do
get "/", {}, {"HTTP_X_PJAX" => "true"}
headers['Content-Length'].should == Rack::Utils.bytesize(body).to_s
end
it "should return the original body when there's no pjax-container" do
self.class.app = generate_app(:body => 'Has no pjax-container')
get "/", {}, {"HTTP_X_PJAX" => "true"}
body.should == "Has no pjax-container"
end
it "should preserve whitespaces of the original body" do
container = "\n \nfirst paragraph
Second paragraph
\n"
self.class.app = generate_app(:body =><<-BODY)
#{container}
BODY
get "/", {}, {"HTTP_X_PJAX" => "true"}
body.should == container
end
end
context "a pjaxified app, upon receiving a non-pjax request" do
before do
self.class.app = generate_app(:body => 'HelloWorld!
')
end
it "should return the original body" do
get "/"
body.should == 'HelloWorld!
'
end
it "should return the correct Content Length" do
get "/"
headers['Content-Length'].should == Rack::Utils.bytesize(body).to_s
end
end
end
ruby-rack-pjax-0.7.0/spec/spec.opts 0000664 0000000 0000000 00000000010 12116363452 0017142 0 ustar 00root root 0000000 0000000 --color
ruby-rack-pjax-0.7.0/spec/spec_helper.rb 0000664 0000000 0000000 00000001050 12116363452 0020124 0 ustar 00root root 0000000 0000000 require "rubygems"
require "bundler"
Bundler.setup
$:.unshift File.expand_path("../../lib", __FILE__)
require "rack-pjax"
Bundler.require(:test)
# helpers ripped from wycat's Rack::Offline
# (https://github.com/wycats/rack-offline/blob/master/spec/spec_helper.rb)
module Rack::Test::Methods
def self.included(klass)
class << klass
attr_accessor :app
end
end
def body
last_response.body
end
def status
last_response.status
end
def headers
last_response.headers
end
def app
self.class.app
end
end