Permalink
Browse files

first commit

  • Loading branch information...
0 parents commit 96364a670404e17b762499051a7690bd0f8c71c0 @rashfael committed Oct 27, 2012
Showing with 27,797 additions and 0 deletions.
  1. +29 −0 .gitignore
  2. +21 −0 Cakefile
  3. +73 −0 README.md
  4. +64 −0 app/application.coffee
  5. 0 app/assets/img/.gitkeep
  6. BIN app/assets/img/glyphicons-halflings-white.png
  7. BIN app/assets/img/glyphicons-halflings.png
  8. +24 −0 app/assets/index.html
  9. +3 −0 app/controllers/base/controller.coffee
  10. +8 −0 app/controllers/deeds_controller.coffee
  11. +8 −0 app/controllers/footer_controller.coffee
  12. +10 −0 app/controllers/header_controller.coffee
  13. +8 −0 app/controllers/home_controller.coffee
  14. +46 −0 app/controllers/session_controller.coffee
  15. +5 −0 app/initialize.coffee
  16. +88 −0 app/lib/services/service_provider.coffee
  17. +13 −0 app/lib/support.coffee
  18. +127 −0 app/lib/utils.coffee
  19. +1 −0 app/mediator.coffee
  20. +3 −0 app/models/base/collection.coffee
  21. +3 −0 app/models/base/model.coffee
  22. +8 −0 app/models/header.coffee
  23. +3 −0 app/models/user.coffee
  24. +3 −0 app/routes.coffee
  25. +7 −0 app/views/base/collection_view.coffee
  26. +25 −0 app/views/base/page_view.coffee
  27. +6 −0 app/views/base/view.coffee
  28. +5 −0 app/views/deeds_views.coffee
  29. +14 −0 app/views/footer_view.coffee
  30. +15 −0 app/views/header_view.coffee
  31. +6 −0 app/views/home_page_view.coffee
  32. +6 −0 app/views/layout.coffee
  33. +11 −0 app/views/login_view.coffee
  34. +11 −0 app/views/styles/application.styl
  35. +2 −0 app/views/styles/header.styl
  36. +1 −0 app/views/styles/login.styl
  37. +2 −0 app/views/templates/deeds.jade
  38. +3 −0 app/views/templates/footer.jade
  39. +16 −0 app/views/templates/header.jade
  40. +3 −0 app/views/templates/home.jade
  41. +1 −0 app/views/templates/login.jade
  42. +8 −0 app/views/templates/mixins/form_helpers.jade
  43. +32 −0 config.coffee
  44. +5 −0 generators/collection/collection.coffee.hbs
  45. +11 −0 generators/collection/generator.json
  46. +12 −0 generators/collection_test/collection_test.coffee.hbs
  47. +9 −0 generators/collection_test/generator.json
  48. +5 −0 generators/collection_view/collection_view.coffee.hbs
  49. +9 −0 generators/collection_view/generator.json
  50. +3 −0 generators/controller/controller.coffee.hbs
  51. +11 −0 generators/controller/generator.json
  52. +5 −0 generators/controller_test/controller_test.coffee.hbs
  53. +9 −0 generators/controller_test/generator.json
  54. 0 generators/generator/generated_file.coffee.hbs
  55. +13 −0 generators/generator/generator.json
  56. +9 −0 generators/generator/generator.json.hbs
  57. +11 −0 generators/model/generator.json
  58. +3 −0 generators/model/model.coffee.hbs
  59. +9 −0 generators/model_test/generator.json
  60. +5 −0 generators/model_test/model_test.coffee.hbs
  61. +9 −0 generators/page_view/generator.json
  62. +5 −0 generators/page_view/page_view.coffee.hbs
  63. +9 −0 generators/style/generator.json
  64. +1 −0 generators/style/style.styl.hbs
  65. +9 −0 generators/template/generator.json
  66. 0 generators/template/template.hbs.hbs
  67. +11 −0 generators/view/generator.json
  68. +5 −0 generators/view/view.coffee.hbs
  69. +9 −0 generators/view_test/generator.json
  70. +5 −0 generators/view_test/view_test.coffee.hbs
  71. +38 −0 lib/routers/Crud.coffee
  72. +52 −0 lib/routers/IoCrud.coffee
  73. +6 −0 lib/routers/Model.coffee
  74. +8 −0 lib/schemas/Deed.coffee
  75. +8 −0 lib/schemas/Model.coffee
  76. +72 −0 lib/server.coffee
  77. +36 −0 package.json
  78. +24 −0 test/assets/test/index.html
  79. +11 −0 test/models/header_test.coffee
  80. +8 −0 test/test-helpers.coffee
  81. +3,590 −0 test/vendor/scripts/chai-1.2.0.js
  82. +4,699 −0 test/vendor/scripts/mocha-1.4.2.js
  83. +4,081 −0 test/vendor/scripts/sinon-1.4.2.js
  84. +95 −0 test/vendor/scripts/sinon-chai-2.1.2.js
  85. +199 −0 test/vendor/styles/mocha-1.4.2.css
  86. +27 −0 test/views/header_view_test.coffee
  87. +11 −0 test/views/home_page_view_test.coffee
  88. +1,431 −0 vendor/scripts/backbone-0.9.2.js
  89. +6 −0 vendor/scripts/bootstrap.min.js
  90. +2,166 −0 vendor/scripts/chaplin-1.0.0-pre-18afedc.coffee
  91. +11 −0 vendor/scripts/console-helper.js
  92. +9,227 −0 vendor/scripts/jquery-1.8.0.js
  93. +1,059 −0 vendor/scripts/underscore-1.3.3.js
  94. +9 −0 vendor/styles/bootstrap-responsive.min.css
  95. +9 −0 vendor/styles/bootstrap.min.css
