Commit 8955b944 authored by Sindre Sorhus's avatar Sindre Sorhus

Merge pull request #429 from gstof/batman-indentation

Batman: fix mixed indentation that cause coffee to generate incorrect js
parents 4dbafb90 ac6d76c8
...@@ -4,7 +4,7 @@ class Alfred extends Batman.App ...@@ -4,7 +4,7 @@ class Alfred extends Batman.App
@route '/active', 'todos#active' @route '/active', 'todos#active'
class Alfred.TodosController extends Batman.Controller class Alfred.TodosController extends Batman.Controller
constructor: -> constructor: ->
super super
@set('newTodo', new Alfred.Todo(completed: false)) @set('newTodo', new Alfred.Todo(completed: false))
...@@ -14,74 +14,74 @@ class Alfred.TodosController extends Batman.Controller ...@@ -14,74 +14,74 @@ class Alfred.TodosController extends Batman.Controller
@accessor 'currentTodos', -> Alfred.Todo.get(@get('currentTodoSet')) @accessor 'currentTodos', -> Alfred.Todo.get(@get('currentTodoSet'))
all: -> all: ->
@set('currentTodoSet', 'all') @set('currentTodoSet', 'all')
completed: -> completed: ->
@set 'currentTodoSet', 'completed' @set 'currentTodoSet', 'completed'
@render(source: 'todos/all') @render(source: 'todos/all')
active: -> active: ->
@set 'currentTodoSet', 'active' @set 'currentTodoSet', 'active'
@render(source: 'todos/all') @render(source: 'todos/all')
createTodo: -> createTodo: ->
@get('newTodo').save (err, todo) => @get('newTodo').save (err, todo) =>
if err if err
throw err unless err instanceof Batman.ErrorsSet throw err unless err instanceof Batman.ErrorsSet
else else
@set 'newTodo', new Alfred.Todo(completed: false, title: "") @set 'newTodo', new Alfred.Todo(completed: false, title: "")
todoDoneChanged: (node, event, context) -> todoDoneChanged: (node, event, context) ->
todo = context.get('todo') todo = context.get('todo')
todo.save (err) -> todo.save (err) ->
throw err if err && !err instanceof Batman.ErrorsSet throw err if err && !err instanceof Batman.ErrorsSet
destroyTodo: (node, event, context) -> destroyTodo: (node, event, context) ->
todo = context.get('todo') todo = context.get('todo')
todo.destroy (err) -> throw err if err todo.destroy (err) -> throw err if err
toggleAll: (node, context) -> toggleAll: (node, context) ->
Alfred.Todo.get('all').forEach (todo) -> Alfred.Todo.get('all').forEach (todo) ->
todo.set('completed', !!node.checked) todo.set('completed', !!node.checked)
todo.save (err) -> todo.save (err) ->
throw err if err && !err instanceof Batman.ErrorsSet throw err if err && !err instanceof Batman.ErrorsSet
clearCompleted: -> clearCompleted: ->
Alfred.Todo.get('completed').forEach (todo) -> Alfred.Todo.get('completed').forEach (todo) ->
todo.destroy (err) -> throw err if err todo.destroy (err) -> throw err if err
toggleEditing: (node, event, context) -> toggleEditing: (node, event, context) ->
todo = context.get('todo') todo = context.get('todo')
editing = todo.set('editing', !todo.get('editing')) editing = todo.set('editing', !todo.get('editing'))
if editing if editing
input = document.getElementById("todo-input-#{todo.get('id')}") input = document.getElementById("todo-input-#{todo.get('id')}")
input.focus() input.focus()
else else
if todo.get('title')?.length > 0 if todo.get('title')?.length > 0
todo.save (err, todo) -> todo.save (err, todo) ->
throw err if err && !err instanceof Batman.ErrorsSet throw err if err && !err instanceof Batman.ErrorsSet
else else
todo.destroy (err, todo) -> todo.destroy (err, todo) ->
throw err if err throw err if err
disableEditingUponSubmit: (node, event, context) -> disableEditingUponSubmit: (node, event, context) ->
if Batman.DOM.events.isEnter(event) if Batman.DOM.events.isEnter(event)
@toggleEditing(node, event, context) @toggleEditing(node, event, context)
class Alfred.Todo extends Batman.Model class Alfred.Todo extends Batman.Model
@encode 'title', 'completed' @encode 'title', 'completed'
@persist Batman.LocalStorage @persist Batman.LocalStorage
@validate 'title', presence: true @validate 'title', presence: true
@storageKey: 'todos-batman' @storageKey: 'todos-batman'
@classAccessor 'active', -> @classAccessor 'active', ->
@get('all').filter (todo) -> !todo.get('completed') @get('all').filter (todo) -> !todo.get('completed')
@classAccessor 'completed', -> @classAccessor 'completed', ->
@get('all').filter (todo) -> todo.get('completed') @get('all').filter (todo) -> todo.get('completed')
@wrapAccessor 'title', (core) -> @wrapAccessor 'title', (core) ->
set: (key, value) -> core.set.call(@, key, value?.trim()) set: (key, value) -> core.set.call(@, key, value?.trim())
window.Alfred = Alfred window.Alfred = Alfred
Alfred.run() Alfred.run()
// Generated by CoffeeScript 1.3.3 var Alfred,
(function() { __hasProp = {}.hasOwnProperty,
var Alfred, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
Alfred = (function(_super) { Alfred = (function(_super) {
__extends(Alfred, _super); __extends(Alfred, _super);
function Alfred() { function Alfred() {
return Alfred.__super__.constructor.apply(this, arguments); return Alfred.__super__.constructor.apply(this, arguments);
} }
Alfred.root('todos#all');
Alfred.route('/completed', 'todos#completed'); Alfred.root('todos#all');
Alfred.route('/active', 'todos#active'); Alfred.route('/completed', 'todos#completed');
return Alfred; Alfred.route('/active', 'todos#active');
})(Batman.App); return Alfred;
Alfred.TodosController = (function(_super) { })(Batman.App);
__extends(TodosController, _super); Alfred.TodosController = (function(_super) {
function TodosController() { __extends(TodosController, _super);
TodosController.__super__.constructor.apply(this, arguments);
this.set('newTodo', new Alfred.Todo({
completed: false
}));
}
TodosController.prototype.routingKey = 'todos'; function TodosController() {
TodosController.__super__.constructor.apply(this, arguments);
this.set('newTodo', new Alfred.Todo({
completed: false
}));
}
TodosController.prototype.currentTodoSet = 'all'; TodosController.prototype.routingKey = 'todos';
TodosController.accessor('currentTodos', function() { TodosController.prototype.currentTodoSet = 'all';
return Alfred.Todo.get(this.get('currentTodoSet'));
});
TodosController.prototype.all = function() {}; TodosController.accessor('currentTodos', function() {
return Alfred.Todo.get(this.get('currentTodoSet'));
});
TodosController.set('currentTodoSet', 'all'); TodosController.prototype.all = function() {
return this.set('currentTodoSet', 'all');
};
TodosController.prototype.completed = function() { TodosController.prototype.completed = function() {
this.set('currentTodoSet', 'completed'); this.set('currentTodoSet', 'completed');
return this.render({ return this.render({
source: 'todos/all' source: 'todos/all'
}); });
}; };
TodosController.prototype.active = function() { TodosController.prototype.active = function() {
this.set('currentTodoSet', 'active'); this.set('currentTodoSet', 'active');
return this.render({ return this.render({
source: 'todos/all' source: 'todos/all'
}); });
}; };
TodosController.prototype.createTodo = function() { TodosController.prototype.createTodo = function() {
var _this = this; var _this = this;
return this.get('newTodo').save(function(err, todo) { return this.get('newTodo').save(function(err, todo) {
if (err) { if (err) {
if (!(err instanceof Batman.ErrorsSet)) { if (!(err instanceof Batman.ErrorsSet)) {
throw err; throw err;
}
} else {
return _this.set('newTodo', new Alfred.Todo({
completed: false,
title: ""
}));
} }
}); } else {
}; return _this.set('newTodo', new Alfred.Todo({
completed: false,
title: ""
}));
}
});
};
TodosController.prototype.todoDoneChanged = function(node, event, context) {
var todo;
todo = context.get('todo');
return todo.save(function(err) {
if (err && !err instanceof Batman.ErrorsSet) {
throw err;
}
});
};
TodosController.prototype.destroyTodo = function(node, event, context) {
var todo;
todo = context.get('todo');
return todo.destroy(function(err) {
if (err) {
throw err;
}
});
};
TodosController.prototype.todoDoneChanged = function(node, event, context) { TodosController.prototype.toggleAll = function(node, context) {
var todo; return Alfred.Todo.get('all').forEach(function(todo) {
todo = context.get('todo'); todo.set('completed', !!node.checked);
return todo.save(function(err) { return todo.save(function(err) {
if (err && !err instanceof Batman.ErrorsSet) { if (err && !err instanceof Batman.ErrorsSet) {
throw err; throw err;
} }
}); });
}; });
};
TodosController.prototype.destroyTodo = function(node, event, context) { TodosController.prototype.clearCompleted = function() {
var todo; return Alfred.Todo.get('completed').forEach(function(todo) {
todo = context.get('todo');
return todo.destroy(function(err) { return todo.destroy(function(err) {
if (err) { if (err) {
throw err; throw err;
} }
}); });
}; });
};
TodosController.prototype.toggleAll = function(node, context) {
return Alfred.Todo.get('all').forEach(function(todo) { TodosController.prototype.toggleEditing = function(node, event, context) {
todo.set('completed', !!node.checked); var editing, input, todo, _ref;
return todo.save(function(err) { todo = context.get('todo');
editing = todo.set('editing', !todo.get('editing'));
if (editing) {
input = document.getElementById("todo-input-" + (todo.get('id')));
return input.focus();
} else {
if (((_ref = todo.get('title')) != null ? _ref.length : void 0) > 0) {
return todo.save(function(err, todo) {
if (err && !err instanceof Batman.ErrorsSet) { if (err && !err instanceof Batman.ErrorsSet) {
throw err; throw err;
} }
}); });
}); } else {
}; return todo.destroy(function(err, todo) {
TodosController.prototype.clearCompleted = function() {
return Alfred.Todo.get('completed').forEach(function(todo) {
return todo.destroy(function(err) {
if (err) { if (err) {
throw err; throw err;
} }
}); });
});
};
TodosController.prototype.toggleEditing = function(node, event, context) {
var editing, input, todo, _ref;
todo = context.get('todo');
editing = todo.set('editing', !todo.get('editing'));
if (editing) {
input = document.getElementById("todo-input-" + (todo.get('id')));
return input.focus();
} else {
if (((_ref = todo.get('title')) != null ? _ref.length : void 0) > 0) {
return todo.save(function(err, todo) {
if (err && !err instanceof Batman.ErrorsSet) {
throw err;
}
});
} else {
return todo.destroy(function(err, todo) {
if (err) {
throw err;
}
});
}
} }
}; }
};
TodosController.prototype.disableEditingUponSubmit = function(node, event, context) {
if (Batman.DOM.events.isEnter(event)) {
return this.toggleEditing(node, event, context);
}
};
return TodosController; TodosController.prototype.disableEditingUponSubmit = function(node, event, context) {
if (Batman.DOM.events.isEnter(event)) {
return this.toggleEditing(node, event, context);
}
};
})(Batman.Controller); return TodosController;
Alfred.Todo = (function(_super) { })(Batman.Controller);
__extends(Todo, _super); Alfred.Todo = (function(_super) {
function Todo() { __extends(Todo, _super);
return Todo.__super__.constructor.apply(this, arguments);
}
Todo.encode('title', 'completed'); function Todo() {
return Todo.__super__.constructor.apply(this, arguments);
}
Todo.persist(Batman.LocalStorage); Todo.encode('title', 'completed');
Todo.validate('title', { Todo.persist(Batman.LocalStorage);
presence: true
});
Todo.storageKey = 'todos-batman'; Todo.validate('title', {
presence: true
});
Todo.classAccessor('active', function() { Todo.storageKey = 'todos-batman';
return this.get('all').filter(function(todo) {
return !todo.get('completed');
});
});
Todo.classAccessor('completed', function() { Todo.classAccessor('active', function() {
return this.get('all').filter(function(todo) { return this.get('all').filter(function(todo) {
return todo.get('completed'); return !todo.get('completed');
});
}); });
});
Todo.wrapAccessor('title', function(core) { Todo.classAccessor('completed', function() {
return { return this.get('all').filter(function(todo) {
set: function(key, value) { return todo.get('completed');
return core.set.call(this, key, value != null ? value.trim() : void 0);
}
};
}); });
});
return Todo; Todo.wrapAccessor('title', function(core) {
return {
set: function(key, value) {
return core.set.call(this, key, value != null ? value.trim() : void 0);
}
};
});
})(Batman.Model); return Todo;
window.Alfred = Alfred; })(Batman.Model);
Alfred.run(); window.Alfred = Alfred;
}).call(this); Alfred.run();
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment