Skip to content

Commit

Permalink
docs: fix view plugin config at quickstart (eggjs#482)
Browse files Browse the repository at this point in the history
  • Loading branch information
atian25 authored and popomore committed Mar 1, 2017
1 parent 19c503b commit 73095e2
Show file tree
Hide file tree
Showing 14 changed files with 13 additions and 93 deletions.
2 changes: 1 addition & 1 deletion docs/source/en/intro/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ And enable it.

```js
// config/plugin.js
exports.view = {
exports.nunjucks = {
enable: true,
package: 'egg-view-nunjucks'
};
Expand Down
12 changes: 10 additions & 2 deletions docs/source/zh-cn/advanced/view-plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ module.exports = class EjsView {

## 插件配置

根据上面的命名约定,配置名一般为模板引起的名字,比如 ejs
根据上面的命名约定,配置名一般为模板引擎的名字,比如 ejs

插件的配置主要来自模板引擎的配置,可根据具体情况定义配置项,如 [ejs 的配置](https://github.com/mde/ejs#options)

Expand All @@ -122,7 +122,15 @@ module.exports = {

框架本身提供了 `ctx.helper` 供开发者使用,但有些情况下,我们希望对 helper 方法进行覆盖,仅在模板渲染时生效。

`helper.shtml` 在 controller 中使用时直接输出清洗后的 html,但在 [nunjucks] 模板中需要绕过模板引擎本身的 `escape` 机制,则可以如下:
在模板渲染中,我们经常会需要输出用户提供的 html 片段,通常需要使用 `egg-security` 插件提供的 `helper.shtml` 清洗下

```html
<div>{{ helper.shtml(data.content) | safe }}</div>
```

但如上代码所示,我们需要加上 ` | safe` 来告知模板引擎,该 html 是安全的,无需再次 `escape`,直接渲染。

而这样用起来比较麻烦,而且容易遗忘,所以我们可以封装下:

先提供一个 helper 子类:

Expand Down
2 changes: 1 addition & 1 deletion docs/source/zh-cn/intro/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ $ npm i egg-view-nunjucks --save

```js
// config/plugin.js
exports.view = {
exports.nunjucks = {
enable: true,
package: 'egg-view-nunjucks'
};
Expand Down
1 change: 1 addition & 0 deletions lib/egg.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ class EggApplication extends EggCore {
if (!(err instanceof Error)) {
const newError = new Error(String(err));
// err maybe an object, try to copy the name, message and stack to the new error instance
/* istanbul ignore else */
if (err) {
if (err.name) newError.name = err.name;
if (err.message) newError.message = err.message;
Expand Down
6 changes: 0 additions & 6 deletions test/fixtures/apps/view-framework/index.js

This file was deleted.

38 changes: 0 additions & 38 deletions test/fixtures/apps/view-framework/lib/view.js

This file was deleted.

3 changes: 0 additions & 3 deletions test/fixtures/apps/view-framework/package.json

This file was deleted.

5 changes: 0 additions & 5 deletions test/fixtures/apps/view/app/app.js

This file was deleted.

21 changes: 0 additions & 21 deletions test/fixtures/apps/view/app/controller/home.js

This file was deleted.

3 changes: 0 additions & 3 deletions test/fixtures/apps/view/app/extend/helper.js

This file was deleted.

7 changes: 0 additions & 7 deletions test/fixtures/apps/view/app/router.js

This file was deleted.

2 changes: 0 additions & 2 deletions test/fixtures/apps/view/app/view/index.html

This file was deleted.

1 change: 0 additions & 1 deletion test/fixtures/apps/view/config/config.default.js

This file was deleted.

3 changes: 0 additions & 3 deletions test/fixtures/apps/view/package.json

This file was deleted.

0 comments on commit 73095e2

Please sign in to comment.