Skip to content

Commit

Permalink
upgrade to latest chaplin + brunch, add bower
Browse files Browse the repository at this point in the history
  • Loading branch information
akre54 committed Aug 7, 2013
1 parent d71c150 commit 8605d55
Show file tree
Hide file tree
Showing 23 changed files with 122 additions and 14,536 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
public/
node_modules/
tmp/
bower_components/
55 changes: 9 additions & 46 deletions app/application.coffee
Original file line number Diff line number Diff line change
@@ -1,66 +1,29 @@
Chaplin = require 'chaplin'
{Application} = require 'chaplin'
mediator = require 'mediator'
routes = require 'routes'
Layout = require 'views/layout'
Farm = require 'models/farm'
SessionController = require 'controllers/session_controller'
HeaderController = require 'controllers/header_controller'
CustomersCollection = require 'models/customers_collection'

# The application object
module.exports = class Application extends Chaplin.Application
module.exports = class Application extends Application
# Set your application name here so the document title is set to
# “Controller title – Site title” (see Layout#adjustTitle)
title: 'Farm Tab'

initialize: ->
super

# Initialize core components
@initDispatcher()
@initLayout()
@initMediator()

# Application-specific scaffold
@initControllers()

# Register all routes and start routing
@initRouter routes
# 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 SessionController()
new HeaderController()
initLayout: (options = {}) ->
options.title ?= @title
@layout = new Layout options

# Create additional mediator properties
# -------------------------------------
initMediator: ->
# Create a user property
Chaplin.mediator.user = new Farm()
Chaplin.mediator.user.customers = new CustomersCollection()
mediator.user = new Farm()
mediator.user.customers = new CustomersCollection()
# Set up any semi-globals
Chaplin.mediator.accessToken = 'somerandomcraptobesetlater'
mediator.accessToken = 'somerandomcraptobesetlater'
# Seal the mediator
Chaplin.mediator.seal()
super
16 changes: 0 additions & 16 deletions app/controllers/auth_controller.coffee

This file was deleted.

10 changes: 10 additions & 0 deletions app/controllers/base/auth_controller.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Controller = require 'controllers/base/controller'
mediator = require 'mediator'

module.exports = class AuthenticatedController extends Controller
beforeAction: ->
super
if mediator.user
return true
else
@redirectToRoute('login')
4 changes: 4 additions & 0 deletions app/controllers/base/controller.coffee
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Chaplin = require 'chaplin'
SiteView = require 'views/site_view'

module.exports = class Controller extends Chaplin.Controller

beforeAction: (params, route) ->
@compse 'site', SiteView
15 changes: 8 additions & 7 deletions app/controllers/customers_controller.coffee
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
mediator = require 'mediator'
Controller = require 'controllers/base/controller'
AuthController = require 'controllers/base/auth_controller'
Customer = require 'models/customer'
CustomerPageView = require 'views/customer_page_view'
CustomersCollection = require 'models/customers_collection'
CustomersCollectionView = require 'views/customers_collection_view'
CreateCustomerView = require 'views/create_customer_view'

module.exports = class CustomersController extends Controller
module.exports = class CustomersController extends AuthController
historyURL: 'customers'

index: ->
mediator.user.customers or= new CustomersCollection()
beforeAction: (params) ->
@customers = mediator.user.customers

@collection = mediator.user.customers
index: ->
@view = new CustomersCollectionView {@collection, container: '#page-container'}
@collection.fetch() if @collection.isEmpty()

show: (params) ->
@model = new Customer id: params.id
debugger
@model = @customers.get(params.id) || new Customer id: params.id
@view = new CustomerPageView {@model}
@model.fetch()

Expand All @@ -28,4 +29,4 @@ module.exports = class CustomersController extends Controller
@view.subscribeEvent 'customer:created', (response, customer) ->
alert 'customer created!'
mediator.user.customers.add customer
mediator.publish '!startupController', 'farms'
mediator.publish '!router:routeByName', 'farms'
14 changes: 7 additions & 7 deletions app/controllers/farms_controller.coffee
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
Controller = require 'controllers/base/controller'
AuthController = require 'controllers/base/auth_controller'
mediator = require 'mediator'
FarmView = require 'views/farm_view'
Farm = require 'models/farm'

module.exports = class FarmsController extends Controller
module.exports = class FarmsController extends AuthController
title: 'My Farm'
historyURL: ''

index: (params = {}) ->
@model = mediator.user
@user = mediator.user

if @model.isNew()
@model.fetch
if @user.isNew()
@user.fetch
success: =>
@view or= new FarmView {@model}
@view or= new FarmView {@user}
else
@view or= new FarmView {@model}
@view or= new FarmView {@user}
2 changes: 1 addition & 1 deletion app/controllers/session_controller.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = class SessionController extends Controller
# This just hardcoded here to avoid async loading of service providers.
# In the end you might want to do this.
@serviceProviders = {
#farmTab: new FarmTab()
farmTab: new FarmTab()
}

# Was the login status already determined?
Expand Down
4 changes: 2 additions & 2 deletions app/initialize.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
$ = require 'jquery'
Application = require 'application'
routes = require 'routes'

$ ->
app = new Application()
app.initialize()
new Application { title: 'Farm Tab', routes }
4 changes: 2 additions & 2 deletions app/lib/view_helper.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mediator = require 'mediator'
utils = require 'chaplin/lib/utils'
{utils} = require 'chaplin'

