Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Initial commit of first prototype.

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

0 notes on commit 4442cf0

Please sign in to comment.
Something went wrong with that request. Please try again.