Permalink
Browse files

Use AMD to define prereqs

  • Loading branch information...
autarch committed Sep 9, 2012
1 parent 5895a5b commit bd55fa48f02427def85fbf0ba8303608d6ee26d3
Showing with 18,962 additions and 1,041 deletions.
  1. +34 −29 lib/Brocket.coffee
  2. +19 −17 lib/Brocket/Base.coffee
  3. +67 −61 lib/Brocket/Helpers.coffee
  4. +153 −151 lib/Brocket/Meta/Attribute.coffee
  5. +20 −19 lib/Brocket/Meta/Cache.coffee
  6. +167 −166 lib/Brocket/Meta/Class.coffee
  7. +46 −45 lib/Brocket/Meta/Method.coffee
  8. +45 −44 lib/Brocket/Meta/Mixin/AttributeCore.coffee
  9. +29 −28 lib/Brocket/Meta/Mixin/HasAttributes.coffee
  10. +32 −31 lib/Brocket/Meta/Mixin/HasMethods.coffee
  11. +29 −28 lib/Brocket/Meta/Mixin/HasRoles.coffee
  12. +135 −134 lib/Brocket/Meta/Role.coffee
  13. +15 −14 lib/Brocket/Meta/Role/Application.coffee
  14. +69 −68 lib/Brocket/Meta/Role/Application/RoleSummation.coffee
  15. +60 −59 lib/Brocket/Meta/Role/Application/ToClass.coffee
  16. +40 −39 lib/Brocket/Meta/Role/Application/ToRole.coffee
  17. +41 −40 lib/Brocket/Meta/Role/Attribute.coffee
  18. +26 −25 lib/Brocket/Meta/Role/Composite.coffee
  19. +12 −11 lib/Brocket/Meta/Role/ConflictingMethod.coffee
  20. +10 −9 lib/Brocket/Meta/Role/RequiredMethod.coffee
  21. +28 −23 lib/Brocket/Role.coffee
  22. +4 −0 lib/Brocket/Types.coffee
  23. +1 −0 node_modules/.bin/r.js
  24. +2 −0 node_modules/amdefine/.npmignore
  25. +58 −0 node_modules/amdefine/LICENSE
  26. +200 −0 node_modules/amdefine/amdefine.js
  27. +41 −0 node_modules/amdefine/package.json
  28. +9 −0 node_modules/requirejs/README.md
  29. +15,484 −0 node_modules/requirejs/bin/r.js
  30. +44 −0 node_modules/requirejs/package.json
  31. +2,041 −0 node_modules/requirejs/require.js
  32. +1 −0 package.json
