Permalink
Browse files

say hi to hoodie!

  • Loading branch information...
0 parents commit bf4865347b1a5eb969d1b645447f5db4d7ca1d6d @gr2m gr2m committed May 19, 2012
Showing with 10,749 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +65 −0 Cakefile
  3. +505 −0 LICENSE
  4. +246 −0 README.md
  5. +7 −0 TODO.md
  6. +138 −0 compiled/src/account.js
  7. +60 −0 compiled/src/email.js
  8. +18 −0 compiled/src/errors.js
  9. +79 −0 compiled/src/events.js
  10. +44 −0 compiled/src/hoodie.js
  11. +248 −0 compiled/src/remote.js
  12. +396 −0 compiled/src/store.js
  13. +62 −0 compiled/test/lib/jasmine-helpers.js
  14. +86 −0 compiled/test/lib/phantomjs_test_runner.js
  15. +17 −0 compiled/test/mocks/bulk_update_response.mock.js
  16. +27 −0 compiled/test/mocks/changed_docs.mock.js
  17. +25 −0 compiled/test/mocks/changes_response.mock.js
  18. +62 −0 compiled/test/mocks/hoodie.mock.js
  19. +340 −0 compiled/test/specs/account.spec.js
  20. +101 −0 compiled/test/specs/email.spec.js
  21. +80 −0 compiled/test/specs/events.spec.js
  22. +65 −0 compiled/test/specs/hoodie.spec.js
  23. +294 −0 compiled/test/specs/remote.spec.js
  24. +809 −0 compiled/test/specs/store.spec.js
  25. +118 −0 docs/account.html
  26. +189 −0 docs/docco.css
  27. +40 −0 docs/email.html
  28. +14 −0 docs/errors.html
  29. +76 −0 docs/events.html
  30. +32 −0 docs/hoodie.html
  31. +192 −0 docs/remote.html
  32. +86 −0 docs/share.html
  33. +333 −0 docs/store.html
  34. +1 −0 hoodie.min.js
  35. +168 −0 index.html
  36. +171 −0 src/account.coffee
  37. +52 −0 src/email.coffee
  38. +27 −0 src/errors.coffee
  39. +92 −0 src/events.coffee
  40. +45 −0 src/hoodie.coffee
  41. +259 −0 src/remote.coffee
  42. +420 −0 src/store.coffee
  43. +62 −0 test/index.html
  44. +20 −0 test/lib/jasmine-1.1.0/MIT.LICENSE
  45. +190 −0 test/lib/jasmine-1.1.0/jasmine-html.js
  46. +166 −0 test/lib/jasmine-1.1.0/jasmine.css
  47. +2,476 −0 test/lib/jasmine-1.1.0/jasmine.js
  48. BIN test/lib/jasmine-1.1.0/jasmine_favicon.png
  49. +55 −0 test/lib/jasmine-helpers.coffee
  50. +77 −0 test/lib/phantomjs_test_runner.coffee
  51. +14 −0 test/mocks/bulk_update_response.mock.coffee
  52. +24 −0 test/mocks/changed_docs.mock.coffee
  53. +20 −0 test/mocks/changes_response.mock.coffee
  54. +27 −0 test/mocks/hoodie.mock.coffee
  55. +287 −0 test/specs/account.spec.coffee
  56. +89 −0 test/specs/email.spec.coffee
  57. +68 −0 test/specs/events.spec.coffee
  58. +53 −0 test/specs/hoodie.spec.coffee
  59. +241 −0 test/specs/remote.spec.coffee
  60. +621 −0 test/specs/store.spec.coffee
  61. +4 −0 vendor/jquery-1.7.2.min.js
  62. +33 −0 vendor/require-1.0.7.js
  63. +1 −0 wishlist/README.md
  64. +131 −0 wishlist/src/share.js
