Permalink
Browse files

Internal class access

One can now access internal scope classes for extending functionality to Collection+JSON
  • Loading branch information...
1 parent 35d1646 commit 82e070592b5368f69e9588626458925b214172ab @camshaft camshaft committed Sep 30, 2012
Showing with 45 additions and 66 deletions.
  1. +0 −28 lib/collection.coffee
  2. +44 −5 lib/index.coffee
  3. +0 −12 lib/item.coffee
  4. +0 −11 lib/query.coffee
  5. +0 −9 lib/template.coffee
  6. +1 −1 package.json
View
@@ -1,28 +0,0 @@
-Item = require "./item"
-Query = require "./query"
-Template = require "./template"
-
-class Collection
- constructor: (@_collection)->
- error: (options)->
- @_collection.error = options
- href: (value)->
- @_collection.href = value
- link: (options)->
- @_collection.links ||= []
- @_collection.links.push options
- item: (itemFun)->
- item = {}
- @_collection.items ||= []
- @_collection.items.push item
- itemFun.call new Item(item)
- query: (queryFun)->
- query = {}
- @_collection.queries ||= []
- @_collection.queries.push query
- queryFun.call new Query(query)
- template: (templateFun)->
- @_collection.template = {}
- templateFun.call new Template(@_collection.template)
-
-module.exports = Collection
View
@@ -1,10 +1,49 @@
-cscj = require("coffee-dsl").dsl()
-Collection = require "./collection"
+module.exports = require("coffee-dsl").dsl()
-cscj.set "collection", (collectionFun)->
+module.exports.set "collection", (collectionFun)->
collection = {version:"1.0"}
root = {collection:collection}
- collectionFun.call new Collection(collection)
+ collectionFun.call new exports.Collection(collection)
root
-module.exports = cscj
+exports.Base = class Base
+ constructor: (@_obj) ->
+ href: (value)->
+ @_obj.href = value
+
+exports.Data = class Data extends exports.Base
+ datum: (options)->
+ @_obj.data ||= []
+ @_obj.data.push options
+
+# expose internal objects for extensions
+exports.Collection = class Collection extends Base
+ error: (options)->
+ @_obj.error = options
+ link: (options)->
+ @_obj.links ||= []
+ @_obj.links.push options
+ item: (itemFun)->
+ item = {}
+ @_obj.items ||= []
+ @_obj.items.push item
+ itemFun.call new exports.Item(item)
+ query: (queryFun)->
+ query = {}
+ @_obj.queries ||= []
+ @_obj.queries.push query
+ queryFun.call new exports.Query(query)
+ template: (templateFun)->
+ @_obj.template = {}
+ templateFun.call new exports.Template(@_obj.template)
+
+exports.Item = class Item extends exports.Data
+ link: (options)->
+ @_obj.links ||= []
+ @_obj.links.push options
+
+exports.Query = class Query extends exports.Data
+ rel: (value)->
+ @_obj.rel = value
+
+exports.Template = class Template extends exports.Data
View
@@ -1,12 +0,0 @@
-class Item
- constructor: (@_item)->
- href: (value)->
- @_item.href = value
- link: (options)->
- @_item.links ||= []
- @_item.links.push options
- datum: (options)->
- @_item.data ||= []
- @_item.data.push options
-
-module.exports = Item
View
@@ -1,11 +0,0 @@
-class Query
- constructor: (@_query) ->
- href: (value)->
- @_query.href = value
- rel: (value)->
- @_query.rel = value
- datum: (options)->
- @_query.data ||= []
- @_query.data.push options
-
-module.exports = Query
View
@@ -1,9 +0,0 @@
-class Template
- constructor: (@_template) ->
- href: (value)->
- @_template.href = value
- datum: (options)->
- @_template.data ||= []
- @_template.data.push options
-
-module.exports = Template
View
@@ -1,6 +1,6 @@
{
"name": "cscj",
- "version": "0.0.0",
+ "version": "0.0.1",
"description": "Collection+JSON Views in CoffeeScript",
"main": "index.js",
"directories": {

0 comments on commit 82e0705

Please sign in to comment.