Skip to content

Commit

Permalink
Keep it up-to-date
Browse files Browse the repository at this point in the history
  • Loading branch information
towerhe committed Feb 11, 2014
1 parent 86fbe70 commit aa3481a
Show file tree
Hide file tree
Showing 48 changed files with 713 additions and 158 deletions.
4 changes: 3 additions & 1 deletion data/guides.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"Ember.js 指南":
"指南与教程":
- title: 'Ember.js 指南'
url: 'index.html'
skip_sidebar: true
Expand Down Expand Up @@ -359,6 +359,8 @@ Cookbook:
url: "understanding-ember/keeping-templates-up-to-date"
- title: "调试"
url: "understanding-ember/debugging"
- title: "The Run Loop"
url: "understanding-ember/run-loop"
#Contributing to Ember.js:
#- title: "Adding New Features"
#url: "contributing/adding-new-features"
Expand Down
6 changes: 3 additions & 3 deletions lib/toc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ def guide_slug

def chapter_github_source_url
base_guide_url = "https://github.com/emberjs-cn/www.emberjs.cn/tree/master/source/guides"
if current_guide
return "#{base_guide_url}/#{current_guide['url']}.md"
if section_slug == guide_slug
return "#{base_guide_url}/#{current_guide['url']}/index.md"
else
return "#{base_guide_url}/index.md"
return "#{base_guide_url}/#{current_guide['url']}.md"
end
end

Expand Down
4 changes: 2 additions & 2 deletions source/bilingual_guides/concepts/naming-conventions.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ for your routes, controllers and templates.

`Ember.js`使用命名惯例来连接各个对象,而不是通过大量的引用。对于路由,控制器以及模板,你都应该使用此命名惯例。

You can usually guess the names, but this guide outlines, in one place, all of the naming conventions. In the following examples 'App' is a name that we chose to namespace or represent our Ember application when it was created, but you can theoretically choose any name you want for your application. We will show you later how to create an Ember application, but for now we will focus on conventions.
You can usually guess the names, but this guide outlines, in one place, all of the naming conventions. In the following examples 'App' is a name that we chose to namespace or represent our Ember application when it was created, but you can choose any name you want for your application. We will show you later how to create an Ember application, but for now we will focus on conventions.

有些时候,或许你可以猜到某些正确的命名,但是,这篇指南在此概述了所有的命名惯例。在下面的例子中'App'是被选来作为命名空间的名字,或者说用来代表Ember应用,当然理论上可以选择任何你喜欢的名字。后面我们将具体介绍如何创建一个Ember应用,不过现在我们将关注惯例。
有些时候,或许你可以猜到某些正确的命名,但是,这篇指南在此概述了所有的命名惯例。在下面的例子中'App'是被选来作为命名空间的名字,或者说用来代表Ember应用,当然也可以选择任何你喜欢的名字。后面我们将具体介绍如何创建一个Ember应用,不过现在我们将关注惯例。

## 应用程序(The Application)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,4 @@ Note: Your component must have a matching template named `share-twitter`. Becaus

#### 示例

<a class="jsbin-embed" href="http://emberjs.jsbin.com/OriZITU/3/edit?js,output">JS Bin</a>
<a class="jsbin-embed" href="http://emberjs.jsbin.com/OpocEPu/1/edit?js,output">JS Bin</a>
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ generated within the application, like a list of comments.

## 讨论

<a class="jsbin-embed" href="http://jsbin.com/iLETUTI/10/embed?output">Cookbook: Continuous Redrawing of Views</a><script src="http://static.jsbin.com/js/embed.js"></script>
<a class="jsbin-embed" href="http://jsbin.com/iLETUTI/17/embed?output">Cookbook: Continuous Redrawing of Views</a><script src="http://static.jsbin.com/js/embed.js"></script>

