Browse Source

Initial commit

pull/1/merge
vagrant 7 years ago
commit
9c35a8e6b7
950 changed files with 186980 additions and 0 deletions
  1. +2
    -0
      .gitattributes
  2. +38
    -0
      .gitignore
  3. +29
    -0
      .npmignore
  4. +72
    -0
      README.md
  5. +48
    -0
      app/application.coffee
  6. +0
    -0
      app/assets/images/.gitkeep
  7. +16
    -0
      app/assets/index.html
  8. +8
    -0
      app/controllers/base/controller.coffee
  9. +6
    -0
      app/controllers/home-controller.coffee
  10. +5
    -0
      app/initialize.coffee
  11. +13
    -0
      app/lib/support.coffee
  12. +12
    -0
      app/lib/utils.coffee
  13. +26
    -0
      app/lib/view-helper.coffee
  14. +9
    -0
      app/models/base/collection.coffee
  15. +5
    -0
      app/models/base/model.coffee
  16. +2
    -0
      app/routes.coffee
  17. +7
    -0
      app/views/base/collection-view.coffee
  18. +7
    -0
      app/views/base/view.coffee
  19. +9
    -0
      app/views/header-view.coffee
  20. +7
    -0
      app/views/home-page-view.coffee
  21. +11
    -0
      app/views/site-view.coffee
  22. +8
    -0
      app/views/styles/application.styl
  23. +21
    -0
      app/views/styles/header.styl
  24. +10
    -0
      app/views/styles/home-page.styl
  25. +8
    -0
      app/views/templates/header.hbs
  26. +3
    -0
      app/views/templates/home.hbs
  27. +6
    -0
      app/views/templates/site.hbs
  28. +33
    -0
      config.coffee
  29. +11
    -0
      generators/README.md
  30. +11
    -0
      generators/collection-test/collection-test.coffee.hbs
  31. +9
    -0
      generators/collection-test/generator.json
  32. +5
    -0
      generators/collection-view/collection-view.coffee.hbs
  33. +11
    -0
      generators/collection-view/generator.json
  34. +5
    -0
      generators/collection/collection.coffee.hbs
  35. +11
    -0
      generators/collection/generator.json
  36. +5
    -0
      generators/controller-test/controller-test.coffee.hbs
  37. +9
    -0
      generators/controller-test/generator.json
  38. +3
    -0
      generators/controller/controller.coffee.hbs
  39. +11
    -0
      generators/controller/generator.json
  40. +0
    -0
      generators/generator/generated_file.coffee.hbs
  41. +13
    -0
      generators/generator/generator.json
  42. +9
    -0
      generators/generator/generator.json.hbs
  43. +9
    -0
      generators/model-test/generator.json
  44. +5
    -0
      generators/model-test/model-test.coffee.hbs
  45. +11
    -0
      generators/model/generator.json
  46. +3
    -0
      generators/model/model.coffee.hbs
  47. +20
    -0
      generators/scaffold/controller.coffee.hbs
  48. +29
    -0
      generators/scaffold/generator.json
  49. +2
    -0
      generators/scaffold/route.coffee.hbs
  50. +9
    -0
      generators/style/generator.json
  51. +1
    -0
      generators/style/style.styl.hbs
  52. +9
    -0
      generators/template/generator.json
  53. +0
    -0
      generators/template/template.hbs.hbs
  54. +9
    -0
      generators/view-test/generator.json
  55. +5
    -0
      generators/view-test/view-test.coffee.hbs
  56. +11
    -0
      generators/view/generator.json
  57. +5
    -0
      generators/view/view.coffee.hbs
  58. +10
    -0
      node_modules/auto-reload-brunch/.npmignore
  59. +32
    -0
      node_modules/auto-reload-brunch/CHANGELOG.md
  60. +63
    -0
      node_modules/auto-reload-brunch/README.md
  61. +67
    -0
      node_modules/auto-reload-brunch/lib/index.js
  62. +6
    -0
      node_modules/auto-reload-brunch/node_modules/ws/.npmignore
  63. +5
    -0
      node_modules/auto-reload-brunch/node_modules/ws/.travis.yml
  64. +260
    -0
      node_modules/auto-reload-brunch/node_modules/ws/History.md
  65. +38
    -0
      node_modules/auto-reload-brunch/node_modules/ws/Makefile
  66. +159
    -0
      node_modules/auto-reload-brunch/node_modules/ws/README.md
  67. +115
    -0
      node_modules/auto-reload-brunch/node_modules/ws/bench/parser.benchmark.js
  68. +66
    -0
      node_modules/auto-reload-brunch/node_modules/ws/bench/sender.benchmark.js
  69. +105
    -0
      node_modules/auto-reload-brunch/node_modules/ws/bench/speed.js
  70. +105
    -0
      node_modules/auto-reload-brunch/node_modules/ws/bench/util.js
  71. +190
    -0
      node_modules/auto-reload-brunch/node_modules/ws/bin/wscat
  72. +14
    -0
      node_modules/auto-reload-brunch/node_modules/ws/binding.gyp
  73. +162
    -0
      node_modules/auto-reload-brunch/node_modules/ws/doc/ws.md
  74. +1
    -0
      node_modules/auto-reload-brunch/node_modules/ws/examples/fileapi/.npmignore
  75. +18
    -0
      node_modules/auto-reload-brunch/node_modules/ws/examples/fileapi/package.json
  76. +39
    -0
      node_modules/auto-reload-brunch/node_modules/ws/examples/fileapi/public/app.js
  77. +22
    -0
      node_modules/auto-reload-brunch/node_modules/ws/examples/fileapi/public/index.html
  78. +55
    -0
      node_modules/auto-reload-brunch/node_modules/ws/examples/fileapi/public/uploader.js
  79. +103
    -0
      node_modules/auto-reload-brunch/node_modules/ws/examples/fileapi/server.js
  80. +17
    -0
      node_modules/auto-reload-brunch/node_modules/ws/examples/serverstats-express_3/package.json
  81. +33
    -0
      node_modules/auto-reload-brunch/node_modules/ws/examples/serverstats-express_3/public/index.html
  82. +21
    -0
      node_modules/auto-reload-brunch/node_modules/ws/examples/serverstats-express_3/server.js
  83. +17
    -0
      node_modules/auto-reload-brunch/node_modules/ws/examples/serverstats/package.json
  84. +33
    -0
      node_modules/auto-reload-brunch/node_modules/ws/examples/serverstats/public/index.html
  85. +19
    -0
      node_modules/auto-reload-brunch/node_modules/ws/examples/serverstats/server.js
  86. +26
    -0
      node_modules/auto-reload-brunch/node_modules/ws/index.js
  87. +59
    -0
      node_modules/auto-reload-brunch/node_modules/ws/lib/BufferPool.js
  88. +47
    -0
      node_modules/auto-reload-brunch/node_modules/ws/lib/BufferUtil.fallback.js
  89. +16
    -0
      node_modules/auto-reload-brunch/node_modules/ws/lib/BufferUtil.js
  90. +24
    -0
      node_modules/auto-reload-brunch/node_modules/ws/lib/ErrorCodes.js
  91. +180
    -0
      node_modules/auto-reload-brunch/node_modules/ws/lib/Receiver.hixie.js
  92. +591
    -0
      node_modules/auto-reload-brunch/node_modules/ws/lib/Receiver.js
  93. +123
    -0
      node_modules/auto-reload-brunch/node_modules/ws/lib/Sender.hixie.js
  94. +220
    -0
      node_modules/auto-reload-brunch/node_modules/ws/lib/Sender.js
  95. +12
    -0
      node_modules/auto-reload-brunch/node_modules/ws/lib/Validation.fallback.js
  96. +16
    -0
      node_modules/auto-reload-brunch/node_modules/ws/lib/Validation.js
  97. +662
    -0
      node_modules/auto-reload-brunch/node_modules/ws/lib/WebSocket.js
  98. +425
    -0
      node_modules/auto-reload-brunch/node_modules/ws/lib/WebSocketServer.js
  99. +5
    -0
      node_modules/auto-reload-brunch/node_modules/ws/lib/browser.js
  100. +4
    -0
      node_modules/auto-reload-brunch/node_modules/ws/node_modules/commander/.npmignore

