Skip to content

Commit

Permalink
docs(generate): create readme, apidocs and code comments
Browse files Browse the repository at this point in the history
  • Loading branch information
tunnckoCore committed Oct 9, 2016
1 parent 7b3e1ab commit 1b1400e
Show file tree
Hide file tree
Showing 4 changed files with 223 additions and 2 deletions.
22 changes: 22 additions & 0 deletions .verb.md
Expand Up @@ -19,6 +19,28 @@ const {%= varname %} = require('{%= name %}')

{%= apidocs('index.js') %}

**Example `views/home.js`**

> Here you can even use [yo-yo][], instead of [bel][]. Or just return
a buffer or stream and just pass `options.toString: false` option.

```js
'use strict'

var bel = require('bel')

module.exports = function home (state) {
return bel`<section>
<h1>${state.heading}</h1>
<p>${state.description}</p>
<h2>${state.subhead}</h2>
<ul>${state.services.map((service) => {
return bel`<li>${service}</li>`
})}</ul>
</section>`
}
```

{% if (verb.related && verb.related.list && verb.related.list.length) { %}
## Related
{%= related(verb.related.list, {words: 12}) %}
Expand Down
144 changes: 144 additions & 0 deletions README.md
@@ -0,0 +1,144 @@
# [koa-bel][author-www-url] [![npmjs.com][npmjs-img]][npmjs-url] [![The MIT License][license-img]][license-url] [![npm downloads][downloads-img]][downloads-url]

> View engine for `koa` without any deps, built to be used with `bel`. Any other engines that can be written in `.js` files would work, too.
[![code climate][codeclimate-img]][codeclimate-url] [![standard code style][standard-img]][standard-url] [![travis build status][travis-img]][travis-url] [![coverage status][coveralls-img]][coveralls-url] [![dependency status][david-img]][david-url]

## Install

```
npm i koa-bel --save
```

## Usage
> For more use-cases see the [tests](./test.js)
```js
const koaBel = require('koa-bel')
```

### [koaBel](index.js#L58)
> Javascript template views for [koa][]@2. You can use [koa-convert][] if you want to work in koa@1.x version.
> Cool thing about that, is it not requires your
templates to be [bel][] or something other like [yo-yo][],
or any other DOM thingy. You can simple return a stream
or buffer or anything that can be added to `ctx.body`.
By default it calls `.toString()` on the returned value, but
you can bypass that if you pass `opts.toString: false` option.

**Params**

* `<dir>` **{String|Buffer}**: directory to read the views
* `[opts]` **{Object}**: optional options
* `returns` **{Function}**: plugin for **[koa][] version 2**

**Example**

```js
const Koa = require('koa')
const bel = require('koa-bel')
const app = new Koa()

const port = 4290

app.use(bel('./views'))
app.use((ctx, next) => {
ctx.render('home', {
heading: 'Welcome page',
description: 'This is our cool landing page, man!',
subhead: 'What we offer?',
services: [
'Realtime Web Apps',
'Security and Simplicity',
'Logo Design and Prototypes'
]
})
return next()
})

app.listen(port, (err) => {
console.log(`Server start listening on http://localhost:${port}`)
})
```

**Example `views/home.js`**

> Here you can even use [yo-yo][], instead of [bel][]. Or just return
a buffer or stream and just pass `options.toString: false` option.

```js
'use strict'

var bel = require('bel')

