From 32b1f3a24ae60407aaaea14c72ccacc42c171c4d Mon Sep 17 00:00:00 2001 From: Arthur Corenzan Date: Wed, 13 Mar 2013 07:25:25 -0700 Subject: [PATCH] Create gh-pages branch via GitHub --- index.html | 78 +++++++++++++++++++++++++++++++++++++++-------------- params.json | 2 +- 2 files changed, 59 insertions(+), 21 deletions(-) diff --git a/index.html b/index.html index c7ad051..044ea58 100644 --- a/index.html +++ b/index.html @@ -34,23 +34,45 @@

WayJS

Lightweight and flexible URL pattern matching in JavaScript.

-

Tests:

+

Test:

You'll need mocha to run the tests.

-

Run $ 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.

+

If you already have mocha installed globally you can simply run $ mocha.

-

Then run $ mocha.

+

If not, you can install the dependencies with $ npm install and then run $ npm test. No need to install mocha with -g or anything.

Minify:

You'll need uglify-js to minify the script.

-

Install it with $ npm install -g uglify-js, then run $ make.

+

Install the dependencies with $ npm install and then run $ npm run minify.

Usage:

-

Register a new route:

+

First thing is to create a new instance.

+ +

In browser:

+ +
var way = new Way();
+
+ +

With AMD/require.js:

+ +
require('way', function(Way) {
+  var way = new Way();
+});
+
+ +

Or with Node:

+ +
var Way, way;
+
+Way = require('way');
+way = new Way();
+
+ +

Now, to register a new route:

way.map('/hello/world', function() {
   console.log('Hello, world');
@@ -62,31 +84,39 @@ 

Usage:

var match = way.match('/hello/world');
 
-

This will return the first route to match or undefined if none.

- -

The route object has the collection of actions and eventually parsed parameters.

+

This will return an object or undefined if no route matches. This object has the collection of actions and parameters.

match.actions; //-> [function() { console.log('Hello, world'); }]
 match.params;  //-> {}
 
-

You can provide multiple actions.

+

You can provide n actions when mapping a route.

-
way.map('/hello/world', function() {/* 1 */}, function() {/* 2 */});
+
way.map('/hello/world', function() {/* 1 */}, function() {/* 2 */}, ...);
 
-

That 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. :)

+

Once you have a match, WayJS get out of the way. What to do with the action and parameters is totally up to you.

-

WayJS works in both browser and Node.

+

A common approach is to iterate over the actions, passing the parameters, and if one of them return false, you break the chain:

+ +
for(i = 0, t = match.actions.length; t--; i++) {
+  if(match.actions[i](match.params) === false) {
+    break;
+  }
+}
+
+
+ +

But that's just a simple suggestion. You can do whatever you need.

Pattern syntax:

Named parameters

-

Capture anything except forward slashes and save in way.params with given name.

+

Capture anything except forward slashes and save in params with given name.

-
way.map('/log/:message', function() {
-  console.log(way.params.message);
+
way.map('/log/:message', function(params) {
+  console.log(params.message);
 });
 
@@ -101,18 +131,26 @@

Optional groups

Splats

-

Capture everything, including slashes and save in way.params.splat. You can include multiple splats, returning an array.

+

Capture everything, including slashes and save in params.splat. You can include multiple splats, returning an array.

-
way.map('/goto/*', function() {
-  console.log('Goto: ', way.params.splat[0]);
+
way.map('/goto/*', function(params) {
+  console.log('Goto: ', params.splat[0]);
 });
 
-

All the special syntaxes above can be combined to create powerful routing patterns.

+

All the special syntaxes above can be combined to create powerful matching patterns.

Changelog:

-

v0.3.4 2012-09-06

+

v0.4.0 2013-03-13

+ +
    +
  • Now Way constructor is properly exposed instead of an instance
  • +
  • Moved routes out of the constructor to the prototype
  • +
  • Fixed docs typos and outdated information
  • +
  • Updated tests accordingly
  • +
  • Dropped Makefile and in favor of npm scripts
  • +

v0.3.4 2012-09-06

  • Fixed bug when casting #map arguments as array
  • diff --git a/params.json b/params.json index da7bb58..aaceef1 100644 --- a/params.json +++ b/params.json @@ -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."} \ No newline at end of file +{"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."} \ No newline at end of file