+ 2
- 0
.gitattributes View File

@ -0,0 +1,2 @@
# Set default behaviour, in case users don't have core.autocrlf set.
* text=auto

+ 38
- 0
.gitignore View File

@ -0,0 +1,38 @@
# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.so
# Packages #
############
# it's better to unpack these files and commit the raw source
# git has its own built in compression methods
*.7z
*.dmg
*.gz
*.iso
*.jar
*.rar
*.tar
*.zip
# Logs and databases #
######################
*.log
*.sql
*.sqlite
# OS generated files #
######################
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
Icon?
ehthumbs.db
Thumbs.db

+ 29
- 0
.npmignore View File

@ -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/

+ 72
- 0
README.md View File

@ -0,0 +1,72 @@
# 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](http://chaplinjs.org) architecture.
Requires Brunch 1.6+.
## 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 site](http://chaplinjs.org) for docs and more info.
## 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.
* CommonJS is used instead of AMD, because it's easier to use & debug.
## Features
* HTML5Boilerplate html & css are included.
* CoffeeScript + Stylus + Handlebars as app languages
(you can change this to anything you want)
* Backbone as main MVC/MVP library, Chaplin as meta-framework.
* Support of IE8 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
## Authentication
If you build an application with authentication, there are some useful abstractions for it out there: https://github.com/chaplinjs/chaplin-auth.
## 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.

+ 48
- 0
app/application.coffee View File

@ -0,0 +1,48 @@
Chaplin = require 'chaplin'
routes = require 'routes'
# 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 Chaplin.Layout#adjustTitle)
title: 'Brunch example application'
initialize: ->
super
# Initialize core components.
# ---------------------------
# Register all 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/'
@initRouter routes
# Dispatcher listens for routing events and initialises controllers.
@initDispatcher controllerSuffix: '-controller'
# Layout listens for click events & delegates internal links to router.
@initLayout()
# Composer grants the ability for views and stuff to be persisted.
@initComposer()
# Mediator is a global message broker which implements pub / sub pattern.
@initMediator()
# Actually start routing.
@startRouting()
# Freeze the application instance to prevent further changes.
Object.freeze? this
# Create additional mediator properties.
initMediator: ->
# Add additional application-specific properties and methods
# e.g. Chaplin.mediator.prop = null
# Seal the mediator.
Chaplin.mediator.seal()

+ 0
- 0
app/assets/images/.gitkeep View File


+ 16
- 0
app/assets/index.html View File

