Skip to content

Commit

Permalink
License and readme
Browse files Browse the repository at this point in the history
  • Loading branch information
xdissent committed Jul 15, 2013
1 parent a342c8b commit b504d1b
Show file tree
Hide file tree
Showing 3 changed files with 187 additions and 1 deletion.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2013 Greg Thornton

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.
161 changes: 161 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
spinnaker
=========

[Sails](http://sailsjs.org) Resources Service for
[AngularJS](http://angularjs.org)

Sails is realtime web framework for [Node](http://nodejs.org) built on
[express](http://expressjs.com) and [socket.io](http://socket.io). AngularJS is
a super heroic Javascript framework that makes advanced UIs with automatic
data binding a snap. Spinnaker is an
[Angular Service](http://docs.angularjs.org/guide/dev_guide.services.understanding_services)
that talks to Sails, modeled after the official
[ngResource](http://docs.angularjs.org/api/ngResource.$resource) module. Rather
than communicating with HTTP requests, spinnaker sends and receives realtime
messages over socket.io. Thanks to Sails' realtime model updates and Angular's
[two-way data binding](http://docs.angularjs.org/guide/dev_guide.templates.databinding),
you can query Sails resources like with `$resource`, and the models will be
updated automatically when the data changes in the backend. If Sails is
configured to use the `redis` pubsub adapter, you AngularJS frontend can be
updated live from completely separate server processes.


Installation
------------

[Bower](http://bower.io) is the preferred installation method. Install bower
via npm:

```sh
$ sudo npm install bower -g
```


Install spinnaker via bower:

```sh
$ bower install spinnaker --save
```


Building from git is also easy:

```sh
$ git clone https://github.com/xdissent/spinnaker.git
$ cd spinnaker
$ npm install
```


The `lib` folder will contain the build artifacts.


Usage
-----

Install Sails 0.9 and create a new app with a model:

```sh
$ sudo npm install 'git+https://github.com/balderdashy/sails#development' -g
$ sails new example --linker
$ cd example
```


Install spinnaker and dependencies into the Sails linker folder:

```sh
$ echo '{"directory": "assets/js/components"}' > .bowerrc
$ bower install spinnaker --save
```


Generate a Sails model:

```sh
$ sails generate widget
```


Add spinnaker and its dependencies to your layout:

```ejs
<!-- example/views/layout.ejs -->
<!-- ... snip ... -->
<script src="/js/components/angular-unstable/angular.js"></script>
<script src="/js/components/angular-resource-master/angular-resource.js"></script>
<script src="/js/components/spinnaker/lib/spinnaker.js"></script>
<!--SCRIPTS-->
<!--SCRIPTS END-->
</body>
</html>
```


Create an angular app at `example/assets/linker/js/app.js`:

```js
var WidgetListCtrl = function ($scope, Widget) {
// Use the spinnaker service to query for all Widgets.
$scope.widgets = Widget.query();

// Create a widget.
$scope.create = function () {
var widget = new Widget({});
widget.$save();
// Or create via $http:
// $http.post('/widget', {});
};

// Update a widget.
$scope.update = function (widget) {
widget.$update({});
// Or update via $http:
// $http.put('/widget/' + widget.id, widget);
};

// Delete a widget.
$scope.destroy = function (widget) {
widget.$remove();
// Or destroy via $http:
// $http['delete']('/widget/' + widget.id, widget);
};
};

WidgetListCtrl.$inject = ['$scope', 'Widget'];

angular.module('widgetService', ['spinnaker'])
.factory('Widget', ['spinnaker' , function (spinnaker) {
return spinnaker('widget');
}]);

angular.module('app', ['widgetService'])
.controller('WidgetListCtrl', WidgetListCtrl);
```


Finally create a view for your app in `example/views/home/index.ejs`:

```ejs
<div ng-app="app" ng-controller="WidgetListCtrl">
<button ng-click="create()">Create Widget</button>
<ul>
<li ng-repeat="widget in widgets">
<pre>{{ widget }}</pre>
<button ng-click="update(widget)">Update Widget</button>
<button ng-click="destroy(widget)">Destroy Widget</button>
</li>
</ul>
</div>
```


Start the Sails server and visit `http://localhost:1337`:

```sh
$ sails lift
```

6 changes: 5 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
"bower_components",
"test",
"tests",
"src"
"src",
"Gruntfile.coffee",
"karma.*",
"libpeerconnection.log",
"package.json"
],
"dependencies": {
"angular-resource-master": "latest"
Expand Down

0 comments on commit b504d1b

Please sign in to comment.