<a class="jsbin-embed" href="http://jsbin.com/iLETUTI/10/embed?output">Cookbook: 持续重绘视图</a><script src="http://static.jsbin.com/js/embed.js"></script>
<a class="jsbin-embed" href="http://jsbin.com/iLETUTI/17/embed?output">Cookbook: 持续重绘视图</a><script src="http://static.jsbin.com/js/embed.js"></script>

### ClockService object

Expand Down Expand Up @@ -115,27 +115,26 @@ App.IntervalController = Ember.ObjectController.extend({
});
```

A controller for a list of comments, which creates a new clock instance
for each comment. Each comment in the list also has a controller. When a
comment is created the `init` method adds a clock instance to the comment.
A controller for a list of comments, each comment will have a new clock
instance when added to the list. The comment item controller sets up
the `seconds` binding, used by the template to show the time since the
comment was created.

一个评论列表的控制器,为每条评论创建一个时钟实例。列表中的每条评论都有一个控制器。当一条评论被创建时,`init`方法添加一个时钟实例到评论
一个评论列表的控制器,每条评论在被添加到列表时,会得到一个新的时钟实例。评论条目控制器设置`seconds`绑定,用于在模板中显示评论创建了多长时间

```javascript
App.CommentItemController = Ember.ObjectController.extend({
init: function() {
this.set('clock', ClockService.create());
}
seconds: Ember.computed.oneWay('clock.pulse').readOnly()
})

