Skip to content

Commit

Permalink
Internal class access
Browse files Browse the repository at this point in the history
One can now access internal scope classes for extending functionality to Collection+JSON
  • Loading branch information
camshaft committed Sep 30, 2012
1 parent 35d1646 commit 82e0705
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 66 deletions.
28 changes: 0 additions & 28 deletions lib/collection.coffee

This file was deleted.

49 changes: 44 additions & 5 deletions lib/index.coffee
@@ -1,10 +1,49 @@
cscj = require("coffee-dsl").dsl() module.exports = require("coffee-dsl").dsl()
Collection = require "./collection"


cscj.set "collection", (collectionFun)-> module.exports.set "collection", (collectionFun)->
collection = {version:"1.0"} collection = {version:"1.0"}
root = {collection:collection} root = {collection:collection}
collectionFun.call new Collection(collection) collectionFun.call new exports.Collection(collection)
root 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
12 changes: 0 additions & 12 deletions lib/item.coffee

This file was deleted.

11 changes: 0 additions & 11 deletions lib/query.coffee

This file was deleted.

9 changes: 0 additions & 9 deletions lib/template.coffee

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{ {
"name": "cscj", "name": "cscj",
"version": "0.0.0", "version": "0.0.1",
"description": "Collection+JSON Views in CoffeeScript", "description": "Collection+JSON Views in CoffeeScript",
"main": "index.js", "main": "index.js",
"directories": { "directories": {
Expand Down

0 comments on commit 82e0705

Please sign in to comment.