module.exports = function home (state) {
return bel`<section>
<h1>${state.heading}</h1>
<p>${state.description}</p>
<h2>${state.subhead}</h2>
<ul>${state.services.map((service) => {
return bel`<li>${service}</li>`
})}</ul>
</section>`
}
```

## Contributing
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/tunnckoCore/koa-bel/issues/new).
But before doing anything, please read the [CONTRIBUTING.md](./CONTRIBUTING.md) guidelines.

## [Charlike Make Reagent](http://j.mp/1stW47C) [![new message to charlike][new-message-img]][new-message-url] [![freenode #charlike][freenode-img]][freenode-url]

[![tunnckoCore.tk][author-www-img]][author-www-url] [![keybase tunnckoCore][keybase-img]][keybase-url] [![tunnckoCore npm][author-npm-img]][author-npm-url] [![tunnckoCore twitter][author-twitter-img]][author-twitter-url] [![tunnckoCore github][author-github-img]][author-github-url]

[bel]: https://github.com/shama/bel
[koa-convert]: https://github.com/gyson/koa-convert
[koa]: https://github.com/koajs/koa
[yo-yo]: https://github.com/maxogden/yo-yo

[npmjs-url]: https://www.npmjs.com/package/koa-bel
[npmjs-img]: https://img.shields.io/npm/v/koa-bel.svg?label=koa-bel

[license-url]: https://github.com/tunnckoCore/koa-bel/blob/master/LICENSE
[license-img]: https://img.shields.io/npm/l/koa-bel.svg

[downloads-url]: https://www.npmjs.com/package/koa-bel
[downloads-img]: https://img.shields.io/npm/dm/koa-bel.svg

[codeclimate-url]: https://codeclimate.com/github/tunnckoCore/koa-bel
[codeclimate-img]: https://img.shields.io/codeclimate/github/tunnckoCore/koa-bel.svg

[travis-url]: https://travis-ci.org/tunnckoCore/koa-bel
[travis-img]: https://img.shields.io/travis/tunnckoCore/koa-bel/master.svg

[coveralls-url]: https://coveralls.io/r/tunnckoCore/koa-bel
[coveralls-img]: https://img.shields.io/coveralls/tunnckoCore/koa-bel.svg

[david-url]: https://david-dm.org/tunnckoCore/koa-bel
[david-img]: https://img.shields.io/david/tunnckoCore/koa-bel.svg

[standard-url]: https://github.com/feross/standard
[standard-img]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg

[author-www-url]: http://www.tunnckocore.tk
[author-www-img]: https://img.shields.io/badge/www-tunnckocore.tk-fe7d37.svg

[keybase-url]: https://keybase.io/tunnckocore
[keybase-img]: https://img.shields.io/badge/keybase-tunnckocore-8a7967.svg

[author-npm-url]: https://www.npmjs.com/~tunnckocore
[author-npm-img]: https://img.shields.io/badge/npm-~tunnckocore-cb3837.svg

[author-twitter-url]: https://twitter.com/tunnckoCore
[author-twitter-img]: https://img.shields.io/badge/twitter-@tunnckoCore-55acee.svg

[author-github-url]: https://github.com/tunnckoCore
[author-github-img]: https://img.shields.io/badge/github-@tunnckoCore-4183c4.svg

[freenode-url]: http://webchat.freenode.net/?channels=charlike
[freenode-img]: https://img.shields.io/badge/freenode-%23charlike-5654a4.svg

[new-message-url]: https://github.com/tunnckoCore/ama
[new-message-img]: https://img.shields.io/badge/ask%20me-anything-green.svg

46 changes: 46 additions & 0 deletions index.js
Expand Up @@ -9,6 +9,52 @@

var path = require('path')

/**
* > Javascript template views for [koa][]@2. You can
* use [koa-convert][] if you want to work in koa@1.x version.
*
* > Cool thing about that, is it not requires your
* templates to be [bel][] or something other like [yo-yo][],
* or any other DOM thingy. You can simple return a stream
* or buffer or anything that can be added to `ctx.body`.
* By default it calls `.toString()` on the returned value, but
* you can bypass that if you pass `opts.toString: false` option.
*
* **Example**
*
* ```js
* const Koa = require('koa')
* const bel = require('koa-bel')
* const app = new Koa()
*
* const port = 4290
*
* app.use(bel('./views'))
* app.use((ctx, next) => {
* ctx.render('home', {
* heading: 'Welcome page',
* description: 'This is our cool landing page, man!',
* subhead: 'What we offer?',
* services: [
* 'Realtime Web Apps',
* 'Security and Simplicity',
* 'Logo Design and Prototypes'
* ]
* })
* return next()
* })
*
* app.listen(port, (err) => {
* console.log(`Server start listening on http://localhost:${port}`)
* })
* ```
*
* @param {String|Buffer} `<dir>` directory to read the views
* @param {Object} `[opts]` optional options
* @return {Function} plugin for **[koa][] version 2**
* @api public
*/

module.exports = function koaBel (dir, opts) {
dir = Buffer.isBuffer(dir) ? dir.toString() : dir

Expand Down
13 changes: 11 additions & 2 deletions package.json
Expand Up @@ -53,6 +53,15 @@
],
"lint": {
"reflinks": true
}
},
"related": {
"list": []
},
"reflinks": [
"bel",
"koa",
"koa-convert",
"yo-yo"
]
}
}
}

0 comments on commit 1b1400e

Please sign in to comment.