@@ -0,0 +1 @@
+.DS_STORE
@@ -0,0 +1,65 @@
+fs = require 'fs'
+{print} = require 'util'
+{spawn, exec} = require 'child_process'
+
+timeout = null
+build = (callback, watch = false) ->
+ if watch
+ coffee = spawn 'coffee', ['-c', '-b', '-o', 'compiled', '-w', '.']
+ else
+ coffee = spawn 'coffee', ['-c', '-b', '-o', 'compiled', '.']
+
+ coffee.stderr.on 'data', (data) ->
+ process.stderr.write data.toString()
+ coffee.stdout.on 'data', (data) ->
+ print data.toString()
+
+ if callback and watch
+ clearTimeout timeout
+ timeout = setTimeout callback, 100
+
+ coffee.on 'exit', (code) ->
+ callback?() if code is 0
+
+test = ->
+ phantom = spawn 'phantomjs', ['test/lib/phantomjs_test_runner.coffee', 'test/index.html']
+
+ phantom.stderr.on 'data', (data) ->
+ process.stderr.write data.toString()
+ phantom.stdout.on 'data', (data) ->
+ print data.toString()
+
+task 'compile', 'Build lib/', ->
+ build()
+
+task 'watch', 'Build lib/ and watch for changes', ->
+ build(null, true)
+
+task 'test', 'test', ->
+ test()
+
+task 'autotest', 'autotest', ->
+ build( test, true)
+
+task 'build', 'build hoodie-client.min.js', ->
+ build = spawn 'r.js', ['-o', 'name=hoodie', 'baseUrl=./compiled/src', 'paths.requireLib=../../vendor/require-1.0.7', 'include=requireLib', 'out=hoodie.min.js']
+ build.stdout.on 'data', (data) -> print data.toString()
+ # build.stderr.on 'data', (data) -> print data.toString()
+ build.on 'exit', (status) -> callback?() if status is 0
+
+task 'docs', 'create docs from code', ->
+
+
+ fs.readdir 'src', (err, contents) ->
+ files = []
+ files = ("src/#{file}" for file in contents when /\.coffee$/.test file)
+
+ console.log files
+ docco = spawn 'docco', files
+ docco.stdout.on 'data', (data) -> print data.toString()
+ # docco.stderr.on 'data', (data) -> print data.toString()
+ docco.on 'exit', (status) -> callback?() if status is 0
+
+task 'all', 'one cake to rule them all', ->
+ exec 'cake compile && cake build && cake docs', (err) ->
+ throw err if err
505 LICENSE

Large diffs are not rendered by default.

