Skip to content

Commit

Permalink
Ember app - code style
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Mar 9, 2013
1 parent d73610a commit 27abf86
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 97 deletions.
162 changes: 78 additions & 84 deletions architecture-examples/emberjs/index.html
Original file line number Diff line number Diff line change
@@ -1,87 +1,81 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>ember.js • TodoMVC</title>
<link rel="stylesheet" href="components/todomvc-common/base.css">
</head>
<body>
<script type="text/x-handlebars" data-template-name="todos">
<section id="todoapp">
<header id="header">
<h1>todos</h1>
{{view Ember.TextField id="new-todo" placeholder="What needs to be done?"
valueBinding="newTitle" action="createTodo"}}
</header>

{{#if length}}
<section id="main">
<ul id="todo-list">
{{#each filteredTodos itemController="todo"}}
<li {{bindAttr class="isCompleted:completed isEditing:editing"}}>
{{#if isEditing}}
{{view Todos.EditTodoView todoBinding="this"}}
{{else}}
{{view Ember.Checkbox checkedBinding="isCompleted" class="toggle"}}
<label {{action "editTodo" on="doubleClick"}}>{{title}}</label>
<button {{action "removeTodo"}} class="destroy"></button>
{{/if}}
</li>
{{/each}}
</ul>
{{view Ember.Checkbox id="toggle-all" checkedBinding="allAreDone"}}
</section>

<footer id="footer">
<span id="todo-count">{{{remainingFormatted}}}</span>
<ul id="filters">
<li>
{{#linkTo todos.index activeClass="selected"}}All{{/linkTo}}
</li>
<li>
{{#linkTo todos.active activeClass="selected"}}Active{{/linkTo}}
</li>
<li>
{{#linkTo todos.completed activeClass="selected"}}Completed{{/linkTo}}
</li>
</ul>

{{#if hasCompleted}}
<button id="clear-completed" {{action "clearCompleted"}} {{bindAttr class="buttonClass:hidden"}}>
Clear completed ({{completed}})
</button>
{{/if}}
</footer>
{{/if}}
</section>

<footer id="info">
<p>Double-click to edit a todo</p>
<p>
Created by
<a href="http://github.com/tomdale">Tom Dale</a>,
<a href="http://github.com/addyosmani">Addy Osmani</a>
</p>
<p>Part of <a href="http://todomvc.com">TodoMVC</a></p>
</footer>
</script>

<!-- /* Handlebars templates end */ -->
<script src="components/todomvc-common/base.js"></script>
<script src="components/jquery/jquery.js"></script>
<script src="components/handlebars/handlebars.js"></script>
<script src="components/ember/ember.js"></script>
<!-- TODO: change out with a component when a built one is available on Bower -->
<script src="js/libs/ember-data.js"></script>
<script src="components/ember-localstorage-adapter/localstorage_adapter.js"></script>
<script src="js/app.js"></script>
<script src="js/router.js"></script>
<script src="js/models/todo.js"></script>
<script src="js/models/store.js"></script>
<script src="js/controllers/todos_controller.js"></script>
<script src="js/controllers/todo_controller.js"></script>
<script src="js/views/todo_view.js"></script>
<script src="js/views/edit_todo_view.js"></script>
</body>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>ember.js • TodoMVC</title>
<link rel="stylesheet" href="components/todomvc-common/base.css">
</head>
<body>
<script type="text/x-handlebars" data-template-name="todos">
<section id="todoapp">
<header id="header">
<h1>todos</h1>
{{view Ember.TextField id="new-todo" placeholder="What needs to be done?"
valueBinding="newTitle" action="createTodo"}}
</header>
{{#if length}}
<section id="main">
<ul id="todo-list">
{{#each filteredTodos itemController="todo"}}
<li {{bindAttr class="isCompleted:completed isEditing:editing"}}>
{{#if isEditing}}
{{view Todos.EditTodoView todoBinding="this"}}
{{else}}
{{view Ember.Checkbox checkedBinding="isCompleted" class="toggle"}}
<label {{action "editTodo" on="doubleClick"}}>{{title}}</label>
<button {{action "removeTodo"}} class="destroy"></button>
{{/if}}
</li>
{{/each}}
</ul>
{{view Ember.Checkbox id="toggle-all" checkedBinding="allAreDone"}}
</section>
<footer id="footer">
<span id="todo-count">{{{remainingFormatted}}}</span>
<ul id="filters">
<li>
{{#linkTo todos.index activeClass="selected"}}All{{/linkTo}}
</li>
<li>
{{#linkTo todos.active activeClass="selected"}}Active{{/linkTo}}
</li>
<li>
{{#linkTo todos.completed activeClass="selected"}}Completed{{/linkTo}}
</li>
</ul>
{{#if hasCompleted}}
<button id="clear-completed" {{action "clearCompleted"}} {{bindAttr class="buttonClass:hidden"}}>
Clear completed ({{completed}})
</button>
{{/if}}
</footer>
{{/if}}
</section>
<footer id="info">
<p>Double-click to edit a todo</p>
<p>
Created by
<a href="http://github.com/tomdale">Tom Dale</a>,
<a href="http://github.com/addyosmani">Addy Osmani</a>
</p>
<p>Part of <a href="http://todomvc.com">TodoMVC</a></p>
</footer>
</script>
<script src="components/todomvc-common/base.js"></script>
<script src="components/jquery/jquery.js"></script>
<script src="components/handlebars/handlebars.js"></script>
<script src="components/ember/ember.js"></script>
<!-- TODO: change out with a component when a built one is available on Bower -->
<script src="js/libs/ember-data.js"></script>
<script src="components/ember-localstorage-adapter/localstorage_adapter.js"></script>
<script src="js/app.js"></script>
<script src="js/router.js"></script>
<script src="js/models/todo.js"></script>
<script src="js/models/store.js"></script>
<script src="js/controllers/todos_controller.js"></script>
<script src="js/controllers/todo_controller.js"></script>
<script src="js/views/todo_view.js"></script>
<script src="js/views/edit_todo_view.js"></script>
</body>
</html>
2 changes: 1 addition & 1 deletion architecture-examples/emberjs/js/app.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
/*global Ember*/
/*global Ember */
window.Todos = Ember.Application.create();
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*global Todos Ember*/
/*global Todos Ember */
'use strict';

Todos.TodoController = Ember.ObjectController.extend({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
/*global Todos Ember*/
/*global Todos Ember */
'use strict';

Todos.TodosController = Ember.ArrayController.extend({
createTodo: function () {
// Get the todo title set by the "New Todo" text field
var title = this.get('newTitle');
if (!title.trim()) { return; }
if (!title.trim()) {
return;
}

// Create the new Todo model
Todos.Todo.createRecord({
Expand Down
2 changes: 1 addition & 1 deletion architecture-examples/emberjs/js/models/store.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*global Todos DS*/
/*global Todos DS */
'use strict';

Todos.Store = DS.Store.extend({
Expand Down
2 changes: 1 addition & 1 deletion architecture-examples/emberjs/js/models/todo.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*global Todos DS Ember*/
/*global Todos DS Ember */
'use strict';

Todos.Todo = DS.Model.extend({
Expand Down
10 changes: 7 additions & 3 deletions architecture-examples/emberjs/js/router.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*global Todos Ember*/
/*global Todos Ember */
'use strict';

Todos.Router.map(function () {
Expand All @@ -24,7 +24,9 @@ Todos.TodosIndexRoute = Ember.Route.extend({
Todos.TodosActiveRoute = Ember.Route.extend({
setupController: function () {
var todos = Todos.Todo.filter(function (todo) {
if (!todo.get('isCompleted')) { return true; }
if (!todo.get('isCompleted')) {
return true;
}
});

this.controllerFor('todos').set('filteredTodos', todos);
Expand All @@ -34,7 +36,9 @@ Todos.TodosActiveRoute = Ember.Route.extend({
Todos.TodosCompletedRoute = Ember.Route.extend({
setupController: function () {
var todos = Todos.Todo.filter(function (todo) {
if (todo.get('isCompleted')) { return true; }
if (todo.get('isCompleted')) {
return true;
}
});

this.controllerFor('todos').set('filteredTodos', todos);
Expand Down
2 changes: 1 addition & 1 deletion architecture-examples/emberjs/js/views/edit_todo_view.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*global Todos Ember*/
/*global Todos Ember */
'use strict';

Todos.EditTodoView = Ember.TextField.extend({
Expand Down
8 changes: 5 additions & 3 deletions architecture-examples/emberjs/js/views/todo_view.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
/*global Todos Ember*/
/*global Todos Ember */
'use strict';

Todos.TodoView = Ember.View.extend({
tagName: 'li',
classNameBindings: ['todo.isCompleted:completed', 'isEditing:editing'],

classNameBindings: [
'todo.isCompleted:completed',
'isEditing:editing'
],
doubleClick: function () {
this.set('isEditing', true);
}
Expand Down

0 comments on commit 27abf86

Please sign in to comment.