Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

first commit

  • Loading branch information...
commit d4acdc7b9c1fd3d88d783a52e47ee60ce1ce0d64 0 parents
@dakatsuka authored
Showing with 101 additions and 0 deletions.
  1. +19 −0 MIT-LICENSE
  2. +38 −0 README.md
  3. +22 −0 package.json
  4. +22 −0 pjax.js
19 MIT-LICENSE
@@ -0,0 +1,19 @@
+Copyright (c) 2011 Dai Akatsuka
+
+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.
38 README.md
@@ -0,0 +1,38 @@
+# express-pjax
+
+Express middleware for Pjax.
+
+## Installation
+
+ npm install express-pjax
+
+## Usage
+
+If you use `res.renderPjax` method, the request of pjax will be handled automatically.
+
+```
+var express = require('express');
+var pjax = require('express-pjax');
+var app = express.createServer();
+
+app.configure(function() {
+ app.use(pjax());
+ // -- snip --
+});
+
+app.get('/', function(req, res) {
+ res.renderPjax('index', { locals: { hello: "Hello World!" } });
+});
+
+app.get('/foo', function(req, res) {
+ res.renderPjax('foo');
+});
+```
+
+## TODO
+
+* Support redirect.
+
+## Copyright
+
+Copyright (C) 2011 Dai Akatsuka, released under the MIT License.
22 package.json
@@ -0,0 +1,22 @@
+{
+ "name": "express-pjax",
+ "description": "Express middleware for Pjax.",
+ "version": "0.0.1",
+ "homepage": "http://github.com/dakatsuka/express-pjax",
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/dakatsuka/express-pjax.git"
+ },
+ "keywords": ["express", "pjax"],
+ "author": "Dai Akatsuka <d.akatsuka@gmail.com>",
+ "bugs": {
+ "url": "http://github.com/dakatsuka/express-pjax/issues"
+ },
+ "licenses": [
+ {
+ "type": "MIT",
+ "url": "http://github.com/dakatsuka/express-pjax/raw/master/MIT-LICENSE"
+ }
+ ],
+ "main": "./pjax.js"
+}
22 pjax.js
@@ -0,0 +1,22 @@
+module.exports = function() {
+ return function(req, res, next) {
+ if (req.header('X-PJAX')) {
+ req.pjax = true;
+ }
+
+ res.renderPjax = function(view, options, fn) {
+ if (req.pjax) {
+ if (options) {
+ options.layout = false;
+ } else {
+ options = {};
+ options.layout = false;
+ }
+ }
+
+ res.render(view, options, fn);
+ };
+
+ next();
+ };
+};
Please sign in to comment.
Something went wrong with that request. Please try again.