Oops, something went wrong.
246 README.md
@@ -0,0 +1,246 @@
+API
+===
+
+
+Setup
+-----
+
+```javascript
+Hoodie = require('hoodie')
+couchDB_endpoint = 'http://worlddominatorapp.iriscouch.com';
+app = new Hoodie(couchDB_endpoint);
+```
+
+
+Accounts / Sessions
+-------------------
+
+
+### Sign Up
+
+```javascript
+app.account.sign_up('joe@example.com', 'secret')
+
+ .done( function(user) {
+ user.email // 'joe@example.com'
+ user.uuid // auto generated
+
+ // data sync kicks in
+ } )
+
+ // signup error
+ .fail( function(err) {
+ alert("Oops: " + err.message)
+ } )
+```
+
+
+### Sign In
+
+```javascript
+app.account.sign_in('joe@example.com', 'secret')
+
+ .done( function(user) {
+ // data sync kicks in
+ } )
+ .fail( function(err) {
+ alert("Oops: " + err.message)
+ } )
+```
+
+### Change password
+
+```javascript
+app.account.change_password('current_secret', 'new_secret')
+
+ .done( function(user) { } )
+ .fail( function(err) { } )
+```
+
+### Sign Out
+
+```javascript
+app.account.sign_out()
+
+ .done( function() {
+ // session ends, local data gets cleaned up
+ } )
+ .fail( function(err) {
+ alert("Oops: " + err.message)
+ } )
+```
+
+
+### Forgot Password
+
+```javascript
+app.account.forgot_password('joe@example.com')
+
+ .done( function() {
+ alert( "Link has been sent to joe@example.com")
+ } )
+ .fail( function(err) {
+ alert("Oops: " + err.message)
+ } )
+```
+
+
+Data Storage / Sync
+-------------------
+
+### uuid
+
+helper to generate unique IDs that you can use to store your objects.
+
+```javascript
+uuid = app.store.uuid(length)
+```
+
+
+### Create / Update
+
+create or update an object.
+
+```javascript
+// create a new object
+type = 'rule'
+app.store.create( type, {name: "rule the world"} )
+
+ .done ( function(new_object) { } )
+ .fail ( function(err) { } )
+
+// save an object
+id = 'abc4567'
+type = 'rule'
+app.store.save( type, id, {name: "rule the world"} )
+
+ .done ( function(object) { } )
+ .fail ( function(err) { } )
+
+// update an existing object
+id = 'abc4567'
+type = 'rule'
+app.store.update( type, id, {nr: 1} )
+
+ .done ( function(updated_object) { } )
+ .fail ( function(err) { } )
+```
+
+
+### Load
+
+load an existing object
+
+```javascript
+app.store.load( type, id )
+
+ .done ( function(object) { } )
+ .fail ( function(err) { } )
+```
+
+
+### Load all
+
+load all objects available or from a specific type
+
+```javascript
+app.store.loadAll( type )
+
+ .done ( function(objects) { } )
+ .fail ( function(err) { } )
+```
+
+
+### Delete
+
+delete an existing object
+
+```javascript
+app.store.delete( type, id )
+
+ .done ( function(deleted_object) { } )
+ .fail ( function(err) { } )
+```
+
+
+### Remote Updates
+
+subscribe to changes from remote
+
+```javascript
+// new doc created
+app.remote.on( 'created', function( type, id, created_object) { } )
+
+// existing doc updated
+app.remote.on( 'updated', function( type, id, updated_object) { } )
+
+// doc deleted
+app.remote.on( 'deleted', function( type, id, deleted_object) { } )
+
+// any of above events
+app.remote.on( 'changed', function( type, id, changed_object) { } )
+
+// all listeners can be filtered by type
+app.remote.on( "created:couch", function( id, created_object) { } )
+app.remote.on( "updated:couch", function( id, updated_object) { } )
+app.remote.on( "deleted:couch", function( id, deleted_object) { } )
+app.remote.on( "changed:couch", function( id, changed_object) { } )
+```
+
+
+Send E-Mails
+------------
+
+hell, yeah!
+
+```javascript
+email = {
+ to : ['susan@example.com'],
+ cc : ['bill@example.com'],
+ subject : 'rule the world',
+ body : "we can do it!\nSigned, Joe"
+}
+
+app.email.send( email )
+
+ // synched to server
+ .progress ( function(email) { } )
+
+ // email sent successfully
+ .done ( function(email) { } )
+
+ // something went wrong
+ .fail ( function(err) { } )
+```
+
+
+Future Ideas
+------------
+
+* sharing
+* searching
+* payments
+* file conversion
+* ... ?
+
+
+Dependencies
+------------
+
+Hoodie depends on and [require.js](http://requirejs.org).
+It currently also depends on jQuery/[zepto](http://zeptojs.com/), but we will remove the dependance soon.
+
+
+Contribute
+==========
+
+When you feel like contributing, I highly recommend to install [PhantomJS](http://www.phantomjs.org/) for automated, headless testing. Run `$ cake autotest` to have test running in the background while hacking.
+
+When you're done with changes, make sure to run `$ r.js -o name=hoodie baseUrl=./compiled out=hoodie.min.js` to update the concatenated & minified js file for production use.
+
+
+License & Copyright
+===================
+
+(c) 2012 Gregor Martynus <g@minutes.io>
+Licensed under the Apache License 2.0.
@@ -0,0 +1,7 @@
+* add restriction: sign up only with valid email
+* remove dependency on jQuery / zepto.js, then uncomment `use strict` statements
+
+### Account
+
+* what if @email is different from what GET /_session returns? Can there be a case like that?
+* before sign in / sign out: sign out if `_couch.account.email` is a different email address
Oops, something went wrong.

0 comments on commit bf48653

Please sign in to comment.