Skip to content

Commit

Permalink
docs: update README with async and custom tag (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
atian25 authored and dead-horse committed Nov 20, 2017
1 parent e2de00e commit 12ba643
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
@@ -1,8 +1,8 @@
sudo: false
language: node_js
node_js:
- '6'
- '8'
- '9'
install:
- npm i npminstall && npminstall
script:
Expand Down
35 changes: 28 additions & 7 deletions README.md
Expand Up @@ -54,11 +54,14 @@ Render in controller

```js
// {app_root}/app/controller/test.js
exports.list = function* () {
// this.body = yield this.renderString('{{ name }}', { name: 'local' });
// not need to assign this.render to this.body
yield this.render('test.nj', { name: 'view test' });
};
class TestController extends Controller {
async list() {
const ctx = this.ctx;
// ctx.body = await ctx.renderString('{{ name }}', { name: 'local' });
// not need to assign `ctx.render` to `ctx.body`
await ctx.render('test.nj', { name: 'view test' });
}
}
```

## Feature
Expand All @@ -72,9 +75,27 @@ exports.list = function* () {
// {app_root}/app/extend/filter.js
exports.hello = name => `hi, ${name}`;

// so you could use it at template
// {app_root}/app/controller/test.js
exports.list = function* () {
this.body = yield this.renderString('{{ name | hello }}', { name: 'egg' });
class TestController extends Controller {
async list() {
const ctx = this.ctx;
ctx.body = await ctx.renderString('{{ name | hello }}', { name: 'egg' });
};
}
```

### Tag

you can extend custom tag like this:

```js
// {app_root}/app.js
const markdown = require('nunjucks-markdown');
const marked = require('marked');

module.exports = app => {
markdown.register(app.nunjucks, marked);
};
```

Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
@@ -1,7 +1,7 @@
environment:
matrix:
- nodejs_version: '6'
- nodejs_version: '8'
- nodejs_version: '9'

install:
- ps: Install-Product node $env:nodejs_version
Expand Down
20 changes: 10 additions & 10 deletions package.json
Expand Up @@ -20,15 +20,15 @@
"nunjucks": "^3.0.1"
},
"devDependencies": {
"autod": "^2.9.0",
"autod": "^3.0.1",
"cheerio": "^1.0.0-rc.2",
"common-tags": "^1.4.0",
"egg": "^1.8.0",
"egg-bin": "^4.3.2",
"egg": "^1.11.0",
"egg-bin": "^4.3.5",
"egg-ci": "^1.8.0",
"egg-mock": "^3.12.1",
"egg-mock": "^3.13.1",
"egg-view": "^1.0.0",
"eslint": "^4.7.1",
"eslint": "^4.11.0",
"eslint-config-egg": "^5.1.1",
"marked": "^0.3.6",
"nunjucks-markdown": "^2.0.1"
Expand All @@ -38,20 +38,20 @@
},
"files": [
"app",
"config",
"lib",
"config",
"app.js"
],
"scripts": {
"test": "npm run lint -- --fix && npm run test-local",
"test": "npm run lint -- --fix && egg-bin pkgfiles && npm run test-local",
"test-local": "egg-bin test",
"cov": "egg-bin cov",
"lint": "eslint .",
"ci": "npm run lint && npm run cov",
"ci": "npm run lint && egg-bin pkgfiles --check && npm run cov",
"autod": "autod"
},
"ci": {
"version": "6, 8"
"version": "8, 9"
},
"repository": {
"type": "git",
Expand All @@ -61,4 +61,4 @@
"homepage": "https://github.com/eggjs/egg-view-nunjucks#readme",
"author": "TZ <atian25@qq.com>",
"license": "MIT"
}
}

0 comments on commit 12ba643

Please sign in to comment.