Permalink
Browse files

Initial commit of first prototype.

  • Loading branch information...
Brandon R. Stoner
Brandon R. Stoner committed Jun 21, 2012
1 parent 18de672 commit 4442cf0fb0ee3557ffa914fc3b8792c75d74b4e5
Showing with 62 additions and 2 deletions.
  1. +1 −1 src/Makefile
  2. +29 −0 src/bone.coffee
  3. +14 −0 src/collections.coffee
  4. +0 −1 src/main.coffee
  5. +18 −0 src/models.coffee
  6. 0 tastybone/__init__.py
View
@@ -10,7 +10,7 @@ base_filename = $(output_directory)/tastybone
output_filename = $(call append_extension,$(base_filename),js)
output_filename_minified = $(call append_extension,$(base_filename),min.js)
-objects = $(patsubst %.coffee,%.js,$(wildcard *.coffee))
+objects = bone.js models.js collections.js test.js
all: $(output_filename_minified)
View
@@ -0,0 +1,29 @@
+window.TastyBone = {}
+TastyBone = window.TastyBone
+
+class Bone
+ collections: {}
+
+ constructor: (@original_url, options) ->
+ # TODO: Implement authentication options.
+
+ _.extend @, Backbone.Events
+
+ options = options or {}
+
+ jQuery.get @original_url, options, (endpoints) =>
+ _.each endpoints, (endpoint, name) =>
+ if name[0] == '_' then return
+
+ capitalizedName = name[0].toUpperCase() + name.slice(1)
+ model = TastyBone.Model.factory endpoint.list_endpoint, @
+
+ next_collection = TastyBone.Collection.factory model,
+ endpoint.list_endpoint
+
+ @collections[capitalizedName + 'Collection'] = next_collection
+
+ @.trigger 'ready', @
+
+TastyBone.Bone = Bone
+
View
@@ -0,0 +1,14 @@
+class TastyPieCollection extends Backbone.Collection
+ parse: (data) ->
+ if data? and data.meta?
+ @meta = data.meta
+
+ data.objects or data
+
+ @factory = (model, endpoint) ->
+ class AutoTastyPieCollection extends TastyPieCollection
+ model: model
+ url: endpoint
+
+window.TastyBone.Collection = TastyPieCollection
+
View
@@ -1 +0,0 @@
-
View
@@ -0,0 +1,18 @@
+class TastyPieModel extends Backbone.Model
+ url: ->
+ # It seems that TastyPie really likes leading slahes. This is a bad thing.
+ url = Backbone.Model.prototype.url.call @
+
+ if url[url.length-1] != '/'
+ url = url + '/'
+
+ url
+
+ @factory: (endpoint, bone) ->
+ # Creates a nested class which accesses the given endpoint. I know. It's weird.
+ class AutoTastyPieModel extends TastyPieModel
+ initialize: ->
+ @urlRoot = endpoint
+
+window.TastyBone.Model = TastyPieModel
+
View
No changes.

0 comments on commit 4442cf0

Please sign in to comment.