@ -0,0 +1,16 @@
<!doctype html>
<!--[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>Brunch example application</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>
</body>
</html>

+ 8
- 0
app/controllers/base/controller.coffee View File

@ -0,0 +1,8 @@
Chaplin = require 'chaplin'
SiteView = require 'views/site-view'
HeaderView = require 'views/header-view'
module.exports = class Controller extends Chaplin.Controller
beforeAction: ->
@compose 'site', SiteView
@compose 'header', HeaderView

+ 6
- 0
app/controllers/home-controller.coffee View File

@ -0,0 +1,6 @@
Controller = require 'controllers/base/controller'
HomePageView = require 'views/home-page-view'
module.exports = class HomeController extends Controller
index: ->
@view = new HomePageView region: 'main'

+ 5
- 0
app/initialize.coffee View File

@ -0,0 +1,5 @@
Application = require 'application'
# Initialize the application on DOM ready event.
$ ->
(new Application).initialize()

+ 13
- 0
app/lib/support.coffee View File

@ -0,0 +1,13 @@
Chaplin = require 'chaplin'
utils = require 'lib/utils'
# Application-specific feature detection
# --------------------------------------
# Delegate to Chaplins support module
support = utils.beget Chaplin.support
# _(support).extend
# someMethod: ->
module.exports = support

+ 12
- 0
app/lib/utils.coffee View File

@ -0,0 +1,12 @@
Chaplin = require 'chaplin'
# Application-specific utilities
# ------------------------------
# Delegate to Chaplins utils module
utils = Chaplin.utils.beget Chaplin.utils
# _(utils).extend
# someMethod: ->
module.exports = utils

+ 26
- 0
app/lib/view-helper.coffee View File

@ -0,0 +1,26 @@
Chaplin = require 'chaplin'
# Application-specific view helpers
# http://handlebarsjs.com/#helpers
# --------------------------------
# Map helpers
# -----------
# Make 'with' behave a little more mustachey.
Handlebars.registerHelper 'with', (context, options) ->
if not context or Handlebars.Utils.isEmpty context
options.inverse(this)
else
options.fn(context)
# Inverse for 'with'.
Handlebars.registerHelper 'without', (context, options) ->
inverse = options.inverse
options.inverse = options.fn
options.fn = inverse
Handlebars.helpers.with.call(this, context, options)
# Get Chaplin-declared named routes. {{#url "like" "105"}}{{/url}}
Handlebars.registerHelper 'url', (routeName, params..., options) ->
Chaplin.helpers.reverse routeName, params

+ 9
- 0
app/models/base/collection.coffee View File

@ -0,0 +1,9 @@
Chaplin = require 'chaplin'
Model = require 'models/base/model'
module.exports = class Collection extends Chaplin.Collection
# Mixin a synchronization state machine
# _(@prototype).extend Chaplin.SyncMachine
# Use the project base model per default, not Chaplin.Model
model: Model

+ 5
- 0
app/models/base/model.coffee View File

@ -0,0 +1,5 @@
Chaplin = require 'chaplin'
module.exports = class Model extends Chaplin.Model
# Mixin a synchronization state machine
# _(@prototype).extend Chaplin.SyncMachine

+ 2
- 0
app/routes.coffee View File

@ -0,0 +1,2 @@
module.exports = (match) ->
match '', 'home#index'

+ 7
- 0
app/views/base/collection-view.coffee View File

@ -0,0 +1,7 @@
Chaplin = require 'chaplin'
View = require 'views/base/view'
module.exports = class CollectionView extends Chaplin.CollectionView
# This class doesnt inherit from the application-specific View class,
# so we need to borrow the method from the View prototype:
getTemplateFunction: View::getTemplateFunction

+ 7
- 0
app/views/base/view.coffee View File

@ -0,0 +1,7 @@
Chaplin = require 'chaplin'
require 'lib/view-helper' # Just load the view helpers, no return value
module.exports = class View extends Chaplin.View
# Precompiled templates function initializer.
getTemplateFunction: ->
@template

+ 9
- 0
app/views/header-view.coffee View File

@ -0,0 +1,9 @@
View = require 'views/base/view'
template = require 'views/templates/header'
module.exports = class HeaderView extends View
autoRender: yes
className: 'header'
region: 'header'
id: 'header'
template: template

+ 7
- 0
app/views/home-page-view.coffee View File

@ -0,0 +1,7 @@
template = require 'views/templates/home'
View = require 'views/base/view'
module.exports = class HomePageView extends View
autoRender: yes
className: 'home-page'
template: template

+ 11
- 0
app/views/site-view.coffee View File

@ -0,0 +1,11 @@
View = require 'views/base/view'
template = require 'views/templates/site'
# Site view is a top-level view which is bound to body.
module.exports = class SiteView extends View
container: 'body'
id: 'site-container'
regions:
'#header-container': 'header'
'#page-container': 'main'
template: template

+ 8
- 0
app/views/styles/application.styl View File

@ -0,0 +1,8 @@
// nib is a powerful lib for stylus that provides cross-browser css3 mixins.
// No more vendor prefixes. http://visionmedia.github.com/nib/
@import 'nib'
// Apply a natural box layout model to all elements.
// http://paulirish.com/2012/box-sizing-border-box-ftw/
*
box-sizing: border-box

+ 21
- 0
app/views/styles/header.styl View File

@ -0,0 +1,21 @@
@import 'nib'
.header
width: 476px
margin: 0 auto
padding: 10px
background-color: #4276b6
&-link
margin-right: 32px
text-decoration: none
color: #eee
&:visited
color: #eee
&:hover
text-decoration: underline
&:last-child
margin-right: 0

+ 10
- 0
app/views/styles/home-page.styl View File

@ -0,0 +1,10 @@
@import 'nib'
.home-page
width: 476px
height: 130px
margin: 5px auto
padding: 5px
margin-bottom: 0.5em
color: #fff
background-color: #4276b6

+ 8
- 0
app/views/templates/header.hbs View File

@ -0,0 +1,8 @@
<a class="header-link" href="test/">App tests</a>
<a class="header-link" href="http://brunch.readthedocs.org/">Docs</a>
<a class="header-link" href="https://github.com/brunch/brunch/issues">
GitHub issues
</a>
<a class="header-link" href="https://github.com/paulmillr/ostio">
Ost.io example app
</a>

+ 3
- 0
app/views/templates/home.hbs View File

@ -0,0 +1,3 @@
<a href="http://brunch.io/">
<img src="http://brunch.io/images/brunch.png" alt="Brunch" />
</a>

+ 6
- 0
app/views/templates/site.hbs View File

@ -0,0 +1,6 @@
<header class="header-container" id="header-container"></header>
<div class="container outer-container">
<div class="page-container" id="page-container">
</div>
</div>

+ 33
- 0
config.coffee View File

@ -0,0 +1,33 @@
exports.config =
# See http://brunch.io/#documentation for docs.
paths:
public: '/usr/share/nginx/www'
files:
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-polyfill.js',
'vendor/scripts/jquery-1.9.1.js',
'vendor/scripts/lodash-1.2.0.js',
'vendor/scripts/backbone-1.0.0.js'
]
after: [
'test/vendor/scripts/test-helper.js'
]
stylesheets:
joinTo:
'stylesheets/app.css': /^(app|vendor)/
'test/stylesheets/test.css': /^test/
order:
after: ['vendor/styles/helpers.css']
templates:
joinTo: 'javascripts/app.js'

+ 11
- 0
generators/README.md View File

