Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mikekelly committed May 30, 2012
0 parents commit abaf8f8
Show file tree
Hide file tree
Showing 20 changed files with 20,070 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Cakefile
@@ -0,0 +1,10 @@
{print} = require 'util'
{exec} = require 'child_process'

compile = () ->
coffee = exec 'coffee --compile --output ./ ./lib/'
coffee.stdout.on 'data', (data) -> print data.toString()
coffee.stderr.on 'data', (data) -> print data.toString()

task 'compile', 'compile coffeescripts', ->
compile()
20 changes: 20 additions & 0 deletions LICENSE
@@ -0,0 +1,20 @@
Copyright (c) 2012 Mike Kelly, http://stateless.co/

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.
9 changes: 9 additions & 0 deletions README.md
@@ -0,0 +1,9 @@
Backbone.Hypermedia
===================

Replacement Model and Collection components which interop with the media type application/hal+json

Examples
========

TODO
58 changes: 58 additions & 0 deletions SpecRunner.html
@@ -0,0 +1,58 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Jasmine Spec Runner</title>

<link rel="shortcut icon" type="image/png" href="vendor/jasmine-1.2.0/jasmine_favicon.png">
<link rel="stylesheet" type="text/css" href="vendor/jasmine-1.2.0/jasmine.css">
<script type="text/javascript" src="vendor/jasmine-1.2.0/jasmine.js"></script>
<script type="text/javascript" src="vendor/jasmine-1.2.0/jasmine-html.js"></script>
<script type="text/javascript" src="vendor/sinon-1.3.4.js"></script>
<script type="text/javascript" src="vendor/jasmine-sinon.js"></script>

<script type="text/javascript" src="vendor/jquery-1.7.2.js"></script>
<script type="text/javascript" src="vendor/underscore.js"></script>
<script type="text/javascript" src="vendor/json2.js"></script>
<script type="text/javascript" src="vendor/backbone.js"></script>
<script type="text/javascript" src="vendor/backbone.js"></script>

<script type="text/javascript" src="spec/model_spec.js"></script>
<script type="text/javascript" src="spec/collection_spec.js"></script>

<script type="text/javascript" src="backbone.hypermedia.js"></script>

<script type="text/javascript">
(function() {
var jasmineEnv = jasmine.getEnv();
jasmineEnv.updateInterval = 1000;

var htmlReporter = new jasmine.HtmlReporter();

jasmineEnv.addReporter(htmlReporter);

jasmineEnv.specFilter = function(spec) {
return htmlReporter.specFilter(spec);
};

var currentWindowOnload = window.onload;

window.onload = function() {
if (currentWindowOnload) {
currentWindowOnload();
}
execJasmine();
};

function execJasmine() {
jasmineEnv.execute();
}

})();
</script>

</head>

<body>
</body>
</html>
78 changes: 78 additions & 0 deletions backbone.hypermedia.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 42 additions & 0 deletions lib/backbone.hypermedia.coffee
@@ -0,0 +1,42 @@
window.HAL = {}

class HAL.Model extends Backbone.Model
constructor: (attrs) ->
super @parse(_.clone attrs)

parse: (attrs = {}) ->
@links = attrs._links || {}
delete attrs._links
@embedded = attrs._embedded || {}
delete attrs._embedded

return attrs

url: ->
@links?.self?.href || super()

class HAL.Collection extends Backbone.Collection
constructor: (obj, options) ->
super @parse(_.clone obj), options

parse: (obj = {}) ->
@links = obj._links || {}
delete obj._links
@embedded = obj._embedded || {}
delete obj._embedded
@attributes = obj || {}

if @itemRel?
items = @embedded[@itemRel]
else
items = @embedded.items

return items

reset: (obj, options) ->
# skip parsing if obj is an Array (i.e. reset items only)
obj = @parse(_.clone obj) if not _.isArray(obj)
return super(obj, options)

url: ->
@links?.self?.href

0 comments on commit abaf8f8

Please sign in to comment.