# Application-specific view helpers
# ---------------------------------
Expand Down Expand Up @@ -45,4 +45,4 @@ Handlebars.registerHelper 'url', (routeName, params..., options) ->
url = null
mediator.publish '!router:reverse', routeName, params, (result) ->
url = result
"/#{url}"
url
18 changes: 7 additions & 11 deletions app/models/base/model.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,17 @@ module.exports = class Model extends Chaplin.Model
base + data
sep = if full.indexOf('?') >= 0 then '&' else '?'
params = @urlParams()
payload = _.keys(params)
.map (key) -> [key, params[key]]
.filter (pair) -> pair[1] != null
.map (pair) -> pair.join('=')
payload = _(params).keys()
.map (key) ->
[key, params[key]]
.filter (pair) ->
pair[1]?
.map (pair) ->
pair.join('=')
.join('&')
url = if payload
full + sep + payload
else
full
url

fetch: (options) ->
@trigger 'loadStart'
options ?= {}
options.success = _.wrap (options.success ? ->), (func, args...) =>
func args...
@trigger 'load'
super
2 changes: 1 addition & 1 deletion app/routes.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = (match) ->
match '', 'farms', name: 'home'
match '', 'farms#index', name: 'home'
match 'customers', 'customers#index', name: 'customers'
match 'customers/new', 'customers#create', name: 'new_customer'
match 'customers/:id', 'customers#show', name: 'customer', constraints: { id: /^\d+$/ }
4 changes: 4 additions & 0 deletions app/views/site_view.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
View = require 'views/base/view'
template = require 'views/templates/site'

class SiteView extends View
Empty file added app/views/templates/site.hbs
Empty file.
34 changes: 34 additions & 0 deletions bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"author": "Adam Krebs",
"name": "farmtab-mobile",
"description": "A mobile payments CSA for market farmers",
"version": "0.0.1",
"homepage": "http://farmtab.com",
"repository": {
"type": "git",
"url": "https://github.com/akre54/FT"
},
"ignore": [
"**/.*",
"node_modules",
"components"
],
"dependencies": {
"chaplin": "~0.10.0",
"console-polyfill": "~0.1.0",
"lodash": "~1.3.1",
"moment": "~2.0.0",
"jquery": "~2.0.2",
"bootstrap": "~2.3.2"
},
"overrides": {
"backbone": {
"dependencies": {
"lodash": "*",
"jquery": "*"
},
"main": "backbone.js"
},
"moment": {"main": "moment.js"}
}
}
45 changes: 17 additions & 28 deletions config.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,7 @@ exports.config =
javascripts:
joinTo:
'javascripts/app.js': /^app/
'javascripts/vendor.js': /^vendor/
'test/javascripts/test.js': /^test(\/|\\)(?!vendor)/
'test/javascripts/test-vendor.js': /^test(\/|\\)(?=vendor)/
order:
# Files in `vendor` directories are compiled before other files
# even if they aren't specified in order.before.
before: [
'vendor/scripts/console-helper.js',
'vendor/scripts/jquery-1.9.0.js',
'vendor/scripts/underscore-1.4.3.js',
'vendor/scripts/backbone-0.9.10.js',
'vendor/scripts/exports.js'
]
'javascripts/vendor.js': /^(bower_components|vendor)/

stylesheets:
joinTo:
Expand All @@ -26,18 +14,19 @@ exports.config =
templates:
joinTo: 'javascripts/app.js'

coffeelint:
options:
arrow_spacing:
level: 'warn'
indentation:
level: 'ignore'
line_endings:
level: 'warn'
max_line_length:
value: 100
level: 'warn'
no_empty_param_list:
level: 'warn'
no_stand_alone_at:
level: 'error'
plugins:
coffeelint:
options:
arrow_spacing:
level: 'warn'
max_line_length:
value: 100
level: 'warn'
indentation:
level: 'ignore'
line_endings:
level: 'warn'
no_empty_param_list:
level: 'warn'
no_stand_alone_at:
level: 'error'
15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,20 @@
"test": "brunch test"
},
"dependencies": {
"javascript-brunch": ">= 1.0 < 1.6",
"coffee-script-brunch": ">= 1.0 < 1.6",
"javascript-brunch": ">= 1.0 < 1.8",
"coffee-script-brunch": ">= 1.0 < 1.8",

"less-brunch": ">= 1.0 < 1.6",
"less-brunch": ">= 1.0 < 1.8",

"handlebars-brunch": ">= 1.0 < 1.6",
"handlebars-brunch": ">= 1.0 < 1.8",

"uglify-js-brunch": ">= 1.0 < 1.6",
"clean-css-brunch": ">= 1.0 < 1.6"
"uglify-js-brunch": ">= 1.0 < 1.8",
"clean-css-brunch": ">= 1.0 < 1.8"
},
"devDependencies": {
"coffeelint-brunch": ">= 1.0 < 1.6",
"coffeelint-brunch": ">= 1.0 < 1.8",
"chai": "1.2.0",
"mbradshawabs/ajaxreplay": "~1.1.0",
"sinon": "1.4.2",
"sinon-chai": "2.1.2"
}
Expand Down
Loading

0 comments on commit 8605d55

Please sign in to comment.