@ -0,0 +1,11 @@
# Generators
These are generators for [scaffolt](https://github.com/paulmillr/scaffolt).
Usage:
```
scaffolt view user
scaffolt model cart --revert
scaffolt controller header --path controllers/regions/header.coffee
```

+ 11
- 0
generators/collection-test/collection-test.coffee.hbs View File

@ -0,0 +1,11 @@
{{#camelize}}{{name}}{{/camelize}} = require 'models/{{name}}'
{{#camelize}}{{pluralName}}{{/camelize}} = require 'models/{{pluralName}}'
describe '{{#camelize}}{{name}}{{/camelize}}', ->
beforeEach ->
@model = new {{#camelize}}{{name}}{{/camelize}}()
@collection = new {{#camelize}}{{pluralName}}{{/camelize}}()
afterEach ->
@model.dispose()
@collection.dispose()

+ 9
- 0
generators/collection-test/generator.json View File

@ -0,0 +1,9 @@
{
"files": [
{
"from": "collection-test.coffee.hbs",
"to": "test/models/{{pluralName}}-test.coffee"
}
],
"dependencies": []
}

+ 5
- 0
generators/collection-view/collection-view.coffee.hbs View File

@ -0,0 +1,5 @@
CollectionView = require 'views/base/collection-view'
{{#camelize}}{{name}}{{/camelize}} = require 'views/{{name}}-view'
module.exports = class {{#camelize}}{{pluralName}}{{/camelize}}View extends CollectionView
itemView: {{#camelize}}{{name}}{{/camelize}}

+ 11
- 0
generators/collection-view/generator.json View File

@ -0,0 +1,11 @@
{
"files": [
{
"from": "collection-view.coffee.hbs",
"to": "app/views/{{name}}-view.coffee"
}
],
"dependencies": [
{"name": "view-test", "params": "{{name}}"}
]
}

+ 5
- 0
generators/collection/collection.coffee.hbs View File

@ -0,0 +1,5 @@
Collection = require 'models/base/collection'
{{#camelize}}{{name}}{{/camelize}} = require 'models/{{name}}'
module.exports = class {{#camelize}}{{pluralName}}{{/camelize}} extends Collection
model: {{#camelize}}{{name}}{{/camelize}}

+ 11
- 0
generators/collection/generator.json View File

@ -0,0 +1,11 @@
{
"files": [
{
"from": "collection.coffee.hbs",
"to": "app/models/{{pluralName}}.coffee"
}
],
"dependencies": [
{"name": "collection-test", "params": "{{name}}"}
]
}

+ 5
- 0
generators/controller-test/controller-test.coffee.hbs View File

@ -0,0 +1,5 @@
{{#camelize}}{{name}}{{/camelize}} = require 'controllers/{{name}}-controller'
describe '{{#camelize}}{{name}}{{/camelize}}', ->
beforeEach ->
@controller = new {{#camelize}}{{name}}{{/camelize}}()

+ 9
- 0
generators/controller-test/generator.json View File

@ -0,0 +1,9 @@
{
"files": [
{
"from": "controller-test.coffee.hbs",
"to": "test/controllers/{{name}}-controller-test.coffee"
}
],
"dependencies": []
}

+ 3
- 0
generators/controller/controller.coffee.hbs View File

@ -0,0 +1,3 @@
Controller = require 'controllers/base/controller'
module.exports = class {{#camelize}}{{pluralName}}{{/camelize}}Controller extends Controller

+ 11
- 0
generators/controller/generator.json View File

@ -0,0 +1,11 @@
{
"files": [
{
"from": "controller.coffee.hbs",
"to": "app/controllers/{{name}}-controller.coffee"
}
],
"dependencies": [
{"name": "controller-test", "params": "{{name}}"}
]
}

+ 0
- 0
generators/generator/generated_file.coffee.hbs View File


+ 13
- 0
generators/generator/generator.json View File

@ -0,0 +1,13 @@
{
"files": [
{
"from": "generator.json.hbs",
"to": "generators/{{name}}/generator.json"
},
{
"from": "generated_file.coffee.hbs",
"to": "generators/{{name}}/{{name}}.coffee.hbs"
}
],
"dependencies": []
}

+ 9
- 0
generators/generator/generator.json.hbs View File

@ -0,0 +1,9 @@
{
"files": [
{
"from": "{{name}}.coffee.hbs",
"to": "app/file.coffee"
}
],
"dependencies": []
}

+ 9
- 0
generators/model-test/generator.json View File

@ -0,0 +1,9 @@
{
"files": [
{
"from": "model-test.coffee.hbs",
"to": "test/models/{{name}}-test.coffee"
}
],
"dependencies": []
}

+ 5
- 0
generators/model-test/model-test.coffee.hbs View File

@ -0,0 +1,5 @@
{{#camelize}}{{name}}{{/camelize}} = require 'models/{{name}}'
describe '{{#camelize}}{{name}}{{/camelize}}', ->
beforeEach ->
@model = new {{#camelize}}{{name}}{{/camelize}}()

+ 11
- 0
generators/model/generator.json View File

@ -0,0 +1,11 @@
{
"files": [
{
"from": "model.coffee.hbs",
"to": "app/models/{{name}}.coffee"
}
],
"dependencies": [
{"name": "model-test", "params": "{{name}}"}
]
}

+ 3
- 0
generators/model/model.coffee.hbs View File

@ -0,0 +1,3 @@
Model = require 'models/base/model'
module.exports = class {{#camelize}}{{name}}{{/camelize}} extends Model

+ 20
- 0
generators/scaffold/controller.coffee.hbs View File

@ -0,0 +1,20 @@
Controller = require 'controllers/base/controller'
{{#camelize}}{{name}}{{/camelize}} = require 'models/{{name}}'
{{#camelize}}{{name}}{{/camelize}}PageView = require 'views/{{name}}-page-view'
{{#camelize}}{{pluralName}}{{/camelize}}Collection = require 'models/{{pluralName}}-collection'
{{#camelize}}{{pluralName}}{{/camelize}}CollectionView = require 'views/{{pluralName}}-collection-view'
module.exports = class {{#camelize}}{{pluralName}}{{/camelize}}Controller extends Controller
historyURL: '{{name}}'
index: ->
@collection = new {{#camelize}}{{pluralName}}{{/camelize}}Collection()
@view = new {{#camelize}}{{pluralName}}{{/camelize}}CollectionView {@collection}
@collection.fetch
success: => @view.render()
show: (params) ->
@model = new {{#camelize}}{{name}}{{/camelize}} id: params.id
@view = new {{#camelize}}{{name}}{{/camelize}}PageView {@model}
@model.fetch
success: => @view.render()

+ 29
- 0
generators/scaffold/generator.json View File

@ -0,0 +1,29 @@
{
"files": [
{
"from": "controller.coffee.hbs",
"to": "app/controllers/{{name}}-controller.coffee"
},
{
"from": "route.coffee.hbs",
"to": "app/routes.coffee",
"method": "append"
}
],
"dependencies": [
{"name": "model", "params": "{{name}}"},
{"name": "collection", "params": "{{name}}"},
{"name": "view", "params": "{{name}}-item"},
{"name": "style", "params": "{{name}}-item"},
{"name": "template", "params": "{{name}}-item"},
{"name": "view", "params": "{{name}}-page"},
{"name": "style", "params": "{{name}}-page"},
{"name": "template", "params": "{{name}}-page"},
{"name": "collection-view", "params": "{{pluralName}}"},
{"name": "style", "params": "{{pluralName}}"},
{"name": "template", "params": "{{pluralName}}"}
]
}

+ 2
- 0
generators/scaffold/route.coffee.hbs View File

@ -0,0 +1,2 @@
match '{{pluralName}}', '{{pluralName}}#index', name: '{{pluralName}}'
match '{{pluralName}}/:id', '{{pluralName}}#show', name: '{{name}}', constraints: {id: /^\d+$/}

+ 9
- 0
generators/style/generator.json View File

@ -0,0 +1,9 @@
{
"files": [
{
"from": "style.styl.hbs",
"to": "app/views/styles/{{name}}.styl"
}
],
"dependencies": []
}

+ 1
- 0
generators/style/style.styl.hbs View File

@ -0,0 +1 @@
@import 'nib'

+ 9
- 0
generators/template/generator.json View File

@ -0,0 +1,9 @@
{
"files": [
{
"from": "template.hbs.hbs",
"to": "app/views/templates/{{name}}.hbs"
}
],
"dependencies": []
}

+ 0
- 0
generators/template/template.hbs.hbs View File


+ 9
- 0
generators/view-test/generator.json View File

@ -0,0 +1,9 @@
{
"files": [
{
"from": "view-test.coffee.hbs",
"to": "test/views/{{name}}-view-test.coffee"
}
],
"dependencies": []
}

+ 5
- 0
generators/view-test/view-test.coffee.hbs View File

@ -0,0 +1,5 @@
{{#camelize}}{{name}}{{/camelize}}View = require 'views/{{name}}-view'
describe '{{#camelize}}{{name}}{{/camelize}}View', ->
beforeEach ->
@view = new {{#camelize}}{{name}}{{/camelize}}View()

+ 11
- 0
generators/view/generator.json View File

@ -0,0 +1,11 @@
{
"files": [
{
"from": "view.coffee.hbs",
"to": "app/views/{{name}}-view.coffee"
}
],
"dependencies": [
{"name": "view-test", "params": "{{name}}"}
]
}

+ 5
- 0
generators/view/view.coffee.hbs View File

@ -0,0 +1,5 @@
View = require 'views/base/view'
template = require 'views/templates/{{name}}'
module.exports = class {{#camelize}}{{name}}{{/camelize}}View extends View
template: template

+ 10
- 0
node_modules/auto-reload-brunch/.npmignore View File

@ -0,0 +1,10 @@
.lock-wscript
.svn/
.hg/
.git/
CVS/
*~
*.bak
.DS_Store
npm-debug.log
test/

+ 32
- 0
node_modules/auto-reload-brunch/CHANGELOG.md View File

@ -0,0 +1,32 @@
# auto-reload-brunch 1.6.1 (18 April 2013)
* Moved configuration to `config.plugins.autoReload` from `config.autoReload`.
# auto-reload-brunch 1.6.0 (7 April 2013)
* Enabled plugin by default.
# auto-reload-brunch 1.5.2 (19 March 2013)
* Added node 0.10 support, removed coffee-script dependency.
# auto-reload-brunch 1.5.1 (30 January 2013)
* Plugin is now disabled in production environment (w / --optimize).
# auto-reload-brunch 1.5.0 (13 January 2013)
* Improved installation process.
# auto-reload-brunch 1.4.0 (26 November 2012)
* Added ability to customize websocket server ip & port and remote server ip.
# auto-reload-brunch 1.3.2 (15 July 2012)
* Updated `ws` dependency to 0.4.20.
# auto-reload-brunch 1.3.1 (29 June 2012)
* Fixed `config.persistent` bug.
# auto-reload-brunch 1.3.0 (29 June 2012)
* Reloading became smarter. If you change stylesheet, the page itself
won't be reloaded etc.
* Added node.js 0.8 and 0.9 support.
* Package is now precompiled before every publishing to npm.
# auto-reload-brunch 1.2.0 (18 May 2012)
* Initial release.

+ 63
- 0
node_modules/auto-reload-brunch/README.md View File

@ -0,0 +1,63 @@
## auto-reload-brunch
Adds automatic browser reloading support to
[brunch](http://brunch.io).
The plugin uses WebSocket technology to pass `compile` events to browser.
## Usage
Install the plugin via npm with `npm install --save auto-reload-brunch`.
Or, do manual install:
* Add `"auto-reload-brunch": "x.y.z"` to `package.json` of your brunch app.
Pick a plugin version that corresponds to your minor (y) brunch version.
* If you want to use git version of plugin, add
`"auto-reload-brunch": "git+ssh://git@github.com:brunch/auto-reload-brunch.git"`.
Auto-reload-brunch can be disabled with this command:
<script>
window.brunch = window.brunch || {};
window.brunch['auto-reload'] = {disabled: true};
</script>
Additionally, if your `brunch watch` is running on a different machine than your
preview screen, you can add `server` config variable to connect to a brunch/websocket server running
another ip address.
window.brunch['server'] = 'xxx.xxx.xxx.xxx';
To use auto reload on a specific port, such as when multiple apps are running
on the same domain, configure the following. On the client:
window.brunch['auto-reload'].port = 1234
In config.coffee
plugins:
autoReload:
port: 1234
## License
The MIT License (MIT)
Copyright (c) 2012-2013 Paul Miller (http://paulmillr.com)
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.

+ 67
- 0
node_modules/auto-reload-brunch/lib/index.js View File

@ -0,0 +1,67 @@
// Generated by CoffeeScript 1.6.2
var AutoReloader, WebSocketServer, sysPath,
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
sysPath = require('path');
WebSocketServer = (require('ws')).Server;
module.exports = AutoReloader = (function() {
AutoReloader.prototype.brunchPlugin = true;
function AutoReloader(config) {
var cfg, port, _ref, _ref1, _ref2, _ref3,
_this = this;
this.config = config;
this.onCompile = __bind(this.onCompile, this);
if (this.config.autoReload) {
console.warn('Warning: config.autoReload is deprecated, please move it to config.plugins.autoReload');
}
this.enabled = this.config.persistent && !this.config.optimize;
this.connections = [];
if (this.enabled) {
cfg = (_ref = (_ref1 = (_ref2 = this.config.plugins) != null ? _ref2.autoReload : void 0) != null ? _ref1 : this.config.autoReload) != null ? _ref : {};
port = (_ref3 = cfg.port) != null ? _ref3 : 9485;
this.server = new WebSocketServer({
host: '0.0.0.0',
port: port
});
this.server.on('connection', function(connection) {
_this.connections.push(connection);
return connection.on('close', function() {
return _this.connections.splice(connection, 1);
});
});
}
}
AutoReloader.prototype.onCompile = function(changedFiles) {
var allCss, message,
_this = this;
if (!this.enabled) {
return;
}
allCss = (changedFiles.length > 0) && (changedFiles.every(function(file) {
return sysPath.extname(file.path) === '.css';
}));
message = allCss ? 'stylesheet' : 'page';
return this.connections.filter(function(connection) {
return connection.readyState === 1;
}).forEach(function(connection) {
return connection.send(message);
});
};
AutoReloader.prototype.include = function() {
if (this.enabled) {
return [sysPath.join(__dirname, '..', 'vendor', 'auto-reload.js')];
} else {
return [];
}
};
return AutoReloader;
})();

+ 6
- 0
node_modules/auto-reload-brunch/node_modules/ws/.npmignore View File

@ -0,0 +1,6 @@
npm-debug.log
node_modules
.*.swp
.lock-*
build

+ 5
- 0
node_modules/auto-reload-brunch/node_modules/ws/.travis.yml View File

@ -0,0 +1,5 @@
language: node_js
npm_args: --ws:native
node_js:
- 0.6
- 0.8

+ 260
- 0
node_modules/auto-reload-brunch/node_modules/ws/History.md View File

@ -0,0 +1,260 @@
v0.4.24 - December 6th, 2012
=====================
* Removed install.js. [shtylman]
* Added browser field to package.json. [shtylman]
* Support overwriting host header. [Raynos]
* Emit 'listening' also with custom http server. [sebiq]
v0.4.24 - December 6th, 2012
=====================
* Yet another intermediate release, to not delay minor features any longer.
* Native support installation issues further circumvented. [einaros]
v0.4.23 - November 19th, 2012
=====================
* Service release - last before major upgrade.
* Changes default host from 127.0.0.1 to 0.0.0.0. [einaros]
v0.4.22 - October 3rd, 2012
=====================
* clear failsafe cleanup timeout once cleanup is called [AndreasMadsen]
* added w3c compatible CloseEvent for onclose / addEventListener("close", ...). [einaros]
* fix the sub protocol header handler [sonnyp]
* fix unhandled exception if socket closes and 'error' is emitted [jmatthewsr-ms]
v0.4.21 - July 14th, 2012
=====================
* Emit error if server reponds with anything other than status code 101. [einaros]
* Added 'headers' event to server. [rauchg]
* path.exists moved to fs.exists. [blakmatrix]
v0.4.20 - June 26th, 2012
=====================
* node v0.8.0 compatibility release.
v0.4.19 - June 19th, 2012
=====================
* Change sender to merge buffers for relatively small payloads, may improve perf in some cases [einaros]
* Avoid EventEmitter for Receiver classes. As above this may improve perf. [einaros]
* Renamed fallback files from the somewhat misleading '*Windows'. [einaros]
v0.4.18 - June 14th 2012
=====================
* Fixed incorrect md5 digest encoding in Hixie handshake [nicokaiser]
* Added example of use with Express 3 [einaros]
* Change installation procedure to not require --ws:native to build native extensions. They will now build if a compiler is available. [einaros]
v0.4.17 - June 13th 2012
=====================
* Improve error handling during connection handshaking [einaros]
* Ensure that errors are caught also after connection teardown [nicokaiser]
* Update 'mocha' version to 1.1.0. [einaros]
* Stop showing 'undefined' for some error logs. [tricknotes]
* Update 'should' version to 0.6.3 [tricknotes]
v0.4.16 - June 1st 2012
=====================
* Build fix for Windows. [einaros]
v0.4.15 - May 20th 2012
=====================
* Enable fauxe streaming for hixie tansport. [einaros]
* Allow hixie sender to deal with buffers. [einaros/pigne]
* Allow error code 1011. [einaros]
* Fix framing for empty packets (empty pings and pongs might break). [einaros]
* Improve error and close handling, to avoid connections lingering in CLOSING state. [einaros]
v0.4.14 - Apr 30th 2012
=====================
* use node-gyp instead of node-waf [TooTallNate]
* remove old windows compatibility makefile, and silently fall back to native modules [einaros]
* ensure connection status [nicokaiser]
* websocket client updated to use port 443 by default for wss:// connections [einaros]
* support unix sockets [kschzt]
v0.4.13 - Apr 12th 2012
=====================
* circumvent node 0.6+ related memory leak caused by Object.defineProperty [nicokaiser]
* improved error handling, improving stability in massive load use cases [nicokaiser]
v0.4.12 - Mar 30th 2012
=====================
* various memory leak / possible memory leak cleanups [einaros]
* api documentation [nicokaiser]
* add option to disable client tracking [nicokaiser]
v0.4.11 - Mar 24th 2012
=====================
* node v0.7 compatibillity release
* gyp support [TooTallNate]
* commander dependency update [jwueller]
* loadbalancer support [nicokaiser]
v0.4.10 - Mar 22th 2012
=====================
* Final hixie close frame fixes. [nicokaiser]
v0.4.9 - Mar 21st 2012
=====================
* Various hixie bugfixes (such as proper close frame handling). [einaros]
v0.4.8 - Feb 29th 2012
=====================
* Allow verifyClient to run asynchronously [karlsequin]
* Various bugfixes and cleanups. [einaros]
v0.4.7 - Feb 21st 2012
=====================
* Exposed bytesReceived from websocket client object, which makes it possible to implement bandwidth sampling. [einaros]
* Updated browser based file upload example to include and output per websocket channel bandwidth sampling. [einaros]
* Changed build scripts to check which architecture is currently in use. Required after the node.js changes to have prebuilt packages target ia32 by default. [einaros]
v0.4.6 - Feb 9th 2012
=====================
* Added browser based file upload example. [einaros]
* Added server-to-browser status push example. [einaros]
* Exposed pause() and resume() on WebSocket object, to enable client stream shaping. [einaros]
v0.4.5 - Feb 7th 2012
=====================
* Corrected regression bug in handling of connections with the initial frame delivered across both http upgrade head and a standalone packet. This would lead to a race condition, which in some cases could cause message corruption. [einaros]
v0.4.4 - Feb 6th 2012
=====================
* Pass original request object to verifyClient, for cookie or authentication verifications. [einaros]
* Implemented addEventListener and slightly improved the emulation API by adding a MessageEvent with a readonly data attribute. [aslakhellesoy]
* Rewrite parts of hybi receiver to avoid stack overflows for large amounts of packets bundled in the same buffer / packet. [einaros]
v0.4.3 - Feb 4th 2012
=====================
* Prioritized update: Corrected issue which would cause sockets to stay open longer than necessary, and resource leakage because of this. [einaros]
v0.4.2 - Feb 4th 2012
=====================
* Breaking change: WebSocketServer's verifyOrigin option has been renamed to verifyClient. [einaros]
* verifyClient now receives { origin: 'origin header', secure: true/false }, where 'secure' will be true for ssl connections. [einaros]
* Split benchmark, in preparation for more thorough case. [einaros]
* Introduced hixie-76 draft support for server, since Safari (iPhone / iPad / OS X) and Opera still aren't updated to use Hybi. [einaros]
* Expose 'supports' object from WebSocket, to indicate e.g. the underlying transport's support for binary data. [einaros]
* Test and code cleanups. [einaros]
v0.4.1 - Jan 25th 2012
=====================
* Use readline in wscat [tricknotes]
* Refactor _state away, in favor of the new _readyState [tricknotes]
* travis-ci integration [einaros]
* Fixed race condition in testsuite, causing a few tests to fail (without actually indicating errors) on travis [einaros]
* Expose pong event [paddybyers]
* Enabled running of WebSocketServer in noServer-mode, meaning that upgrades are passed in manually. [einaros]
* Reworked connection procedure for WebSocketServer, and cleaned up tests. [einaros]
v0.4.0 - Jan 2nd 2012
=====================
* Windows compatibility [einaros]
* Windows compatible test script [einaros]
v0.3.9 - Jan 1st 2012
======================
* Improved protocol framing performance [einaros]
* WSS support [kazuyukitanimura]
* WSS tests [einaros]
* readyState exposed [justinlatimer, tricknotes]
* url property exposed [justinlatimer]
* Removed old 'state' property [einaros]
* Test cleanups [einaros]
v0.3.8 - Dec 27th 2011
======================
* Made it possible to listen on specific paths, which is especially good to have for precreated http servers [einaros]
* Extensive WebSocket / WebSocketServer cleanup, including changing all internal properties to unconfigurable, unenumerable properties [einaros]
* Receiver modifications to ensure even better performance with fragmented sends [einaros]
* Fixed issue in sender.js, which would cause SlowBuffer instances (such as returned from the crypto library's randomBytes) to be copied (and thus be dead slow) [einaros]
* Removed redundant buffer copy in sender.js, which should improve server performance [einaros]
v0.3.7 - Dec 25nd 2011
======================
* Added a browser based API which uses EventEmitters internally [3rd-Eden]
* Expose request information from upgrade event for websocket server clients [mmalecki]
v0.3.6 - Dec 19th 2011
======================
* Added option to let WebSocket.Server use an already existing http server [mmalecki]
* Migrating various option structures to use options.js module [einaros]
* Added a few more tests, options and handshake verifications to ensure that faulty connections are dealt with [einaros]
* Code cleanups in Sender and Receiver, to ensure even faster parsing [einaros]
v0.3.5 - Dec 13th 2011
======================
* Optimized Sender.js, Receiver.js and bufferutil.cc:
* Apply loop-unrolling-like small block copies rather than use node.js Buffer#copy() (which is slow).
* Mask blocks of data using combination of 32bit xor and loop-unrolling, instead of single bytes.
* Keep pre-made send buffer for small transfers.
* Leak fixes and code cleanups.
v0.3.3 - Dec 12th 2011
======================
* Compile fix for Linux.
* Rewrote parts of WebSocket.js, to avoid try/catch and thus avoid optimizer bailouts.
v0.3.2 - Dec 11th 2011
======================
* Further performance updates, including the additions of a native BufferUtil module, which deals with several of the cpu intensive WebSocket operations.
v0.3.1 - Dec 8th 2011
======================
* Service release, fixing broken tests.
v0.3.0 - Dec 8th 2011
======================
* Node.js v0.4.x compatibility.
* Code cleanups and efficiency improvements.
* WebSocket server added, although this will still mainly be a client library.
* WebSocket server certified to pass the Autobahn test suite.
* Protocol improvements and corrections - such as handling (redundant) masks for empty fragments.
* 'wscat' command line utility added, which can act as either client or server.
v0.2.6 - Dec 3rd 2011
======================
* Renamed to 'ws'. Big woop, right -- but easy-websocket really just doesn't cut it anymore!
v0.2.5 - Dec 3rd 2011
======================
* Rewrote much of the WebSocket parser, to ensure high speed for highly fragmented messages.
* Added a BufferPool, as a start to more efficiently deal with allocations for WebSocket connections. More work to come, in that area.
* Updated the Autobahn report, at http://einaros.github.com/easy-websocket, with comparisons against WebSocket-Node 1.0.2 and Chrome 16.
v0.2.0 - Nov 25th 2011
======================
* Major rework to make sure all the Autobahn test cases pass. Also updated the internal tests to cover more corner cases.
v0.1.2 - Nov 14th 2011
======================
* Back and forth, back and forth: now settled on keeping the api (event names, methods) closer to the websocket browser api. This will stick now.
* Started keeping this history record. Better late than never, right?

+ 38
- 0
node_modules/auto-reload-brunch/node_modules/ws/Makefile View File

@ -0,0 +1,38 @@
ALL_TESTS = $(shell find test/ -name '*.test.js')
ALL_INTEGRATION = $(shell find test/ -name '*.integration.js')
all:
node-gyp configure build
clean:
node-gyp clean
run-tests:
@./node_modules/.bin/mocha \
-t 2000 \
$(TESTFLAGS) \
$(TESTS)
run-integrationtests:
@./node_modules/.bin/mocha \
-t 5000 \
$(TESTFLAGS) \
$(TESTS)
test:
@$(MAKE) NODE_PATH=lib TESTS="$(ALL_TESTS)" run-tests
integrationtest:
@$(MAKE) NODE_PATH=lib TESTS="$(ALL_INTEGRATION)" run-integrationtests
benchmark:
@node bench/sender.benchmark.js
@node bench/parser.benchmark.js
autobahn:
@NODE_PATH=lib node test/autobahn.js
autobahn-server:
@NODE_PATH=lib node test/autobahn-server.js
.PHONY: test

+ 159
- 0
node_modules/auto-reload-brunch/node_modules/ws/README.md View File

@ -0,0 +1,159 @@
[![Build Status](https://secure.travis-ci.org/einaros/ws.png)](http://travis-ci.org/einaros/ws)
# ws: a node.js websocket library #
`ws` is a simple to use websocket implementation, up-to-date against RFC-6455, and [probably the fastest WebSocket library for node.js](http://hobbycoding.posterous.com/the-fastest-websocket-module-for-nodejs).
Passes the quite extensive Autobahn test suite. See http://einaros.github.com/ws for the full reports.
Comes with a command line utility, `wscat`, which can either act as a server (--listen), or client (--connect); Use it to debug simple websocket services.
## Protocol support ##
* **Hixie draft 76** (Old and deprecated, but still in use by Safari and Opera. Added to ws version 0.4.2, but server only. Can be disabled by setting the `disableHixie` option to true.)
* **HyBi drafts 07-12** (Use the option `protocolVersion: 8`, or argument `-p 8` for wscat)
* **HyBi drafts 13-17** (Current default, alternatively option `protocolVersion: 13`, or argument `-p 13` for wscat)
_See the echo.websocket.org example below for how to use the `protocolVersion` option._
## Usage ##
### Installing ###
`npm install ws`
### Sending and receiving text data ###
```js
var WebSocket = require('ws');
var ws = new WebSocket('ws://www.host.com/path');
ws.on('open', function() {
ws.send('something');
});
ws.on('message', function(data, flags) {
// flags.binary will be set if a binary data is received
// flags.masked will be set if the data was masked
});
```
### Sending binary data ###
```js
var WebSocket = require('ws');
var ws = new WebSocket('ws://www.host.com/path');
ws.on('open', function() {
var array = new Float32Array(5);
for (var i = 0; i < array.length; ++i) array[i] = i / 2;
ws.send(array, {binary: true, mask: true});
});
```
Setting `mask`, as done for the send options above, will cause the data to be masked according to the websocket protocol. The same option applies for text data.
### Server example ###
```js
var WebSocketServer = require('ws').Server
, wss = new WebSocketServer({port: 8080});
wss.on('connection', function(ws) {
ws.on('message', function(message) {
console.log('received: %s', message);
});
ws.send('something');
});
```
### Error handling best practices ###
```js
// If the WebSocket is closed before the following send is attempted
ws.send('something');
// Errors (both immediate and async write errors) can be detected in an optional callback.
// The callback is also the only way of being notified that data has actually been sent.
ws.send('something', function(error) {
// if error is null, the send has been completed,
// otherwise the error object will indicate what failed.
});
// Immediate errors can also be handled with try/catch-blocks, but **note**
// that since sends are inherently asynchronous, socket write failures will *not*
// be captured when this technique is used.
try {
ws.send('something');
}
catch (e) {
// handle error
}
```
### echo.websocket.org demo ###
```js
var WebSocket = require('ws');
var ws = new WebSocket('ws://echo.websocket.org/', {protocolVersion: 8, origin: 'http://websocket.org'});
ws.on('open', function() {
console.log('connected');
ws.send(Date.now().toString(), {mask: true});
});
ws.on('close', function() {
console.log('disconnected');
});
ws.on('message', function(data, flags) {
console.log('Roundtrip time: ' + (Date.now() - parseInt(data)) + 'ms', flags);
setTimeout(function() {
ws.send(Date.now().toString(), {mask: true});
}, 500);
});
```
### wscat against echo.websocket.org ###
$ npm install -g ws
$ wscat -c ws://echo.websocket.org -p 8
connected (press CTRL+C to quit)
> hi there
< hi there
> are you a happy parrot?
< are you a happy parrot?
### Other examples ###
For a full example with a browser client communicating with a ws server, see the examples folder.
Note that the usage together with Express 3.0 is quite different from Express 2.x. The difference is expressed in the two different serverstats-examples.
Otherwise, see the test cases.
### Running the tests ###
`make test`
## API Docs ##
See the doc/ directory for Node.js-like docs for the ws classes.
## License ##
(The MIT License)
Copyright (c) 2011 Einar Otto Stangvik &lt;einaros@gmail.com&gt;
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.

+ 115
- 0
node_modules/auto-reload-brunch/node_modules/ws/bench/parser.benchmark.js View File

@ -0,0 +1,115 @@
/*!
* ws: a node.js websocket client
* Copyright(c) 2011 Einar Otto Stangvik <einaros@gmail.com>
* MIT Licensed
*/
/**
* Benchmark dependencies.
*/
var benchmark = require('benchmark')
, Receiver = require('../').Receiver
, suite = new benchmark.Suite('Receiver');
require('tinycolor');
require('./util');
/**
* Setup receiver.
*/
suite.on('start', function () {
receiver = new Receiver();
});
suite.on('cycle', function () {
receiver = new Receiver();
});
/**
* Benchmarks.
*/
var pingMessage = 'Hello'
, pingPacket1 = getBufferFromHexString('89 ' + (pack(2, 0x80 | pingMessage.length)) +
' 34 83 a8 68 '+ getHexStringFromBuffer(mask(pingMessage, '34 83 a8 68')));
suite.add('ping message', function () {
receiver.add(pingPacket1);
});
var pingPacket2 = getBufferFromHexString('89 00')
suite.add('ping with no data', function () {
receiver.add(pingPacket2);
});
var closePacket = getBufferFromHexString('88 00');
suite.add('close message', function () {
receiver.add(closePacket);
receiver.endPacket();
});
var maskedTextPacket = getBufferFromHexString('81 93 34 83 a8 68 01 b9 92 52 4f a1 c6 09 59 e6 8a 52 16 e6 cb 00 5b a1 d5');
suite.add('masked text message', function () {
receiver.add(maskedTextPacket);
});
binaryDataPacket = (function() {
var length = 125
, message = new Buffer(length)
for (var i = 0; i < length; ++i) message[i] = i % 10;
return getBufferFromHexString('82 ' + getHybiLengthAsHexString(length, true) + ' 34 83 a8 68 '
+ getHexStringFromBuffer(mask(message), '34 83 a8 68'));
})();
suite.add('binary data (125 bytes)', function () {
try {
receiver.add(binaryDataPacket);
}
catch(e) {console.log(e)}
});
binaryDataPacket2 = (function() {
var length = 65535
, message = new Buffer(length)
for (var i = 0; i < length; ++i) message[i] = i % 10;
return getBufferFromHexString('82 ' + getHybiLengthAsHexString(length, true) + ' 34 83 a8 68 '
+ getHexStringFromBuffer(mask(message), '34 83 a8 68'));
})();
suite.add('binary data (65535 bytes)', function () {
receiver.add(binaryDataPacket2);
});
binaryDataPacket3 = (function() {
var length = 200*1024
, message = new Buffer(length)
for (var i = 0; i < length; ++i) message[i] = i % 10;
return getBufferFromHexString('82 ' + getHybiLengthAsHexString(length, true) + ' 34 83 a8 68 '
+ getHexStringFromBuffer(mask(message), '34 83 a8 68'));
})();
suite.add('binary data (200 kB)', function () {
receiver.add(binaryDataPacket3);
});
/**
* Output progress.
*/
suite.on('cycle', function (bench, details) {
console.log('\n ' + suite.name.grey, details.name.white.bold);
console.log(' ' + [
details.hz.toFixed(2).cyan + ' ops/sec'.grey
, details.count.toString().white + ' times executed'.grey
, 'benchmark took '.grey + details.times.elapsed.toString().white + ' sec.'.grey
,
].join(', '.grey));
});
/**
* Run/export benchmarks.
*/
if (!module.parent) {
suite.run();
} else {
module.exports = suite;
}

+ 66
- 0
node_modules/auto-reload-brunch/node_modules/ws/bench/sender.benchmark.js View File

@ -0,0 +1,66 @@
/*!
* ws: a node.js websocket client
* Copyright(c) 2011 Einar Otto Stangvik <einaros@gmail.com>
* MIT Licensed
*/
/**
* Benchmark dependencies.
*/
var benchmark = require('benchmark')
, Sender = require('../').Sender
, suite = new benchmark.Suite('Sender');
require('tinycolor');
require('./util');
/**
* Setup sender.
*/
suite.on('start', function () {
sender = new Sender();
sender._socket = { write: function() {} };
});
suite.on('cycle', function () {
sender = new Sender();
sender._socket = { write: function() {} };
});
/**
* Benchmarks
*/
framePacket = new Buffer(200*1024);
framePacket.fill(99);
suite.add('frameAndSend, unmasked (200 kB)', function () {
sender.frameAndSend(0x2, framePacket, true, false);
});
suite.add('frameAndSend, masked (200 kB)', function () {
sender.frameAndSend(0x2, framePacket, true, true);
});
/**
* Output progress.
*/
suite.on('cycle', function (bench, details) {
console.log('\n ' + suite.name.grey, details.name.white.bold);
console.log(' ' + [
details.hz.toFixed(2).cyan + ' ops/sec'.grey
, details.count.toString().white + ' times executed'.grey
, 'benchmark took '.grey + details.times.elapsed.toString().white + ' sec.'.grey
,
].join(', '.grey));
});
/**
* Run/export benchmarks.
*/
if (!module.parent) {
suite.run();
} else {
module.exports = suite;
}

+ 105
- 0
node_modules/auto-reload-brunch/node_modules/ws/bench/speed.js View File

@ -0,0 +1,105 @@
var cluster = require('cluster')
, WebSocket = require('../')
, WebSocketServer = WebSocket.Server
, crypto = require('crypto')
, util = require('util')
, ansi = require('ansi');
require('tinycolor');
function roundPrec(num, prec) {
var mul = Math.pow(10, prec);
return Math.round(num * mul) / mul;
}
function humanSize(bytes) {
if (bytes >= 1048576) return roundPrec(bytes / 1048576, 2) + ' MB';
if (bytes >= 1024) return roundPrec(bytes / 1024, 2) + ' kB';
return roundPrec(bytes, 2) + ' B';
}
function generateRandomData(size) {
var buffer = new Buffer(size);
for (var i = 0; i < size; ++i) {
buffer[i] = ~~(Math.random() * 127);
}
return buffer;
}
if (cluster.isMaster) {
var wss = new WebSocketServer({port: 8181}, function() {
cluster.fork();
});
wss.on('connection', function(ws) {
ws.on('message', function(data, flags) {
ws.send(data, {binary: flags&&flags.binary});
});
ws.on('close', function() {});
});
cluster.on('death', function(worker) {
wss.close();
});
}
else {
var cursor = ansi(process.stdout);
var configs = [
[true, 10000, 64],
[true, 5000, 16*1024],
[true, 1000, 128*1024],
[true, 100, 1024*1024],
[true, 1, 500*1024*1024],
[false, 10000, 64],
[false, 5000, 16*1024],
[false, 1000, 128*1024],
[false, 100, 1024*1024],
];
var largest = configs[0][1];
for (var i = 0, l = configs.length; i < l; ++i) {
if (configs[i][2] > largest) largest = configs[i][2];
}
console.log('Generating %s of test data ...', humanSize(largest));
var randomBytes = generateRandomData(largest);
function roundtrip(useBinary, roundtrips, size, cb) {
var data = randomBytes.slice(0, size);
var prefix = util.format('Running %d roundtrips of %s %s data', roundtrips, humanSize(size), useBinary ? 'binary' : 'text');