Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
59 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"name":"WayJS","tagline":"Lightweight and flexible URL pattern matching in JavaScript.","body":"# WayJS\r\n\r\nLightweight and flexible URL pattern matching in JavaScript.\r\n\r\n## Tests:\r\n\r\nYou'll need [mocha](https://github.com/visionmedia/mocha) to run the tests.\r\n\r\nRun `$ npm install -g mocha`. The `-g` flag tells the NPM to install the module globally so mocha's binaries goes in your `/usr/bin` directory.\r\n\r\nThen run `$ mocha`.\r\n\r\n## Minify:\r\n\r\nYou'll need [uglify-js](https://github.com/mishoo/UglifyJS) to minify the script.\r\n\r\nInstall it with `$ npm install -g uglify-js`, then run `$ make`.\r\n\r\n## Usage:\r\n\r\nRegister a new route:\r\n\r\n```javascript\r\nway.map('/hello/world', function() {\r\n console.log('Hello, world');\r\n});\r\n```\r\n\r\nThen match some path against route table:\r\n\r\n```javascript\r\nvar match = way.match('/hello/world');\r\n```\r\n\r\nThis will return the first route to match or `undefined` if none.\r\n\r\nThe route object has the collection of actions and eventually parsed parameters.\r\n\r\n```javascript\r\nmatch.actions; //-> [function() { console.log('Hello, world'); }]\r\nmatch.params; //-> {}\r\n```\r\n\r\nYou can provide multiple actions.\r\n\r\n```javascript\r\nway.map('/hello/world', function() {/* 1 */}, function() {/* 2 */});\r\n```\r\n\r\nThat way you have control over the flow and do things like if the first action do not return true, it won't call the next one, or pass the returning value from the current action to the next one, or anything else that suits you. I told you it was flexible. :)\r\n\r\nWayJS works in both browser and Node.\r\n\r\n## Pattern syntax:\r\n\r\n### Named parameters\r\n\r\nCapture anything except forward slashes and save in `way.params` with given name.\r\n\r\n way.map('/log/:message', function() {\r\n console.log(way.params.message);\r\n });\r\n\r\n### Optional groups\r\n\r\nMatches with or without the snippet inside the parenthesis.\r\n\r\n way.map('(/good)/bye', function() {\r\n console.log('Farewell!!');\r\n })\r\n\r\n### Splats\r\n\r\nCapture everything, including slashes and save in `way.params.splat`. You can include multiple splats, returning an array.\r\n\r\n way.map('/goto/*', function() {\r\n console.log('Goto: ', way.params.splat[0]);\r\n });\r\n\r\nAll the special syntaxes above can be combined to create powerful routing patterns.\r\n\r\n## Changelog:\r\n\r\n### v0.3.4 2012-09-06\r\n\r\n- Fixed bug when casting #map arguments as array\r\n\r\n### v0.3.3 2012-09-05\r\n\r\n- Added support for [requirejs](http://requirejs.org/)\r\n\r\n### v0.3.2 2012-09-05\r\n\r\n- Changed to multiple actions instead of allowing multiple matches\r\n- Accepts multiple splats\r\n- Tests updated accordingly\r\n\r\n### v0.2.1 2012-08-24\r\n\r\n- Changed patterns regex to do exact matches\r\n\r\n### v0.2.0 2012-08-23\r\n\r\n- Accepts multiple matches, returning a collection of them\r\n- Fixed bug with parameter values being sliced\r\n\r\n### v0.1.0 2012-08-21\r\n\r\n- First version\r\n","google":"UA-38812126-1","note":"Don't delete this file! It's used internally to help with page regeneration."} | ||
{"name":"WayJS","tagline":"Lightweight and flexible URL pattern matching in JavaScript.","body":"# WayJS\r\n\r\nLightweight and flexible URL pattern matching in JavaScript.\r\n\r\n## Test:\r\n\r\nYou'll need [mocha](https://github.com/visionmedia/mocha) to run the tests.\r\n\r\nIf you already have `mocha` installed globally you can simply run `$ mocha`.\r\n\r\nIf not, you can install the dependencies with `$ npm install` and then run `$ npm test`. No need to install `mocha` with `-g` or anything.\r\n\r\n## Minify:\r\n\r\nYou'll need [uglify-js](https://github.com/mishoo/UglifyJS) to minify the script.\r\n\r\nInstall the dependencies with `$ npm install` and then run `$ npm run minify`.\r\n\r\n## Usage:\r\n\r\nFirst thing is to create a new instance.\r\n\r\nIn browser:\r\n\r\n```javascript\r\nvar way = new Way();\r\n```\r\n\r\nWith AMD/require.js:\r\n\r\n```javascript\r\nrequire('way', function(Way) {\r\n var way = new Way();\r\n});\r\n```\r\n\r\nOr with Node:\r\n\r\n```javascript\r\nvar Way, way;\r\n\r\nWay = require('way');\r\nway = new Way();\r\n```\r\n\r\nNow, to register a new route:\r\n\r\n```javascript\r\nway.map('/hello/world', function() {\r\n console.log('Hello, world');\r\n});\r\n```\r\n\r\nThen match some path against route table:\r\n\r\n```javascript\r\nvar match = way.match('/hello/world');\r\n```\r\n\r\nThis will return an `object` or `undefined` if no route matches. This object has the collection of actions and parameters.\r\n\r\n```javascript\r\nmatch.actions; //-> [function() { console.log('Hello, world'); }]\r\nmatch.params; //-> {}\r\n```\r\n\r\nYou can provide `n` actions when mapping a route.\r\n\r\n```javascript\r\nway.map('/hello/world', function() {/* 1 */}, function() {/* 2 */}, ...);\r\n```\r\n\r\nOnce you have a match, WayJS get out of the way. What to do with the action and parameters is totally up to you.\r\n\r\nA common approach is to iterate over the actions, passing the parameters, and if one of them return false, you break the chain:\r\n\r\n```javascript\r\nfor(i = 0, t = match.actions.length; t--; i++) {\r\n if(match.actions[i](match.params) === false) {\r\n break;\r\n }\r\n}\r\n\r\n```\r\n\r\nBut that's just a simple suggestion. You can do whatever you need.\r\n\r\n## Pattern syntax:\r\n\r\n### Named parameters\r\n\r\nCapture anything except forward slashes and save in `params` with given name.\r\n\r\n way.map('/log/:message', function(params) {\r\n console.log(params.message);\r\n });\r\n\r\n### Optional groups\r\n\r\nMatches with or without the snippet inside the parenthesis.\r\n\r\n way.map('(/good)/bye', function() {\r\n console.log('Farewell!!');\r\n })\r\n\r\n### Splats\r\n\r\nCapture everything, including slashes and save in `params.splat`. You can include multiple splats, returning an array.\r\n\r\n way.map('/goto/*', function(params) {\r\n console.log('Goto: ', params.splat[0]);\r\n });\r\n\r\nAll the special syntaxes above can be combined to create powerful matching patterns.\r\n\r\n## Changelog:\r\n\r\n### v0.4.0 2013-03-13\r\n\r\n- Now Way constructor is properly exposed instead of an instance\r\n- Moved `routes` out of the constructor to the prototype\r\n- Fixed docs typos and outdated information\r\n- Updated tests accordingly\r\n- Dropped Makefile and in favor of npm scripts\r\n\r\n### v0.3.4 2012-09-06\r\n\r\n- Fixed bug when casting #map arguments as array\r\n\r\n### v0.3.3 2012-09-05\r\n\r\n- Added support for [requirejs](http://requirejs.org/)\r\n\r\n### v0.3.2 2012-09-05\r\n\r\n- Changed to multiple actions instead of allowing multiple matches\r\n- Accepts multiple splats\r\n- Tests updated accordingly\r\n\r\n### v0.2.1 2012-08-24\r\n\r\n- Changed patterns regex to do exact matches\r\n\r\n### v0.2.0 2012-08-23\r\n\r\n- Accepts multiple matches, returning a collection of them\r\n- Fixed bug with parameter values being sliced\r\n\r\n### v0.1.0 2012-08-21\r\n\r\n- First version\r\n","google":"UA-38812126-1","note":"Don't delete this file! It's used internally to help with page regeneration."} |