Skip to content

Commit

Permalink
Updated docs
Browse files Browse the repository at this point in the history
  • Loading branch information
IonicaBizau committed Aug 29, 2017
1 parent ad7078d commit f68df7a
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 75 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@
*~
*.log
node_modules
*.env
48 changes: 42 additions & 6 deletions DOCUMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,49 @@

You can see below the API reference of this module.

### Plugin Configuration
### `bloggify:init(config)`
If the routes (default: `app/routes`) folder exists, it will dictate the routes structure. For example:

`_` is alias for `index`. `_foo` is alias for `:foo`

```
routes/
├── 404.ajs << 404 page
├── _.ajs << The index page (loaded on `/`)
├── api << Rest API (`/api`)
│   ├── index.js << Api Handlers (e.g. sending a custom 404)
│   └── users << The `/api/users[/...]` endpoint
│   ├── index.js << Handling `/api/users` (sending the list of users)
│   └── _username << Handling `/api/users/:username`
│   └── index.js << Fetching the user, by username, and sending it
└── users << The users list, in HTML format (`/users`)
├── _.ajs << The `/users` view
├── _.js << The `/users` controler
└── _user << `/users/:user` endpoint
├── _.ajs << View
└── _.js << Controller
```

The controller files look like this:

```js
// Before hook
exports.before = (ctx, cb) => ...

// After hook
exports.after = (ctx, cb) => ...

// Handle all the methods
// Alias for module.exports = ctx => ...
exports.all = ctx => ...

// Handle post requests
exports.post = ctx => ...
```

#### Params
- **Object** `config`:
- `routes_dir` (String): The path to the directory where the routes are stored. They should be randable view files. For dynamic routes, use the `_`character.
- `controllers_dir` (String): The path to the controllers directory.
- `error_pages` (Object): The error pages template names.
- `404` (String): The path to the `404` error page.
- `500` (String): The path to the `500` error page.
- `bad_csrf` (String): The path the template that should be rendered when a bad CSRF token is sent to the server.

"/path/to/route": { controllerPath, viewPath }

103 changes: 35 additions & 68 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,87 +12,54 @@ $ npm i --save bloggify-flexible-router
```


## :clipboard: Example

## :memo: Documentation


```js
// Config
/*
{
"bloggify-flexible-router": {
"controllers_dir": "app/controllers",
"routes_dir": "app/routes",
"error_pages": {
"404": "404.ajs",
"500": "500.ajs",
"bad_csrf": "422.ajs"
}
}
}
*/

// The app/routes contains:
// ├── 404.ajs
// ├── 422.ajs
// ├── 500.ajs
// └── users
// └── _user
// └── index.ajs

// The app/controllers contain the controllers. For instance, app/users/_user/index.js would look like this:
const USERS = {
"Alice": {
name: "Alice"
, location: "Earth"
}
};

// Before middleware
exports.before = (ctx, cb) => { /* ... */ };

// GET requests
// You can use `all`, `post`, `get` etc.
exports.get = (ctx, cb) => {
const user = USERS[ctx.params.user];

// End with a 404 if the user is not found
if (!user) {
return ctx.next();
}

// Pass the data to the template
cb(null, {
user
});
};

// After middleware
exports.after = (ctx, cb) => { /* ... */ };
```
### `bloggify:init(config)`
If the routes (default: `app/routes`) folder exists, it will dictate the routes structure. For example:

## :question: Get Help
`_` is alias for `index`. `_foo` is alias for `:foo`

There are few ways to get help:
```
routes/
├── 404.ajs << 404 page
├── _.ajs << The index page (loaded on `/`)
├── api << Rest API (`/api`)
│   ├── index.js << Api Handlers (e.g. sending a custom 404)
│   └── users << The `/api/users[/...]` endpoint
│   ├── index.js << Handling `/api/users` (sending the list of users)
│   └── _username << Handling `/api/users/:username`
│   └── index.js << Fetching the user, by username, and sending it
└── users << The users list, in HTML format (`/users`)
├── _.ajs << The `/users` view
├── _.js << The `/users` controler
└── _user << `/users/:user` endpoint
├── _.ajs << View
└── _.js << Controller
```

1. Please [post questions on Stack Overflow](https://stackoverflow.com/questions/ask). You can open issues with questions, as long you add a link to your Stack Overflow question.
2. For bug reports and feature requests, open issues. :bug:
3. For direct and quick help from me, you can [use Codementor](https://www.codementor.io/johnnyb). :rocket:
The controller files look like this:

```js
// Before hook
exports.before = (ctx, cb) => ...

## :memo: Documentation
// After hook
exports.after = (ctx, cb) => ...

// Handle all the methods
// Alias for module.exports = ctx => ...
exports.all = ctx => ...

### `bloggify:init(config)`
// Handle post requests
exports.post = ctx => ...
```

#### Params
- **Object** `config`:
- `routes_dir` (String): The path to the directory where the routes are stored. They should be randable view files. For dynamic routes, use the `_`character.
- `controllers_dir` (String): The path to the controllers directory.
- `error_pages` (Object): The error pages template names.
- `404` (String): The path to the `404` error page.
- `500` (String): The path to the `500` error page.
- `bad_csrf` (String): The path the template that should be rendered when a bad CSRF token is sent to the server.

"/path/to/route": { controllerPath, viewPath }



Expand Down

0 comments on commit f68df7a

Please sign in to comment.