View
@@ -1,42 +1,47 @@
-Base = require "./Brocket/Base"
-Class = require "./Brocket/Meta/Class"
-Helpers = require "./Brocket/Helpers"
-util = require "util"
+`if (typeof define !== 'function') { var define = require('amdefine')(module) }`
-_has = (meta, name, attr) ->
- clone = name: name
- for own key, val of attr
- clone[key] = val
+define (require) ->
+ Base = require "./Brocket/Base"
+ Class = require "./Brocket/Meta/Class"
+ Helpers = require "./Brocket/Helpers"
+ util = require "util"
- meta.addAttribute clone
+ _has = (meta, name, attr) ->
+ clone = name: name
+ for own key, val of attr
+ clone[key] = val
-_method = (meta, name, body) ->
- meta.addMethod name: name, body: body, source: meta
+ meta.addAttribute clone
-_subclasses = (meta, supers) ->
- meta.setSuperclasses supers
+ _method = (meta, name, body) ->
+ meta.addMethod name: name, body: body, source: meta
-_with = (meta, roles) ->
- Helpers.applyRoles meta, roles
+ _subclasses = (meta, supers) ->
+ meta.setSuperclasses supers
-_consumes = (meta, name, options) ->
+ _with = (meta, roles) ->
+ Helpers.applyRoles meta, roles
-module.exports.makeClass = (name, definition) ->
- metaclass = new Class name: name
+ _consumes = (meta, name, options) ->
- metaclass.setSuperclasses(Base)
+ makeClass = (name, definition) ->
+ metaclass = new Class name: name
- klass = metaclass.class()
+ metaclass.setSuperclasses(Base)
- B = {}
- B.has = (name, attr) -> _has metaclass, name, attr
- B.method = (name, body) -> _method metaclass, name, body
- B.subclasses = (supers) -> _subclasses metaclass, supers
- B.with = (roles...) -> _with metaclass, roles
- B.consumes = (role, options) -> _consumes metaclass, role, options
+ klass = metaclass.class()
- definition ?= -> return
+ B = {}
+ B.has = (name, attr) -> _has metaclass, name, attr
+ B.method = (name, body) -> _method metaclass, name, body
+ B.subclasses = (supers) -> _subclasses metaclass, supers
+ B.with = (roles...) -> _with metaclass, roles
+ B.consumes = (role, options) -> _consumes metaclass, role, options
- definition.call @, B
+ definition ?= -> return
- return klass
+ definition.call @, B
+
+ return klass
+
+ return { makeClass: makeClass };
View
@@ -1,24 +1,26 @@
-Class = require "./Meta/Class"
-util = require "util"
+`if (typeof define !== 'function') { var define = require('amdefine')(module) }`
-class Base
- constructor: ->
- throw new Error "Cannot construct a Brocket/Base object"
+define (require) ->
+ Class = require "./Meta/Class"
+ util = require "util"
- BUILDARGS: (params) ->
- return params ? {}
+ class Base
+ constructor: ->
+ throw new Error "Cannot construct a Brocket/Base object"
- BUILDALL: (params) ->
- for meta in @meta().selfAndParents().reverse()
- build = meta.methodNamed "BUILD"
- build.body().call @, params if build?
+ BUILDARGS: (params) ->
+ return params ? {}
- return
+ BUILDALL: (params) ->
+ for meta in @meta().selfAndParents().reverse()
+ build = meta.methodNamed "BUILD"
+ build.body().call @, params if build?
- DOES: (role) ->
- return @meta().doesRole role
+ return
- _meta = new Class { name: "Brocket.Base", _class: @ }
- @meta: -> _meta
+ DOES: (role) ->
+ return @meta().doesRole role
+
+ _meta = new Class { name: "Brocket.Base", _class: @ }
+ @meta: -> _meta
-module.exports = Base
View
@@ -1,84 +1,90 @@
-_ = require "underscore"
-util = require "util"
+`if (typeof define !== 'function') { var define = require('amdefine')(module) }`
-Class = null
-Role = null
+define (require) ->
+ _ = require "underscore"
+ util = require "util"
+
+ Class = null
+ Role = null
+
+ e = {};
+ e.arrayToObject = (array) ->
+ if typeof array == "string"
+ obj = {}
+ obj[array] = true
+ return obj
-module.exports.arrayToObject = (array) ->
- if typeof array == "string"
obj = {}
- obj[array] = true
- return obj
+ for elt in array
+ obj[elt] = true
- obj = {}
- for elt in array
- obj[elt] = true
+ return obj
- return obj
+ e.className = (klass) ->
+ if matches = klass.toString().match( /function\s*(\w+)/ )
+ return matches[1]
+ else
+ return null
-module.exports.className = (klass) ->
- if matches = klass.toString().match( /function\s*(\w+)/ )
- return matches[1]
- else
- return null
+ e.applyRoles = (applyTo, roles...) ->
+ Role ?= require "./Meta/Role"
-module.exports.applyRoles = (applyTo, roles...) ->
- Role ?= require "./Meta/Role"
+ if roles[0] instanceof Array
+ roles = roles[0]
- if roles[0] instanceof Array
- roles = roles[0]
+ rolesWithArgs = e.optList roles, { lhs: Role }
- rolesWithArgs = module.exports.optList roles, { lhs: Role }
+ if rolesWithArgs.length == 2
+ role = rolesWithArgs[0]
+ args = rolesWithArgs[1]
- if rolesWithArgs.length == 2
- role = rolesWithArgs[0]
- args = rolesWithArgs[1]
+ role.apply applyTo, args
+ else
+ (Role.Combine rolesWithArgs).apply applyTo
- role.apply applyTo, args
- else
- (Role.Combine rolesWithArgs).apply applyTo
+ return
- return
+ e.optList = (list, args) ->
+ args ?= {}
-module.exports.optList = (list, args) ->
- args ?= {}
+ lhsTest =
+ if args.lhs?
+ (item) -> item instanceof args.lhs
+ else
+ (item) -> typeof item == "string"
- lhsTest =
- if args.lhs?
- (item) -> item instanceof args.lhs
- else
- (item) -> typeof item == "string"
+ pairs = []
+ for item in list
+ if lhsTest item
+ pairs.push [item]
+ else if item instanceof Object
+ pairs[ pairs.length - 1 ].push item
- pairs = []
- for item in list
- if lhsTest item
- pairs.push [item]
- else if item instanceof Object
- pairs[ pairs.length - 1 ].push item
+ retVal = []
+ for pair in pairs
+ pair[1] ?= {}
+ retVal = retVal.concat pair
- retVal = []
- for pair in pairs
- pair[1] ?= {}
- retVal = retVal.concat pair
+ return retVal
- return retVal
+ e.findMeta = (thing, classClass) ->
+ Class ?= require "./Meta/Class"
+ Role ?= require "./Meta/Role"
-module.exports.findMeta = (thing, classClass) ->
- Class ?= require "./Meta/Class"
- Role ?= require "./Meta/Role"
+ return thing if thing instanceof Class
+ return thing if thing instanceof Role
+ return thing.meta() if thing.meta?
- return thing if thing instanceof Class
- return thing if thing instanceof Role
- return thing.meta() if thing.meta?
+ unless typeof thing == "function"
+ throw new Error "Cannot find a metaclass for a #{thing}"
- unless typeof thing == "function"
- throw new Error "Cannot find a metaclass for a #{thing}"
+ # Allows callers to pass an alternate metaclass
+ classClass ?= Class
- # Allows callers to pass an alternate metaclass
- classClass ?= Class
+ unless classClass.newFromClass?
+ name = e.className classClass
+ throw new Error "The #{name} class does not have a newFromClass method"
- unless classClass.newFromClass?
- name = module.exports.className classClass
- throw new Error "The #{name} class does not have a newFromClass method"
+ return classClass.newFromClass thing
- return classClass.newFromClass thing
+ return e
Oops, something went wrong.

0 comments on commit bd55fa4

Please sign in to comment.