Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
dakatsuka committed Nov 22, 2011
0 parents commit d4acdc7
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 0 deletions.
19 changes: 19 additions & 0 deletions 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 changes: 38 additions & 0 deletions 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 changes: 22 additions & 0 deletions 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 changes: 22 additions & 0 deletions 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();
};
};

0 comments on commit d4acdc7

Please sign in to comment.