forked from tastejs/todomvc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request tastejs#639 from paulmillr/topics/update-brunch-ch…
…aplin Update Brunch with Chaplin.
- Loading branch information
Showing
40 changed files
with
15,569 additions
and
8,918 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
bower_components/ | ||
!bower_components/todomvc-common/ | ||
|
||
# NPM packages folder. | ||
node_modules/ | ||
|
||
|
52 changes: 3 additions & 49 deletions
52
labs/dependency-examples/chaplin-brunch/app/application.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,21 @@ | ||
Chaplin = require 'chaplin' | ||
mediator = require 'mediator' | ||
routes = require 'routes' | ||
HeaderController = require 'controllers/header-controller' | ||
FooterController = require 'controllers/footer-controller' | ||
TodosController = require 'controllers/todos-controller' | ||
Todos = require 'models/todos' | ||
Layout = require 'views/layout' | ||
|
||
# The application object | ||
module.exports = class Application extends Chaplin.Application | ||
# Set your application name here so the document title is set to | ||
# “Controller title – Site title” (see Layout#adjustTitle) | ||
title: 'Chaplin • TodoMVC' | ||
|
||
initialize: -> | ||
super | ||
|
||
# Initialize core components | ||
@initDispatcher controllerSuffix: '-controller' | ||
@initLayout() | ||
@initMediator() | ||
|
||
# Application-specific scaffold | ||
@initControllers() | ||
|
||
# Register all routes and start routing | ||
@initRouter routes, pushState: no | ||
# You might pass Router/History options as the second parameter. | ||
# Chaplin enables pushState per default and Backbone uses / as | ||
# the root per default. You might change that in the options | ||
# if necessary: | ||
# @initRouter routes, pushState: false, root: '/subdir/' | ||
|
||
# Freeze the application instance to prevent further changes | ||
Object.freeze? this | ||
|
||
# Override standard layout initializer | ||
# ------------------------------------ | ||
initLayout: -> | ||
# Use an application-specific Layout class. Currently this adds | ||
# no features to the standard Chaplin Layout, it’s an empty placeholder. | ||
@layout = new Layout {@title} | ||
|
||
# Instantiate common controllers | ||
# ------------------------------ | ||
initControllers: -> | ||
# These controllers are active during the whole application runtime. | ||
# You don’t need to instantiate all controllers here, only special | ||
# controllers which do not to respond to routes. They may govern models | ||
# and views which are needed the whole time, for example header, footer | ||
# or navigation views. | ||
# e.g. new NavigationController() | ||
new HeaderController() | ||
new FooterController() | ||
new TodosController() | ||
|
||
# Create additional mediator properties | ||
# ------------------------------------- | ||
initMediator: -> | ||
# Create a user property | ||
mediator.user = null | ||
# Add additional application-specific properties and methods | ||
mediator.todos = new Todos() | ||
# If todos are fetched from server, we will need to wait | ||
# for them. | ||
mediator.todos.fetch() | ||
# Seal the mediator | ||
mediator.seal() | ||
super |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 0 additions & 3 deletions
3
labs/dependency-examples/chaplin-brunch/app/controllers/base/controller.coffee
This file was deleted.
Oops, something went wrong.
8 changes: 0 additions & 8 deletions
8
labs/dependency-examples/chaplin-brunch/app/controllers/footer-controller.coffee
This file was deleted.
Oops, something went wrong.
8 changes: 0 additions & 8 deletions
8
labs/dependency-examples/chaplin-brunch/app/controllers/header-controller.coffee
This file was deleted.
Oops, something went wrong.
28 changes: 23 additions & 5 deletions
28
labs/dependency-examples/chaplin-brunch/app/controllers/index-controller.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,25 @@ | ||
Controller = require 'controllers/base/controller' | ||
HeaderView = require 'views/header-view' | ||
FooterView = require 'views/footer-view' | ||
TodosView = require 'views/todos-view' | ||
mediator = require 'mediator' | ||
|
||
module.exports = class IndexController extends Controller | ||
title: 'Todo list' | ||
module.exports = class IndexController extends Chaplin.Controller | ||
# The method is executed before any controller actions. | ||
# We compose structure in order for it to be rendered only once. | ||
beforeAction: -> | ||
@compose 'structure', -> | ||
params = collection: mediator.todos | ||
@header = new HeaderView params | ||
@footer = new FooterView params | ||
|
||
list: (options) -> | ||
@publishEvent 'todos:filter', options.filterer?.trim() ? 'all' | ||
# On each new load, old @view will be disposed and | ||
# new @view will be created. This is idiomatic Chaplin memory management: | ||
# one controller per screen. | ||
list: (params) -> | ||
filterer = params.filterer?.trim() ? 'all' | ||
@publishEvent 'todos:filter', filterer | ||
@view = new TodosView collection: mediator.todos, filterer: (model) -> | ||
switch filterer | ||
when 'completed' then model.get('completed') | ||
when 'active' then not model.get('completed') | ||
else true |
8 changes: 0 additions & 8 deletions
8
labs/dependency-examples/chaplin-brunch/app/controllers/todos-controller.coffee
This file was deleted.
Oops, something went wrong.
5 changes: 3 additions & 2 deletions
5
labs/dependency-examples/chaplin-brunch/app/initialize.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
Application = require 'application' | ||
routes = require 'routes' | ||
|
||
# Initialize the application on DOM ready event. | ||
$ -> | ||
app = new Application() | ||
app.initialize() | ||
new Application | ||
controllerSuffix: '-controller', pushState: false, routes: routes |
13 changes: 0 additions & 13 deletions
13
labs/dependency-examples/chaplin-brunch/app/lib/support.coffee
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
labs/dependency-examples/chaplin-brunch/app/lib/utils.coffee
This file was deleted.
Oops, something went wrong.
39 changes: 0 additions & 39 deletions
39
labs/dependency-examples/chaplin-brunch/app/lib/view-helper.coffee
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
module.exports = require('chaplin').mediator | ||
module.exports = Chaplin.mediator |
9 changes: 0 additions & 9 deletions
9
labs/dependency-examples/chaplin-brunch/app/models/base/collection.coffee
This file was deleted.
Oops, something went wrong.
5 changes: 0 additions & 5 deletions
5
labs/dependency-examples/chaplin-brunch/app/models/base/model.coffee
This file was deleted.
Oops, something went wrong.
8 changes: 5 additions & 3 deletions
8
labs/dependency-examples/chaplin-brunch/app/models/todo.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
labs/dependency-examples/chaplin-brunch/app/models/todos.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
labs/dependency-examples/chaplin-brunch/app/views/base/collection-view.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
Chaplin = require 'chaplin' | ||
View = require 'views/base/view' | ||
|
||
module.exports = class CollectionView extends Chaplin.CollectionView | ||
# This class doesn’t inherit from the application-specific View class, | ||
# so we need to borrow the method from the View prototype: | ||
getTemplateFunction: View::getTemplateFunction | ||
useCssAnimation: true |
3 changes: 0 additions & 3 deletions
3
labs/dependency-examples/chaplin-brunch/app/views/base/view.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 11 additions & 12 deletions
23
labs/dependency-examples/chaplin-brunch/app/views/footer-view.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 11 additions & 13 deletions
24
labs/dependency-examples/chaplin-brunch/app/views/header-view.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,16 @@ | ||
View = require 'views/base/view' | ||
template = require 'views/templates/header' | ||
View = require './base/view' | ||
template = require './templates/header' | ||
|
||
module.exports = class HeaderView extends View | ||
autoRender: yes | ||
autoRender: true | ||
el: '#header' | ||
events: | ||
'keypress #new-todo': 'createOnEnter' | ||
template: template | ||
|
||
initialize: -> | ||
super | ||
@delegate 'keypress', '#new-todo', @createOnEnter | ||
|
||
createOnEnter: (event) => | ||
ENTER_KEY = 13 | ||
title = $(event.currentTarget).val().trim() | ||
return if event.keyCode isnt ENTER_KEY or not title | ||
@collection.create {title} | ||
@$('#new-todo').val '' | ||
createOnEnter: (event) => | ||
ENTER_KEY = 13 | ||
title = $(event.currentTarget).val().trim() | ||
return if event.keyCode isnt ENTER_KEY or not title | ||
@collection.create {title} | ||
@$('#new-todo').val '' |
10 changes: 0 additions & 10 deletions
10
labs/dependency-examples/chaplin-brunch/app/views/layout.coffee
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.