Skip to content

Commit

Permalink
docs: rule for transforming filepath to properties (#547)
Browse files Browse the repository at this point in the history
  • Loading branch information
popomore authored and dead-horse committed Mar 13, 2017
1 parent d088283 commit 9eecf7b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
27 changes: 21 additions & 6 deletions docs/source/zh-cn/advanced/loader.md
Expand Up @@ -182,6 +182,17 @@ plugin1 为 framework1 依赖的插件,配置合并后 object key 的顺序会
- 加载时如果遇到同名的会覆盖,比如想要覆盖 `ctx.ip` 可以直接在应用的 `app/extend/context.js` 定义 ip 就可以了。
- [应用完整启动顺序查看框架开发](./framework.md)

### 文件加载规则

框架在加载文件时会进行转换,因为文件命名风格和 API 风格存在差异。我们推荐文件使用下划线,而 API 使用驼峰。比如 `app/service/user_info.js` 会转换成 `app.service.userInfo`

框架也支持连字符和驼峰的方式

- `app/service/user-info.js` => `app.service.userInfo`
- `app/service/userInfo.js` => `app.service.userInfo`

Loader 还提供了 [caseStyle](#caseStyle-boolean) 强制指定首字母大小写,比如加载 model 时 API 首字母大写,`app/model/user.js` => `app.model.User`,就可以指定 `caseStyle: 'upper'`

## 扩展 Loader

[Loader] 是一个基类,并根据文件加载的规则提供了一些内置的方法,但基本本身并不会去调用,而是由继承类调用。
Expand Down Expand Up @@ -346,19 +357,23 @@ app.loader.loadToApp(directory, 'model', {
});
```

#### lowercaseFirst [Boolean]
#### caseStyle [String]

文件的转换规则,可选为 `camel``upper``lower`,默认为 `camel`

是否强制将第一个字符转成小写,默认为 false
三者都会将文件名转换成驼峰,但是对于首字母的处理有所不同

比如加载 `app/controller/User.js`,如果为 true 加载后生成 `app.controller.user`
- `camel`:首字母不变。
- `upper`:首字母大写。
- `lower`:首字母小写。

在加载不同文件时配置不同

文件 | 配置
--- | ---
app/controller | true
app/middleware | true
app/service | true
app/controller | lower
app/middleware | lower
app/service | lower

#### override [Boolean]

Expand Down
2 changes: 1 addition & 1 deletion docs/source/zh-cn/core/cookie-and-session.md
@@ -1,7 +1,7 @@
title: cookie 与 session
---

### cookie
## cookie

HTTP 请求都是无状态的,但是我们的 web 应用通常都需要知道发起请求的人是谁。为了解决这个问题,HTTP 协议设计了一个特殊的请求头:[cookie](https://en.wikipedia.org/wiki/HTTP_cookie)。服务端可以通过响应头(set-cookie)将少量数据响应给客户端,浏览器会遵循协议将数据保存,并在下次请求同一个服务的时候带上(浏览器也会遵循协议,只在访问符合 cookie 指定规则的网站时带上对应的 cookie 来保证安全性)。

Expand Down

0 comments on commit 9eecf7b

Please sign in to comment.