Permalink
Browse files

fix package repo

  • Loading branch information...
1 parent 9a41455 commit e4bd68f2c99602dfe9eb9c3f315a2dbc1ecce0ec @crcn crcn committed Feb 17, 2012
Showing with 71 additions and 40 deletions.
  1. +2 −0 README.md
  2. +9 −11 package.json
  3. +60 −29 project.sublime-workspace
View
@@ -1,5 +1,7 @@
## Connect router with syntactic sugar
+
+
## Basic Example
```javascript
View
@@ -2,19 +2,17 @@
"name": "connect-router",
"description": "Robust routing for express.js",
"version": "0.0.2",
- "repository": {
- },
- "engines": {
- },
+ "repository": {},
+ "engines": {},
"dependencies": {
- "dolce":"*"
+ "dolce": "*"
},
"devDependencies": {
- "express":"*",
- "connect":"*",
- "crema":"*",
- "haba":"*",
+ "express": "*",
+ "connect": "*",
+ "crema": "*",
+ "haba": "*",
"ebnf-diagram": "git+https://crcn@github.com/crcn/node-ebnf-diagram.git"
},
- "main":"./lib/index.js"
-}
+ "main": "./lib/index.js"
+}
View
@@ -20,10 +20,18 @@
}
},
{
- "file": "lib/index.js",
+ "file": "/tmp/subl stdin UuNTQR.txt",
"settings":
{
- "buffer_size": 1825,
+ "buffer_size": 0,
+ "line_ending": "Unix"
+ }
+ },
+ {
+ "file": "/tmp/subl stdin VVqAVQ.txt",
+ "settings":
+ {
+ "buffer_size": 0,
"line_ending": "Unix"
}
},
@@ -107,10 +115,7 @@
}
},
{
- "contents": "## Connect router with syntactic sugar\n\n\n\n## Basic Example\n\n```javascript\nvar express = require('express'),\napp = express.createServer(),\nconnectRouter = require('connect-router');\n\napp.use(connectRouter(function(router) {\n \n \n //you can use existing middleware to explicitly define\n //them in routes\n router.on('parseBody', express.bodyParser());\n\n /**\n * checks if a user exists\n */\n\n router.on('user/exists', function(req, res, next) {\n \n //pseudocode userExists func\n if(userExists(req.query.username)) {\n res.send('That username already exists');\n return;\n }\n\n next();\n });\n\n /**\n * Check if the user exists before signing up\n */\n\n router.on('-method=POST parseBody -> user/exists -> signup', function(req, res, next) {\n \n res.send('Successfuly signed up ');\n\n });\n\n}));\n\n//OR load routes from a directory\napp.use(connectRouter(__dirname + '/path/to/routes', 'another/path/to/traverse/**/*')); \n\n\napp.listen(8080);\n```\n\n## Syntax\n\n![Alt syntax](http://i.imgur.com/Q3IJz.png)\n\n## API\n\n### .router(route, ...);\n\nLoads in the given routes. Can be a function, or a list of paths to load in. For example:\n\n```javascript\n\n//scans a directory for routes\nconnectRouter(__dirname + '/path/to/scan');\n\n//recursively scans paths for routes\nconnectRouter(__dirname + '/path/to/scan/**/*');\n\n//scans for files ending in .route.js\nconnectRouter(__dirname + '/path/to/scan/**/*.route.js');\n\n//load in a func\nconnectRouter(function(router) {\n\n router.on('something', function(req, res) {\n res.send('done!')\n });\n\n});\n\n\n```\n\nA route plugin should look something like this:\n\n```javascript\n\nexports.plugin = function(router) {\n \n router.on('-method=POST signup', function() {\n //do stuff\n });\n}\n\n```\n\n\n\n## Explicit Middleware\n\nExplicit middleware is defined by using the `->` token. The basic example above uses explicit middleware, but here's another example:\n\n```javascript\n\nrouter.on('validate/token', function(req, res, next) {\n \n if(!tokenValid(req.data.token)) {\n res.send('That token is invalid');\n }\n\n req.profile = { username: 'someUsername' };\n\n next();\n\n});\n\n//validate the user is logged in BEFORE returning the user profile\nrouter.on('-method=GET validate/token -> my/profile', function(req, res, next) {\n \n //do stuff with req.profile\n \n res.send('Your profile stuff');\n\n});\n\n```\n\n## Implicit Middleware\n\nImplicit middleware is used to *extend* existing routes. This is certainly useful if you want to drop in plugins which are specific to a given route. A good use case:\n\n\n### beta_user.js:\n\n```javascript\n\n//Since we're in beta, extend the signup route. If the user has been invited, then\n//go onto the ORIGINAL signup route, otherwise return an error. \n\n//AFTER XXXX is out of beta, all we need to do is remove beta_user.js, and users\n//can signup without any constraints.\nrouter.on('-method=POST signup/*', function(req, res, next) {\n \n if(!userInvited(req.data.signupToken)) {\n res.send('You have not been invited yet.');\n return;\n }\n\n next();\n});\n\n```\n\n### user.js\n\n```javascript\nrouter.on('-method=POST signup', function(req, res, next) {\n \n res.send('thanks for signing up!');\n\n\n});\n```\n\n## Greedy Middleware\n\nGreedy middleware allows you to wrap around entire paths. `some/route/**` means any path *after* `**` must go through this middleware. Here's an example:\n\n```javascript\n\n//injected as middleware if -perm is provided. -perm tags flag that a route\n//requires authorization\nrouter.on('-perm /**', function(req, res, next) {\n \n if(isAuthorized(req.data.userId, req.last.tags.perm)) {\n res.send('Not Authorized');\n return;\n }\n\n next();\n});\n\n\n//goes through permissions middleware\nrouter.on('-perm=SUPER invite/user', function(req, res, next) {\n \n res.send('You have invited a user!');\n\n});\n\n//does NOT go through perm middleware\nrouter.on('some/public/route', function(req, res, next) {\n \n res.send('You have invited a user!');\n\n});\n```\n\nNote that greedy middleware is filterable based on the route tags. You can define anything you want. Here's another\nexample:\n\n```javascript\n\n//if POST is present, then automatically parse the body\nrouter.on('-method=POST /**', express.parseBody());\n\n//body is automatically parsed for us\nrouter.on('-method=POST signup', function(req, res) {\n\n res.send('Thanks for signing up!');\n\n});\n```\n\n\n\n\n",
"file": "README.md",
- "file_size": 4266,
- "file_write_time": 1327340445000000,
"settings":
{
"buffer_size": 4268,
@@ -166,6 +171,7 @@
},
"file_history":
[
+ "/Users/craig/Dropbox/Developer/Public/connect-router/lib/index.js",
"/Users/craig/Dropbox/Developer/Public/dolce/examples/param.js",
"/Volumes/minimac/Users/craig/Dropbox/Developer/Public/haba/examples/test1/plugins/hello1.js",
"/Volumes/minimac/Users/craig/Dropbox/Developer/Public/haba/lib/plugins/remote.js",
@@ -343,7 +349,7 @@
"groups":
[
{
- "selected": 1,
+ "selected": 13,
"sheets":
[
{
@@ -374,33 +380,58 @@
},
{
"buffer": 1,
- "file": "lib/index.js",
+ "file": "/tmp/subl stdin UuNTQR.txt",
"settings":
{
- "buffer_size": 1825,
+ "buffer_size": 0,
"regions":
{
},
"selection":
[
[
- 828,
- 828
+ 0,
+ 0
]
],
"settings":
{
- "syntax": "Packages/JavaScript/JavaScript.tmLanguage",
- "translate_tabs_to_spaces": false
+ "syntax": "Packages/Text/Plain text.tmLanguage"
},
"translation.x": 0.0,
- "translation.y": 437.0,
+ "translation.y": 0.0,
"zoom_level": 1.0
},
"type": "text"
},
{
"buffer": 2,
+ "file": "/tmp/subl stdin VVqAVQ.txt",
+ "settings":
+ {
+ "buffer_size": 0,
+ "regions":
+ {
+ },
+ "selection":
+ [
+ [
+ 0,
+ 0
+ ]
+ ],
+ "settings":
+ {
+ "syntax": "Packages/Text/Plain text.tmLanguage"
+ },
+ "translation.x": 0.0,
+ "translation.y": 0.0,
+ "zoom_level": 1.0
+ },
+ "type": "text"
+ },
+ {
+ "buffer": 3,
"file": "examples/plugin.js",
"settings":
{
@@ -427,7 +458,7 @@
"type": "text"
},
{
- "buffer": 3,
+ "buffer": 4,
"file": "examples/plugins/signup.js",
"settings":
{
@@ -453,7 +484,7 @@
"type": "text"
},
{
- "buffer": 4,
+ "buffer": 5,
"file": "examples/plugins/betaSignup.js",
"settings":
{
@@ -479,7 +510,7 @@
"type": "text"
},
{
- "buffer": 5,
+ "buffer": 6,
"file": "examples/auth.js",
"settings":
{
@@ -506,7 +537,7 @@
"type": "text"
},
{
- "buffer": 6,
+ "buffer": 7,
"file": "test/benchmark-routes.js",
"settings":
{
@@ -532,7 +563,7 @@
"type": "text"
},
{
- "buffer": 7,
+ "buffer": 8,
"file": "test/benchmark.js",
"settings":
{
@@ -559,7 +590,7 @@
"type": "text"
},
{
- "buffer": 8,
+ "buffer": 9,
"settings":
{
"buffer_size": 0,
@@ -585,7 +616,7 @@
"type": "text"
},
{
- "buffer": 9,
+ "buffer": 10,
"file": "package.json",
"settings":
{
@@ -613,7 +644,7 @@
"type": "text"
},
{
- "buffer": 10,
+ "buffer": 11,
"file": "node_modules/express/index.js",
"settings":
{
@@ -639,7 +670,7 @@
"type": "text"
},
{
- "buffer": 11,
+ "buffer": 12,
"file": "node_modules/express/lib/http.js",
"settings":
{
@@ -667,7 +698,7 @@
"type": "text"
},
{
- "buffer": 12,
+ "buffer": 13,
"file": "README.md",
"settings":
{
@@ -678,8 +709,8 @@
"selection":
[
[
- 3722,
- 3722
+ 4264,
+ 4264
]
],
"settings":
@@ -688,13 +719,13 @@
"translate_tabs_to_spaces": false
},
"translation.x": 0.0,
- "translation.y": 2567.0,
+ "translation.y": 2354.0,
"zoom_level": 1.0
},
"type": "text"
},
{
- "buffer": 13,
+ "buffer": 14,
"file": "/tmp/subl stdin 8xPbpg.txt",
"settings":
{
@@ -720,7 +751,7 @@
"type": "text"
},
{
- "buffer": 14,
+ "buffer": 15,
"file": "build/syntax.ebnf",
"settings":
{
@@ -746,7 +777,7 @@
"type": "text"
},
{
- "buffer": 15,
+ "buffer": 16,
"file": "build/build-ebnf",
"settings":
{

0 comments on commit e4bd68f

Please sign in to comment.