@@ -0,0 +1,29 @@
+# Numerous always-ignore extensions
+*.diff
+*.err
+*.orig
+*.log
+*.rej
+*.swo
+*.swp
+*.vi
+*~
+*.sass-cache
+
+# OS or Editor folders
+.DS_Store
+.cache
+.project
+.settings
+.tmproj
+nbproject
+Thumbs.db
+
+# NPM packages folder.
+node_modules/
+
+# Brunch folder for temporary files.
+tmp/
+
+# Brunch output folder.
+public/
@@ -0,0 +1,21 @@
+{exec} = require 'child_process'
+{spawn} = require 'child_process'
+{fork} = require 'child_process'
+os = require 'os'
+
+if os.platform() is 'win32'
+ coffee = 'coffee.cmd'
+ brunch = 'brunch.cmd'
+ nodemon = 'nodemon.cmd'
+else
+ coffee = 'coffee'
+ brunch = 'brunch'
+ nodemon = 'nodemon'
+
+task 'run', 'Launch the server', ->
+ server = spawn coffee, ['lib/server'], {stdio: 'inherit'}
+
+task 'watch', 'Watches all brunches', ->
+ brunch = spawn brunch, ['w'], {stdio: 'inherit'}
+ nodemon = spawn nodemon, ['-w', 'lib', '-L'], {stdio: 'inherit'}
+
@@ -0,0 +1,73 @@
+# Brunch with Chaplin
+![](https://a248.e.akamai.net/camo.github.com/b7ebb8bbcec7938940cf8e9c441124c3bddafd3a/687474703a2f2f662e636c2e6c792f6974656d732f34373039326b30423141334a317a3166306b34362f6277632e706e67)
+
+Brunch with Chaplin is a skeleton (boilerplate) for [Brunch](http://brunch.io)
+based on [Chaplin](https://github.com/chaplinjs/chaplin) framework.
+
+Requires Brunch 1.4+.
+
+## Getting started
+* Create new project via executing `brunch new <project name>`.
+Brunch with chaplin is a default application skeleton for Brunch,
+so you don't need to specify `--skeleton` option for the command.
+* Build the project with `brunch b` or `brunch w`.
+* Open the `public/` dir to see the result.
+* Write your code.
+
+Example application built with the skeleton:
+[Ost.io](https://github.com/paulmillr/ostio).
+
+See [Chaplin github page](https://github.com/chaplinjs/chaplin) for
+documentation.
+
+## Difference from Chaplin Boilerplate
+[Chaplin Boilerplate](https://github.com/chaplinjs/chaplin-boilerplate)
+is a official boilerplate all for chaplin. This skeleton is almost the same,
+except a few changes:
+
+* Added Header.
+* Added authentication abstractions (`SessionController`, `LoginView` etc).
+* CommonJS is used instead of AMD, because it's easier to use & debug.
+
+## Features
+* HTML5Boilerplate 4.0.0 html & css are included.
+* CoffeeScript + Stylus + Handlebars as app languages
+(you can change this to anything you want)
+* Backbone as main framework
+* Supports IE6 and up.
+* Cross-module communication using the Mediator and Publish/Subscribe patterns
+* Controllers for managing individual UI views
+* Rails-style routes which map URLs to controller actions
+* An application view as dispatcher and view manager
+* Extended model, view and collection classes to avoid repetition and
+enforce conventions
+* Strict memory management and object disposal
+* A collection with additional manipulation methods for smarter change events
+* A collection view for easy and intelligent list rendering
+* Client-side authentication using service providers like Facebook, Google
+and Twitter
+
+## License
+The MIT license.
+
+Copyright (c) 2012 Paul Miller (http://paulmillr.com/)
+
+Copyright (c) 2012 Moviepilot GmbH, 9elements GmbH et al.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the "Software"), to deal in
+the Software without restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+of the Software, and to permit persons to whom the Software is furnished to do
+so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
@@ -0,0 +1,64 @@
+Chaplin = require 'chaplin'
+mediator = require 'mediator'
+routes = require 'routes'
+SessionController = require 'controllers/session_controller'
+HeaderController = require 'controllers/header_controller'
+FooterController = require 'controllers/footer_controller'
+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: 'Shack Karma'
+
+ 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()
+ new FooterController()
+
+ # Create additional mediator properties
+ # -------------------------------------
+ initMediator: ->
+ # Create a user property
+ Chaplin.mediator.user = null
+ # Add additional application-specific properties and methods
+ # Seal the mediator
+ Chaplin.mediator.seal()
No changes.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,24 @@
+<!doctype html>
+<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]-->
+<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8" lang="en"> <![endif]-->
+<!--[if IE 8]> <html class="no-js lt-ie9" lang="en"> <![endif]-->
+<!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]-->
+<head>
+ <meta charset="utf-8">
+ <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
+ <title>Shack Karma</title>
+ <meta name="viewport" content="width=device-width">
+ <link rel="stylesheet" href="/stylesheets/app.css">
+ <script src="/javascripts/vendor.js"></script>
+ <script src="/javascripts/app.js"></script>
+ <script>require('initialize');</script>
+</head>
+<body>
+ <header id="header-container"></header>
+
+ <div class="container">
+ <div id="page-container"></div>
+ <div id="footer-container"></div>
+ </div>
+</body>
+</html>
@@ -0,0 +1,3 @@
+Chaplin = require 'chaplin'
+
+module.exports = class Controller extends Chaplin.Controller
@@ -0,0 +1,8 @@
+Controller = require 'controllers/base/controller'
+DeedsPageView = require 'views/deeds_views'
+
+module.exports = class DeedsController extends Controller
+ historyURL: 'deeds'
+
+ index: ->
+ @view = new DeedsPageView()
@@ -0,0 +1,8 @@
+Controller = require 'controllers/base/controller'
+mediator = require 'mediator'
+FooterView = require 'views/footer_view'
+
+module.exports = class FooterController extends Controller
+ initialize: ->
+ super
+ @view = new FooterView()
@@ -0,0 +1,10 @@
+Controller = require 'controllers/base/controller'
+mediator = require 'mediator'
+Header = require 'models/header'
+HeaderView = require 'views/header_view'
+
+module.exports = class HeaderController extends Controller
+ initialize: ->
+ super
+ @model = new Header()
+ @view = new HeaderView({@model})
@@ -0,0 +1,8 @@
+Controller = require 'controllers/base/controller'
+HomePageView = require 'views/home_page_view'
+
+module.exports = class HomeController extends Controller
+ historyURL: 'home'
+
+ index: ->
+ @view = new HomePageView()
@@ -0,0 +1,46 @@
+mediator = require 'mediator'
+Controller = require 'controllers/base/controller'
+User = require 'models/user'
+LoginView = require 'views/login_view'
+
+module.exports = class SessionController extends Controller
+ initialize: ->
+ # Login flow events
+ # @subscribeEvent 'serviceProviderSession', @serviceProviderSession
+
+ # Handle login
+ # @subscribeEvent 'logout', @logout
+ # @subscribeEvent 'userData', @userData
+
+ # Handler events which trigger an action
+
+ # Show the login dialog
+ # @subscribeEvent '!showLogin', @showLoginView
+ # Try to login with a service provider
+ # @subscribeEvent '!login', @triggerLogin
+ # Initiate logout
+ # @subscribeEvent '!logout', @triggerLogout
+
+ # Determine the logged-in state
+ @getSession()
+
+ # Instantiate the user with the given data
+ createUser: (userData) ->
+ mediator.user = new User userData
+
+ # Try to get an existing session from one of the login providers
+ getSession: =>
+ $.ajax
+ type: 'POST'
+ url: '/authenticate'
+ data: '{}'
+ dataType: 'json'
+ contentType: 'application/json'
+ statusCode:
+ 401: =>
+ @showLoginView()
+ success: (data) ->
+
+ # Handler for the global !showLoginView event
+ showLoginView: =>
+ @view = new LoginView()
@@ -0,0 +1,5 @@
+Application = require 'application'
+
+$ ->
+ app = new Application()
+ app.initialize()
@@ -0,0 +1,88 @@
+utils = require 'lib/utils'
+Chaplin = require 'chaplin'
+
+module.exports = class ServiceProvider
+
+ # Mixin a Subscriber
+ _(@prototype).extend Chaplin.Subscriber
+
+ loading: false
+
+ constructor: ->
+ # Mixin a Deferred
+ _(this).extend $.Deferred()
+
+ utils.deferMethods
+ deferred: this
+ methods: ['triggerLogin', 'getLoginStatus']
+ onDeferral: @load
+
+ # Disposal
+ # --------
+
+ disposed: false
+
+ dispose: ->
+ return if @disposed
+
+ # Unbind handlers of global events
+ @unsubscribeAllEvents()
+
+ # Finished
+ @disposed = true
+
+ # You're frozen when your heart’s not open
+ Object.freeze? this
+
+###
+
+ Standard methods and their signatures:
+
+ load: ->
+ # Load a script like this:
+ utils.loadLib 'http://example.org/foo.js', @loadHandler, @reject
+
+ loadHandler: =>
+ # Init the library, then resolve
+ ServiceProviderLibrary.init(foo: 'bar')
+ @resolve()
+
+ isLoaded: ->
+ # Return a Boolean
+ Boolean window.ServiceProviderLibrary and ServiceProviderLibrary.login
+
+ # Trigger login popup
+ triggerLogin: (loginContext) ->
+ callback = _(@loginHandler).bind(this, loginContext)
+ ServiceProviderLibrary.login callback
+
+ # Callback for the login popup
+ loginHandler: (loginContext, response) =>
+
+ eventPayload = {provider: this, loginContext}
+ if response
+ # Publish successful login
+ mediator.publish 'loginSuccessful', eventPayload
+
+ # Publish the session
+ mediator.publish 'serviceProviderSession',
+ provider: this
+ userId: response.userId
+ accessToken: response.accessToken
+ # etc.
+
+ else
+ mediator.publish 'loginFail', eventPayload
+
+ getLoginStatus: (callback = @loginStatusHandler, force = false) ->
+ ServiceProviderLibrary.getLoginStatus callback, force
+
+ loginStatusHandler: (response) =>
+ return unless response
+ mediator.publish 'serviceProviderSession',
+ provider: this
+ userId: response.userId
+ accessToken: response.accessToken
+ # etc.
+
+###
Oops, something went wrong.

0 comments on commit 96364a6

Please sign in to comment.