App.CommentsController = Ember.ArrayController.extend({
needs: ['interval'],
clockBinding: 'controllers.interval.clock',
itemController: 'commentItem',
actions: {
add: function () {
this.addObject(Em.Object.create({
comment: $('#comment').val()
comment: $('#comment').val(),
clock: ClockService.create()
}));
}
}
Expand Down Expand Up @@ -229,7 +228,7 @@ The source code:

源代码:

* <http://jsbin.com/iLETUTI/8/>
* <http://jsbin.com/iLETUTI/17/edit?html,js,output>

Further reading:

Expand Down
2 changes: 1 addition & 1 deletion source/bilingual_guides/getting-ember/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Ember的发布管理团队针对Ember和Ember Data维护了不同的发布方法

### 频道

The latest [Release](/builds#/release), [Beta](/builds#/beta), and [Canary](/builds#/canary) builds of Ember and Ember data can be found [here](/builds). For each channel a development, minified, and production version is available. For more on the differnt channels read the [Post 1.0 Release Cycle](http://emberjs.com/blog/2013/09/06/new-ember-release-process.html) blog post.
The latest [Release](/builds#/release), [Beta](/builds#/beta), and [Canary](/builds#/canary) builds of Ember and Ember data can be found [here](/builds). For each channel a development, minified, and production version is available. For more on the different channels read the [Post 1.0 Release Cycle](http://emberjs.com/blog/2013/09/06/new-ember-release-process.html) blog post.

最新的Ember和Ember Data的[Release](/builds#/release)[Beta](/builds#/beta)[Canary](/builds#/canary)构建可以在[这里](/builds)找到。每一个频道都提供了一个开发版、最小化版和生产版。更多关于不同频道的信息可以查看博客[1.0后发布周期](http://emberjs.com/blog/2013/09/06/new-ember-release-process.html)

Expand Down
4 changes: 2 additions & 2 deletions source/bilingual_guides/getting-started/accepting-edits.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ In `index.html` replace the static `<input>` element with our custom `{{edit-tod
<!--- ... additional lines truncated for brevity ... -->
<!--- ... 为保持代码简洁,在此省略了其他代码 ... -->
{{#if isEditing}}
{{edit-todo class="edit" value=title focus-out="acceptChanges"
{{edit-todo class="edit" value=title focus-out="acceptChanges"
insert-newline="acceptChanges"}}
{{else}}
<!--- ... additional lines truncated for brevity ... -->
Expand All @@ -63,7 +63,7 @@ Pressing the `<enter>` key will trigger the `acceptChanges` event on the instan

点击`<enter>`键会触发`TodoController`实例的`acceptChanges`事件。焦点离开`<input>`时会出发`focus-out`事件,并调用视图的`TodoController`实例的`acceptChanges`方法。

Additionally, we connect the `value` property of this `<input>` to the `title` property of this instance of `TodoController`. We will not implement a `title` property on the controller so it will retain the default behavior of proxying all requests to its `model`.
Additionally, we connect the `value` property of this `<input>` to the `title` property of this instance of `TodoController`. We will not implement a `title` property on the controller so it will retain the default behavior of proxying all requests to its `model`.

此外,`TodoController`实例的`title`属性与`<input>``value`属性进行了绑定。控制器中并没有定义`title`属性,这样控制就保持默认的行为,将所有请求代理到其`model`之上。

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ Next, update your `index.html` to wrap the inner contents of `<body>` in a Handl

<script src="js/application.js"></script>
<script src="js/router.js"></script>
</body>
<!-- ... additional lines truncated for brevity ... -->
<!-- ... 为确保简洁,略去头尾代码 ... -->
```
Expand Down
28 changes: 13 additions & 15 deletions source/bilingual_guides/getting-started/adding-child-routes.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,25 @@ In `index.html` move the entire `<ul>` of todos into a new template named `todos

```html
<script type="text/x-handlebars" data-template-name="todos/index">
<ul id="todo-list">
{{#each itemController="todo"}}
<li {{bind-attr class="isCompleted:completed isEditing:editing"}}>
{{#if isEditing}}
{{edit-todo class="edit" value=title focus-out="acceptChanges" insert-newline="acceptChanges"}}
{{else}}
{{input type="checkbox" checked=isCompleted class="toggle"}}
<label {{action "editTodo" on="doubleClick"}}>{{title}}</label><button {{action "removeTodo"}} class="destroy"></button>
{{/if}}
</li>
{{/each}}
</ul>
<ul id="todo-list">
{{#each itemController="todo"}}
<li {{bind-attr class="isCompleted:completed isEditing:editing"}}>
{{#if isEditing}}
{{edit-todo class="edit" value=title focus-out="acceptChanges" insert-newline="acceptChanges"}}
{{else}}
{{input type="checkbox" checked=isCompleted class="toggle"}}
<label {{action "editTodo" on="doubleClick"}}>{{title}}</label><button {{action "removeTodo"}} class="destroy"></button>
{{/if}}
</li>
{{/each}}
</ul>
</script>
```

Still within `index.html` place a Handlebars `{{outlet}}` helper where the `<ul>` was previously:

`<ul>`原来所处位置添加一个Handlebars的`{{outlet}}`助手:


```handlebars
<!--- ... additional lines truncated for brevity ... -->
<!--- ... 为保持代码简洁,在此省略了其他代码 ... -->
Expand Down Expand Up @@ -72,8 +71,7 @@ Todos.TodosIndexRoute = Ember.Route.extend({
});
```

When the application loads at the url `'/'` Ember.js will enter the `todos` route and render the `todos` template as before. It will also transition into the `todos.index` route and fill the `{{outlet}}` in the `todos` template with the `todos/index` template. The model data for this template is the result of the `model` method of `TodosIndexRoute`, which indicates that the
model for this route is the same model for the `TodosRoute`.
When the application loads at the url `'/'` Ember.js will enter the `todos` route and render the `todos` template as before. It will also transition into the `todos.index` route and fill the `{{outlet}}` in the `todos` template with the `todos/index` template. The model data for this template is the result of the `model` method of `TodosIndexRoute`, which indicates that the model for this route is the same model for the `TodosRoute`.

当应用从`'/'`加载时,Ember.js将进入`todos`路由并跟之前一样渲染`todos`模板。这也将转换到`todos.index`路由,并使用`todos/index`模板来填充`todos`模板中的`{{outlet}}`。模板使用的模型数据是`TodosIndexRoute``model`方法的返回的值。这表示该路由的模型与`TodoRoute`的模型相同。

Expand Down
4 changes: 3 additions & 1 deletion source/bilingual_guides/getting-started/deleting-todos.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ In `js/controllers/todo_controller.js` implement the `removeTodo` method referen
// ... additional lines truncated for brevity ...
// ... 为保持代码简洁,在此省略了其他代码 ...
actions: {
// ... additional lines truncated for brevity ...
// ... 为保持代码简洁,在此省略了其他代码 ...
removeTodo: function () {
var todo = this.get('model');
todo.deleteRecord();
Expand All @@ -46,7 +48,7 @@ Because the todo is no longer part of the collection of all todos, its `<li>` el

因为删除的待办事项不再是所有待办事项集合的一部分,因此其对应的`<li>`元素将自动的从页面上移除。如果被删除的待办事项是未完成的,那么对应的未完成待办事项的数量将减一,显示该数字的部分也将自动重新渲染。如果数量的变化导致`item``items`间的变形,那么对应的页面部分也将自动重新渲染。

Reload your web browser to ensure that there are no errors and the behaviors described above occurs.
Reload your web browser to ensure that there are no errors and the behaviors described above occurs.

重新载入Web浏览器以确保没有任何错误发生,并且之前描述的行为均工作正常。

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,20 @@ actions: {
completed.invoke('deleteRecord');

this.get('store').commit();
}
},
// ... additional lines truncated for brevity ...
},
hasCompleted: function () {
return this.get('completed') > 0;
}.property('completed'),

completed: function () {
return this.filterBy('isCompleted', true).get('length');
}.property('@each.isCompleted')
}.property('@each.isCompleted'),
// ... additional lines truncated for brevity ...
```

Reload your web browser to ensure that there are no errors and the behavior described above occurs.
Reload your web browser to ensure that there are no errors and the behavior described above occurs.

重载浏览器确保没有任何错误,并且上面描述的功能正常。

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ Implement these properties as part of this template's controller, the `Todos.Tod
在模板的控制器`Todos.TodosController`中实现以上的属性:

```javascript
// Hint: these lines MUST NOT go into the 'actions' object.
// 提示:下面的代码不能放入'actions'
actions: {
// ... additional lines truncated for brevity ...
// ... 为保持代码简洁,在此省略了其他代码 ...
},

// ... additional lines truncated for brevity ...
// ... 为保持代码简洁,在此省略了其他代码 ...
remaining: function () {
Expand Down Expand Up @@ -62,7 +65,7 @@ The `inflection` property will return either a plural or singular version of the
### 附加资源

* [Changes in this step in `diff` format](https://github.com/emberjs/quickstart-code-sample/commit/b418407ed9666714c82d894d6b70f785674f7a45)
* [Computed Properties Guide](/guides/object-model/computed-properties/)
* [Computed Properties Guide](/guides/object-model/computed-properties/)

* [`diff`格式呈现本次修改](https://github.com/emberjs/quickstart-code-sample/commit/b418407ed9666714c82d894d6b70f785674f7a45)
* [计算属性指南](/guides/object-model/computed-properties/)
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ TodoMVC的依赖:

* [jQuery](http://code.jquery.com/jquery-1.10.2.min.js)
* [Handlebars](http://builds.handlebarsjs.com.s3.amazonaws.com/handlebars-1.0.0.js)
* [Ember.js 1.0](http://builds.emberjs.com/tags/v1.0.0/ember.js)
* [Ember Data 1.0 beta](http://builds.emberjs.com/tags/v1.0.0-beta.3/ember-data.js)
* [Ember.js 1.3](http://builds.emberjs.com/tags/v1.3.0/ember.js)
* [Ember Data 1.0 beta](http://builds.emberjs.com/tags/v1.0.0-beta.5/ember-data.js)

For this example, all of these resources should be stored in the folder `js/libs` located in the same location as `index.html`. Update your `index.html` to load these files by placing `<script>` tags just before your closing `</body>` tag in the following order:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ Todos.Router.map(function () {
// ... additional lines truncated for brevity ...

Todos.TodosCompletedRoute = Ember.Route.extend({
model: function(){
model: function() {
return this.store.filter('todo', function (todo) {
return todo.get('isCompleted');
});
},
renderTemplate: function(controller){
renderTemplate: function(controller) {
this.render('todos/index', {controller: controller});
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ Todos.Router.map(function () {
// ... additional lines truncated for brevity ...

Todos.TodosActiveRoute = Ember.Route.extend({
model: function(){
model: function() {
return this.store.filter('todo', function (todo) {
return !todo.get('isCompleted');
});
},
renderTemplate: function(controller){
renderTemplate: function(controller) {
this.render('todos/index', {controller: controller});
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ Todos.ApplicationAdapter = DS.LSAdapter.extend({
});
```

The local storage adapter, written by Ryan Florence, can be downloaded [from its source](https://github.com/rpflorence/ember-localstorage-adapter). Add it to your project as `js/libs/localstorage_adapter.js`. You may place this file anywhere you like (even just putting all code into the same file), but this guide will assume you have created the file and named it as indicated.
The local storage adapter, written by Ryan Florence, can be downloaded [from its source](https://raw.github.com/rpflorence/ember-localstorage-adapter/master/localstorage_adapter.js). Add it to your project as `js/libs/localstorage_adapter.js`. You may place this file anywhere you like (even just putting all code into the same file), but this guide will assume you have created the file and named it as indicated.

`localstorage`适配器由Ryan
Florence编写,可以从[其源](https://github.com/rpflorence/ember-localstorage-adapter)下载。将其添加至项目的`js/libs/localstorage_adapter.js`。当然你也可以将其放置到任何你喜欢的位置(或者将所有代码放置到一个文件中),不过本指南假设你按照指定的路径保存文件和对其命名。
Florence编写,可以从[其源](https://raw.github.com/rpflorence/ember-localstorage-adapter/master/localstorage_adapter.js)下载。将其添加至项目的`js/libs/localstorage_adapter.js`。当然你也可以将其放置到任何你喜欢的位置(或者将所有代码放置到一个文件中),不过本指南假设你按照指定的路径保存文件和对其命名。

In `index.html` include `js/libs/localstorage_adapter.js` as a dependency:

Expand Down
2 changes: 1 addition & 1 deletion source/bilingual_guides/models/handling-metadata.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ By default, Ember Data's JSON deserializer looks for a `meta` key:
"id": 1,
"title": "Progressive Enhancement is Dead",
"comments": ["1", "2"],
"_links": {
"links": {
"user": "/people/tomdale"
},
// ...
Expand Down
16 changes: 12 additions & 4 deletions source/bilingual_guides/models/persisting-records.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,17 @@ var post = store.createRecord('post', {
body: 'Lorem ipsum'
});

post.save().then(function(post) {
this.transitionToRoute('posts/show', post);
});
var self = this;

function transitionToPost(post) {
self.transitionToRoute('posts.show', post);
}

function failure(reason) {
// handle the error
}

post.save().then(transitionToPost).catch(failure);

// => POST to '/posts'
// => transitioning to posts.show route
Expand All @@ -61,7 +69,7 @@ var post = store.createRecord('post', {
});

var onSuccess = function(post) {
this.transitionToRoute('posts/show', post);
this.transitionToRoute('posts.show', post);
};

var onFail = function(post) {
Expand Down
4 changes: 2 additions & 2 deletions source/bilingual_guides/models/the-rest-adapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ have a model with a `hasMany` relationship:

```js
App.Post = DS.Model.extend({
comments: DS.hasMany('App.Comment', { async: true })
comments: DS.hasMany('comment', { async: true })
});
```

Expand Down Expand Up @@ -224,7 +224,7 @@ camelized version of the Ember Data model's name, with the string

```js
App.Comment = DS.Model.extend({
post: DS.belongsTo('App.Post')
post: DS.belongsTo('post')
});
```

Expand Down
Loading

0 comments on commit aa3481a

Please sign in to comment.