pax_global_header00006660000000000000000000000064121163634520014515gustar00rootroot0000000000000052 comment=e8ff938adc74078fcdf205e2731904cefbeb7cd6 ruby-rack-pjax-0.7.0/000077500000000000000000000000001211636345200143605ustar00rootroot00000000000000ruby-rack-pjax-0.7.0/.gitignore000066400000000000000000000000701211636345200163450ustar00rootroot00000000000000*.gem .bundle Gemfile.lock pkg/* .rvmrc .rbenv-version ruby-rack-pjax-0.7.0/.travis.yml000066400000000000000000000001141211636345200164650ustar00rootroot00000000000000rvm: - 1.8.7 - 1.9.2 - 1.9.3 - jruby branches: only: - master ruby-rack-pjax-0.7.0/Gemfile000066400000000000000000000002051211636345200156500ustar00rootroot00000000000000source "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/LICENSE000066400000000000000000000020521211636345200153640ustar00rootroot00000000000000Copyright (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.md000066400000000000000000000046711211636345200156470ustar00rootroot00000000000000Rack-pjax [![travis](https://secure.travis-ci.org/eval/rack-pjax.png?branch=master)](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). [![railscast](http://railscasts.com/assets/railscasts_logo-1eeafbafc2154fc5340c0a9800f402fd.png)](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/Rakefile000066400000000000000000000005271211636345200160310ustar00rootroot00000000000000require '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/000077500000000000000000000000001211636345200151265ustar00rootroot00000000000000ruby-rack-pjax-0.7.0/lib/rack-pjax.rb000066400000000000000000000000431211636345200173300ustar00rootroot00000000000000require 'rack' require "rack/pjax" ruby-rack-pjax-0.7.0/lib/rack/000077500000000000000000000000001211636345200160465ustar00rootroot00000000000000ruby-rack-pjax-0.7.0/lib/rack/pjax.rb000066400000000000000000000021161211636345200173350ustar00rootroot00000000000000require '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/000077500000000000000000000000001211636345200170105ustar00rootroot00000000000000ruby-rack-pjax-0.7.0/lib/rack/pjax/version.rb000066400000000000000000000000711211636345200210200ustar00rootroot00000000000000module Rack class Pjax VERSION = "0.7.0" end end ruby-rack-pjax-0.7.0/metadata.yml000066400000000000000000000041551211636345200166700ustar00rootroot00000000000000--- !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.gemspec000066400000000000000000000014531211636345200176100ustar00rootroot00000000000000# -*- 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/000077500000000000000000000000001211636345200153125ustar00rootroot00000000000000ruby-rack-pjax-0.7.0/spec/rack/000077500000000000000000000000001211636345200162325ustar00rootroot00000000000000ruby-rack-pjax-0.7.0/spec/rack/pjax_spec.rb000066400000000000000000000072161211636345200205410ustar00rootroot00000000000000require 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 => 'Hello
World!
') 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 => '

World!

') get "/", {}, {"HTTP_X_PJAX" => "true"} body.should == '

World!

' end it "should handle html5 br tags correctly" do self.class.app = generate_app(:body => '

foo
bar

') 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 => 'Hello
World!
') end it "should return the original body" do get "/" body.should == 'Hello
World!
' 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.opts000066400000000000000000000000101211636345200171420ustar00rootroot00000000000000--color ruby-rack-pjax-0.7.0/spec/spec_helper.rb000066400000000000000000000010501211636345200201240ustar00rootroot00000000000000require "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