Skip to content
Browse files

working on switching to rake pipeline/qunit/minispade

  • Loading branch information...
1 parent 8015775 commit 69ecaa8f1cf3e0e90e1d004e792ab9c3b39c815b @collin committed Apr 25, 2012
Showing with 673 additions and 561 deletions.
  1. +1 −0 .gitignore
  2. +19 −0 Assetfile
  3. +37 −0 Assetfile-docs
  4. +8 −0 Gemfile
  5. +43 −0 Gemfile.lock
  6. +52 −0 Rakefile
  7. +0 −9 lib/alpha_simprini/client/views/horizontal_split.coffee
  8. +0 −2 lib/alpha_simprini/client/views/splitter.coffee
  9. +0 −8 lib/alpha_simprini/client/views/vertical_split.coffee
  10. 0 lib/alpha_simprini/client/views/viewport.coffee
  11. +18 −18 lib/alpha_simprini/core/properties/has_one.coffee
  12. +0 −93 lib/alpha_simprini/packer.coffee
  13. +0 −44 lib/alpha_simprini/string.coffee
  14. +9 −9 {lib → src}/alpha_simprini.coffee
  15. +1 −2 {lib → src}/alpha_simprini/client.coffee
  16. +1 −6 {lib → src}/alpha_simprini/client/application.coffee
  17. +0 −3 {lib → src}/alpha_simprini/client/binding.coffee
  18. +0 −3 {lib → src}/alpha_simprini/client/binding/check_box.coffee
  19. +0 −3 {lib → src}/alpha_simprini/client/binding/container.coffee
  20. +2 −4 {lib → src}/alpha_simprini/client/binding/edit_line.coffee
  21. +0 −4 {lib → src}/alpha_simprini/client/binding/field.coffee
  22. +0 −2 {lib → src}/alpha_simprini/client/binding/file.coffee
  23. +0 −3 {lib → src}/alpha_simprini/client/binding/input.coffee
  24. +0 −3 {lib → src}/alpha_simprini/client/binding/many.coffee
  25. +0 −4 {lib → src}/alpha_simprini/client/binding/model.coffee
  26. +0 −4 {lib → src}/alpha_simprini/client/binding/one.coffee
  27. +0 −3 {lib → src}/alpha_simprini/client/binding/select.coffee
  28. +0 −3 {lib → src}/alpha_simprini/client/binding_group.coffee
  29. +0 −4 {lib → src}/alpha_simprini/client/dom.coffee
  30. +0 −4 {lib → src}/alpha_simprini/client/models/targets.coffee
  31. +0 −5 {lib → src}/alpha_simprini/client/view.coffee
  32. +0 −3 {lib → src}/alpha_simprini/client/view_events.coffee
  33. +0 −6 {lib → src}/alpha_simprini/client/view_model.coffee
  34. +0 −1 {lib → src}/alpha_simprini/client/views/canvas.coffee
  35. +1 −3 {lib → src}/alpha_simprini/client/views/dialog.coffee
  36. +0 −1 {lib → src}/alpha_simprini/client/views/panel.coffee
  37. +0 −3 {lib → src}/alpha_simprini/client/views/region.coffee
  38. +0 −1 {lib → src}/alpha_simprini/client/views/stage.coffee
  39. +2 −2 {lib → src}/alpha_simprini/core.coffee
  40. +5 −6 {lib → src}/alpha_simprini/core/callbacks.coffee
  41. +45 −48 {lib → src}/alpha_simprini/core/collection.coffee
  42. +28 −30 {lib → src}/alpha_simprini/core/filtered_collection.coffee
  43. +0 −3 {lib → src}/alpha_simprini/core/instance_methods.coffee
  44. +0 −2 {lib → src}/alpha_simprini/core/logging.coffee
  45. +26 −30 {lib → src}/alpha_simprini/core/model.coffee
  46. +0 −3 {lib → src}/alpha_simprini/core/model/dendrite.coffee
  47. +1 −4 {lib → src}/alpha_simprini/core/model/rest.coffee
  48. +2 −3 {lib → src}/alpha_simprini/core/model/share.coffee
  49. +1 −3 {lib → src}/alpha_simprini/core/model/store.coffee
  50. +0 −3 {lib → src}/alpha_simprini/core/model/synapse.coffee
  51. +16 −19 {lib → src}/alpha_simprini/core/models/file.coffee
  52. +0 −2 {lib → src}/alpha_simprini/core/models/group.coffee
  53. +16 −17 {lib → src}/alpha_simprini/core/models/grouping.coffee
  54. +10 −11 {lib → src}/alpha_simprini/core/models/multiple_selection_model.coffee
  55. +10 −11 {lib → src}/alpha_simprini/core/models/radio_selection_model.coffee
  56. +0 −3 {lib → src}/alpha_simprini/core/properties/belongs_to.coffee
  57. +24 −26 {lib → src}/alpha_simprini/core/properties/field.coffee
  58. +35 −38 {lib → src}/alpha_simprini/core/properties/has_many.coffee
  59. +93 −0 src/alpha_simprini/core/properties/has_one.coffee
  60. +23 −26 {lib → src}/alpha_simprini/core/properties/virtual_property.coffee
  61. +7 −10 {lib → src}/alpha_simprini/core/state_machine.coffee
  62. +93 −0 src/alpha_simprini/packer.coffee
  63. +44 −0 src/alpha_simprini/string.coffee
View
1 .gitignore
@@ -1,3 +1,4 @@
*node_modules/*
examples/todo/node_modules/
.DS_Store
+lib/
View
19 Assetfile
@@ -0,0 +1,19 @@
+require "rake-pipeline-web-filters"
+require "json"
+# require "uglifier"
+
+output "dist"
+input "lib" do
+ match "**/*.js" do
+ minispade rewrite_requires: true, string: true, module_id_generator: proc { |input|
+ id = input.path.dup
+ id.sub!('/lib/', '/')
+ id.sub!(/\.js$/, '')
+ id.sub!(/\/main$/, '')
+ id
+ }
+
+ concat "AlphaSimprini-spade.js"
+ end
+
+end
View
37 Assetfile-docs
@@ -0,0 +1,37 @@
+require "rake-pipeline-web-filters"
+require "json"
+# require "uglifier"
+
+class PathologyDocumentFilter < Rake::Pipeline::Filter
+ # NOW WE HAVE TWO PROBLEMS
+ # this splits methods/documentation into two groups
+ # we'll flip the order four the output
+ DOC_FILTER = /((?:[ ]+#.+doc[ =].+\n)(?:[ ]+#.*\n)+)/
+ def generate_output(inputs, output)
+ inputs.each do |input|
+ result = File.read(input.fullpath)
+ result.gsub!(DOC_FILTER) do |match|
+ $1.gsub!(/[ ]+(#)/) {|match| " " * (match.length - 2) }
+ end
+ output.write result
+ end
+ end
+end
+
+output "docs"
+input "./src" do
+ match "**/*.coffee" do
+ filter PathologyDocumentFilter
+ filter Rake::Pipeline::Web::Filters::CoffeeScriptFilter
+
+ minispade rewrite_requires: true, string: true, module_id_generator: proc { |input|
+ id = input.path.dup
+ id.sub!('/lib/', '/')
+ id.sub!(/\.js$/, '')
+ id.sub!(/\/main$/, '')
+ id
+ }
+
+ concat "AlphaSimprini-docs.js"
+ end
+end
View
8 Gemfile
@@ -0,0 +1,8 @@
+# A sample Gemfile
+source "https://rubygems.org"
+
+gem "rake-pipeline", :git => "https://github.com/livingsocial/rake-pipeline.git"
+gem "rake-pipeline-web-filters", :git => "https://github.com/wycats/rake-pipeline-web-filters.git"
+gem "colored"
+gem "uglifier", "~> 1.0.3"
+gem "coffee-script"
View
43 Gemfile.lock
@@ -0,0 +1,43 @@
+GIT
+ remote: https://github.com/livingsocial/rake-pipeline.git
+ revision: 543f4322fe70facee9572d29ddabf7f090dad68a
+ specs:
+ rake-pipeline (0.6.0)
+ rake (~> 0.9.0)
+ thor
+
+GIT
+ remote: https://github.com/wycats/rake-pipeline-web-filters.git
+ revision: ba0b8a00356b4c854930a8e849b5629d51ffd70f
+ specs:
+ rake-pipeline-web-filters (0.6.0)
+ rack
+ rake-pipeline (~> 0.6)
+
+GEM
+ remote: https://rubygems.org/
+ specs:
+ coffee-script (2.2.0)
+ coffee-script-source
+ execjs
+ coffee-script-source (1.2.0)
+ colored (1.2)
+ execjs (1.3.0)
+ multi_json (~> 1.0)
+ multi_json (1.3.2)
+ rack (1.4.1)
+ rake (0.9.2.2)
+ thor (0.14.6)
+ uglifier (1.0.4)
+ execjs (>= 0.3.0)
+ multi_json (>= 1.0.2)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ coffee-script
+ colored
+ rake-pipeline!
+ rake-pipeline-web-filters!
+ uglifier (~> 1.0.3)
View
52 Rakefile
@@ -0,0 +1,52 @@
+abort "Use Ruby 1.9 to build AlphaSimprini" unless RUBY_VERSION["1.9"]
+
+require 'rake-pipeline'
+
+def build
+ Rake::Pipeline::Project.new("Assetfile")
+end
+
+def doc_build
+ Rake::Pipeline::Project.new("Assetfile-docs")
+end
+
+desc "Strip trailing whitespace for CoffeeScript files in packages"
+task :strip_whitespace do
+ Dir["{src,test}/**/*.coffee"].each do |name|
+ body = File.read(name)
+ File.open(name, "w") do |file|
+ file.write body.gsub(/ +\n/, "\n")
+ end
+ end
+end
+
+desc "Compile CoffeeScript"
+task :coffeescript => :clean do
+ puts "Compiling CoffeeScript"
+ `coffee -co lib/ src/`
+ puts "Done"
+end
+
+desc "Build AlphaSimprini with documentation"
+task :doc_build => [:strip_whitespace] do
+ puts "Building AlphaSimprini Docs..."
+ doc_build.clean
+ doc_build.invoke
+ puts "Done"
+end
+
+
+desc "Build AlphaSimprini"
+task :dist => [:coffeescript, :strip_whitespace] do
+ puts "Building AlphaSimprini..."
+ build.invoke
+ puts "Done"
+end
+
+desc "Clean build artifacts from previous builds"
+task :clean do
+ puts "Cleaning build..."
+ `rm -rf ./lib/*`
+ build.clean
+ puts "Done"
+end
View
9 lib/alpha_simprini/client/views/horizontal_split.coffee
@@ -1,9 +0,0 @@
-module "AS.Views", ->
- class @HorizontalSplit extends AS.View
-
- content: (args) ->
- @left ?= new AS.Views.Panel
- @bar ?= new AS.Views.Splitter
- @right ?= new AS.Views.Panel
- @el.append @left.el, @bar.el, @right.el
-
View
2 lib/alpha_simprini/client/views/splitter.coffee
@@ -1,2 +0,0 @@
-module "AS.Views", ->
- class @Splitter extends AS.View
View
8 lib/alpha_simprini/client/views/vertical_split.coffee
@@ -1,8 +0,0 @@
-module "AS.Views", ->
- class @VerticalSplit extends AS.View
-
- initialize: () ->
- @top ?= new AS.Views.Panel
- @bar ?= new AS.Views.Splitter
- @bottom ?= new AS.Views.Panel
- @el.append @top.el, @bar.el, @bottom.el
View
0 lib/alpha_simprini/client/views/viewport.coffee
No changes.
View
36 lib/alpha_simprini/core/properties/has_one.coffee
@@ -2,18 +2,24 @@ AS = require("alpha_simprini")
_ = require("underscore")
AS.Model.HasOne = AS.Model.Field.extend ({delegate, include, def, defs}) ->
+ def couldBe: (test) ->
+ return true if test in @options.model?().ancestors
+ @_super.apply(this, arguments)
# @::couldBe.doc =
# params: [
# ["test", undefined, true]
# ]
# desc: """
#
# """
- def couldBe: (test) ->
- return true if test in @options.model?().ancestors
- @_super.apply(this, arguments)
AS.Model.HasOne.Instance = AS.Model.Field.Instance.extend ({def}) ->
+ def initialize: (@object, @options) ->
+ @options.model ?= -> AS.Model
+ @model = @options.model
+ @namespace = ".#{_.uniqueId()}"
+ @_super.apply(this, arguments)
+ @bind "destroy", => @set(null)
# @::initialize.doc =
# params: [
# ["@object", AS.Model, true]
@@ -22,28 +28,15 @@ AS.Model.HasOne.Instance = AS.Model.Field.Instance.extend ({def}) ->
# desc: """
#
# """
- def initialize: (@object, @options) ->
- @options.model ?= -> AS.Model
- @model = @options.model
- @namespace = ".#{_.uniqueId()}"
- @_super.apply(this, arguments)
- @bind "destroy", => @set(null)
+ def get: ->
+ @value
# @::get.doc =
# return: [AS.Model, null]
# desc: """
#
# """
- def get: ->
- @value
- # @::set.doc =
- # params: [
- # ["value", AS.Model]
- # ]
- # desc: """
- #
- # """
def set: (value) ->
value = value.model if value?.model
return @value if value is @value
@@ -77,6 +70,13 @@ AS.Model.HasOne.Instance = AS.Model.Field.Instance.extend ({def}) ->
@trigger("change")
@triggerDependants()
@value
+ # @::set.doc =
+ # params: [
+ # ["value", AS.Model]
+ # ]
+ # desc: """
+ #
+ # """
@Synapse = AS.Model.Field.Instance.Synapse.extend ({delegate, include, def, defs}) ->
def get: ->
View
93 lib/alpha_simprini/packer.coffee
@@ -1,93 +0,0 @@
-module "AS.Heap", ->
- @CLASS = 0x11
- @ATTRIBUTES = 0x12
- @CLASSES = 0x13
- @OBJECTS = 0x14
- @NAMED_OBJECTS = 0x15
- @LITERALS = 0x16
-
- class @NullClass
- constructor: ->
-
- @Classes =
- PackedClass: Function
- Array: Array
- Numeric: Number
- Fixnum: Number
- String: String
- Symbol: String
- Hash: Object
- NilClass: null
- FalseClass: false
- TrueClass: true
-
- class @Unpacker
- constructor: (hash) ->
- @literals = hash[AS.Heap.LITERALS]
- @classes = {}
-
- for key, value of hash[AS.Heap.CLASSES]
- @classes[value] = @resolve_class(key)
-
- @packed_objects = hash[AS.Heap.OBJECTS]
- @objects = {}
- @named_objects = {}
-
- @unpack_object(key) for key, value of @packed_objects
-
- for key, value of hash[AS.Heap.NAMED_OBJECTS]
- @named_objects[@unpack_object(key)] = @unpack_object(value)
-
- resolve_class: (key) ->
- unless (klass = AS.Heap.Classes[key]) is undefined
- klass
- else
- throw new Error("Unresolved class with key #{key}")
-
-
- allocate_object: (klass) ->
- eval("function #{klass.name} () {this.constructor = klass; }")
- ctor = eval klass.name
- ctor.prototype = klass.prototype
- ctor.__super__ = klass.__super__
- object = new ctor
-
- unpack_object: (key) ->
- return @objects[key] if @objects[key]
- value = @packed_objects[key]
- attributes = value[AS.Heap.ATTRIBUTES]
- klass = @classes[value[AS.Heap.CLASS]]
- if klass == Object
- object = @objects[key] = {}
- for _key, _value of attributes
- object[@unpack_object(_key)] = @unpack_object(_value)
- object
- # else if klass == Function
- # console.log "FUCTIONCLASS", klass, @unpack_object(value)
- else if klass == Array
- @objects[key] = @unpack_object(item) for item in attributes
- else if klass == Number
- @objects[key] = @literals[attributes]
- else if klass == String
- @objects[key] = @literals[attributes]
- else if klass == null
- @objects[key] = null
- else if klass == true
- @objects[key] = true
- else if klass == false
- @objects[key] = false
- else
- object = @objects[key] = @allocate_object(klass)
- for _key, _value of attributes
- object[@unpack_object(_key).replace(/^@/, '')] = @unpack_object(_value)
- object
-
-# FIXME: TESTCASE
-# class ThingClass
-#
-# constructor: (@ace, @b, @c, @t) ->
-#
-# AS.Heap.Classes.Thing = ThingClass
-#
-# window.d = {"19":{"Thing":0,"Symbol":1,"String":2,"Array":3,"NilClass":4,"Fixnum":5,"Numeric":6},"20":{"70175767968160":{"17":0,"18":{"677308":70175767963660,"677468":70175767968120,"677628":247,"677788":70175767968160}},"677308":{"17":2,"18":0},"70175767963660":{"17":3,"18":[70175767968100,70175767968060,70175767968020,70175767967980,70175767967940,70175767967900,70175767967860,70175767967820,70175767967780,70175767967740,70175767967700,70175767967660,70175767967620,70175767967580,70175767967540,70175767967500,70175767967460,70175767967420,70175767967380,70175767967340,70175767967300,70175767967260,70175767967220,70175767967180,70175767967140,70175767967100,70175767967060,70175767967020,70175767966980,70175767966940,70175767966900,70175767966860,70175767966820,70175767966780,70175767966740,70175767966700,70175767966660,70175767966620,70175767966580,70175767966540,70175767966500,70175767966460,70175767966420,70175767966380,70175767966340,70175767966300,70175767966260,70175767966220,70175767966180,70175767966140,70175767966100,70175767966060,70175767966020,70175767965980,70175767965940,70175767965900,70175767965860,70175767965820,70175767965780,70175767965740,70175767965700,70175767965660,70175767965620,70175767965580,70175767965540,70175767965500,70175767965460,70175767965420,70175767965380,70175767965340,70175767965300,70175767965260,70175767965220,70175767965180,70175767965140,70175767965100,70175767965060,70175767965020,70175767964980,70175767964940,70175767964900,70175767964860,70175767964820,70175767964780,70175767964740,70175767964700,70175767964660,70175767964620,70175767964580,70175767964540,70175767964500,70175767964460,70175767964420,70175767964380,70175767964340,70175767964300,70175767964260,70175767964220,70175767964180,70175767964140,70175767964100,70175767964060,70175767964020,70175767963980,70175767963940,70175767963900,70175767963860,70175767963820,70175767963780,70175767963740,70175767963700]},"70175767968100":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"4":{"17":4,"18":{}},"677468":{"17":2,"18":1},"677628":{"17":2,"18":2},"677788":{"17":2,"18":3},"70175767968060":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767968020":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767967980":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767967940":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767967900":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767967860":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767967820":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767967780":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767967740":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767967700":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767967660":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767967620":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767967580":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767967540":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767967500":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767967460":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767967420":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767967380":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767967340":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767967300":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767967260":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767967220":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767967180":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767967140":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767967100":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767967060":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767967020":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767966980":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767966940":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767966900":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767966860":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767966820":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767966780":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767966740":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767966700":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767966660":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767966620":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767966580":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767966540":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767966500":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767966460":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767966420":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767966380":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767966340":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767966300":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767966260":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767966220":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767966180":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767966140":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767966100":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767966060":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767966020":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767965980":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767965940":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767965900":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767965860":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767965820":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767965780":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767965740":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767965700":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767965660":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767965620":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767965580":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767965540":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767965500":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767965460":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767965420":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767965380":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767965340":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767965300":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767965260":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767965220":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767965180":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767965140":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767965100":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767965060":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767965020":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767964980":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767964940":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767964900":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767964860":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767964820":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767964780":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767964740":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767964700":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767964660":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767964620":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767964580":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767964540":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767964500":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767964460":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767964420":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767964380":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767964340":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767964300":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767964260":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767964220":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767964180":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767964140":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767964100":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767964060":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767964020":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767963980":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767963940":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767963900":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767963860":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767963820":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767963780":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767963740":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767963700":{"17":0,"18":{"677308":4,"677468":4,"677628":4,"677788":4}},"70175767968120":{"17":2,"18":4},"247":{"17":6,"18":5},"70175767963520":{"17":2,"18":6}},"21":{"70175767963520":70175767968160},"22":["@ace","@b","@c","@t","OMGt,t,t,t,t,t,t,t,t,t,t,tt,t,t,t,t,t,t,t,t,t,t,tt,t,t,t,t,t,t,t,t,t,t,tt,t,t,t,t,t,t,t,t,t,t,tt,t,t,t,t,t,t,t,t,t,t,t",123,"thing"]}
-# window.up=new AS.Heap.Unpacker(d)
View
44 lib/alpha_simprini/string.coffee
@@ -1,44 +0,0 @@
-_ = require("underscore")
-_.str = require("underscore.string")
-_.mixin(_.str.exports())
-
-
-String::blank = ->
- !!@match(/^\s*?$/)
-
-String::underscore = ->
- under = @replace(/([A-Z])/g, (match) -> "_#{match}")
- if under[0] is "_"
- under.slice(1).toLowerCase()
- else
- under.toLowerCase()
-
-String::camelcase = ->
- @replace(/^([a-z])|_([a-z])|-([a-z])/g, (match) -> match.toUpperCase()).replace(/-|_/, '')
-
-String::dasherize = ->
- @underscore().replace(/_/g, '-')
-
-# funcitons following point are subject to the following license:
-###
-Copyright (c) 2010 Ryan Schuft (ryan.schuft@gmail.com)
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-###
-
View
18 lib/alpha_simprini.coffee → src/alpha_simprini.coffee
@@ -1,17 +1,17 @@
# Bootstraps
-Pathology = require "pathology"
-Taxi = require "taxi"
-require "./alpha_simprini/string"
-require "./alpha_simprini/core/logging"
+require "pathology"
+require "taxi"
+require "alpha_simprini/string"
+require "alpha_simprini/core/logging"
-AS = module.exports = Pathology.Namespace.new("AlphaSimprini")
+window.AS = Pathology.Namespace.new("AlphaSimprini")
AS.unimplemented = (method) ->
return ->
throw new Error ["you MUST implement the method '#{method}' on: #{@toString()}"]
AS.part = (name) ->
- exports[name] = require: (libraries) -> AS.require name.toLowerCase(), libraries
+ AS[name] = require: (libraries) -> AS.require name.toLowerCase(), libraries
# Namespaces
AS.Models = Pathology.Namespace.new()
@@ -29,11 +29,11 @@ AS.COLLECTION_DELEGATES = ["first", "rest", "last", "compact", "flatten", "witho
AS.require = (framework="alpha_simprini", libraries) ->
if libraries is undefined
- require "./alpha_simprini/#{framework}"
+ require "alpha_simprini/#{framework}"
else
for library in libraries.split(/\s+/)
continue if library.blank()
- require "./alpha_simprini/#{framework}/#{library}"
+ require "alpha_simprini/#{framework}/#{library}"
# Core libs, should run well in Node.js or in a Browser
-require "./alpha_simprini/core"
+require "alpha_simprini/core"
View
3 lib/alpha_simprini/client.coffee → src/alpha_simprini/client.coffee
@@ -1,6 +1,5 @@
-AS = require "alpha_simprini"
+require "alpha_simprini"
Client = AS.part("Client")
-_ = require "underscore"
Client.require """
dom view view_model binding_group view_events
View
7 lib/alpha_simprini/client/application.coffee → src/alpha_simprini/client/application.coffee
@@ -1,9 +1,4 @@
-AS = require("alpha_simprini")
-Taxi = require("taxi")
-{each} = require("underscore")
-jwerty = require("jwerty").jwerty
-domready = $ = require("jquery")
-_ = require "underscore"
+{each} = _
AS.Application = AS.Object.extend ({def, include}) ->
include Taxi.Mixin
View
3 lib/alpha_simprini/client/binding.coffee → src/alpha_simprini/client/binding.coffee
@@ -1,6 +1,3 @@
-AS = require("alpha_simprini")
-_ = require "underscore"
-
AS.Binding = AS.Object.extend ({def}) ->
def initialize: (@context, @model, @field, @options={}, @fn=undefined) ->
if _.isString(@field)
View
3 ..._simprini/client/binding/check_box.coffee → ..._simprini/client/binding/check_box.coffee
@@ -1,6 +1,3 @@
-AS = require("alpha_simprini")
-_ = require "underscore"
-
AS.Binding.CheckBox = AS.Binding.Input.extend ({def}) ->
def initialize: (context, model, field, options={}, fn=undefined) ->
options.type = "checkbox"
View
3 ..._simprini/client/binding/container.coffee → ..._simprini/client/binding/container.coffee
@@ -1,6 +1,3 @@
-AS = require "alpha_simprini"
-jQuery = require "jquery"
-
AS.Binding.Container = AS.Object.extend ({delegate, include, def, defs}) ->
delegate 'find', 'html', to: 'el'
View
6 ..._simprini/client/binding/edit_line.coffee → ..._simprini/client/binding/edit_line.coffee
@@ -1,8 +1,6 @@
-AS = require("alpha_simprini")
-_ = require "underscore"
-
+require "rangy-core"
AS.Binding.EditLine = AS.Binding.extend ({def}) ->
- def rangy: require("rangy-core")
+ def rangy: rangy
def applyChange: (doc, oldval, newval) ->
return if oldval == newval
View
4 ...lpha_simprini/client/binding/field.coffee → ...lpha_simprini/client/binding/field.coffee
@@ -1,7 +1,3 @@
-AS = require("alpha_simprini")
-_ = require "underscore"
-jQuery = require "jquery"
-
AS.Binding.Field = AS.Binding.extend ({def}) ->
def initialize: ->
@_super.apply this, arguments
View
2 ...alpha_simprini/client/binding/file.coffee → ...alpha_simprini/client/binding/file.coffee
@@ -1,5 +1,3 @@
-_ = require("underscore")
-AS = require "alpha_simprini"
AS.Binding.File = AS.Binding.Input.extend ({delegate, include, def, defs}) ->
def makeContent: ->
options = _.clone(@options)
View
3 ...lpha_simprini/client/binding/input.coffee → ...lpha_simprini/client/binding/input.coffee
@@ -1,6 +1,3 @@
-AS = require("alpha_simprini")
-_ = require "underscore"
-
AS.Binding.Input = AS.Binding.Field.extend ({def}) ->
def initialize: ->
@_super.apply(this, arguments)
View
3 ...alpha_simprini/client/binding/many.coffee → ...alpha_simprini/client/binding/many.coffee
@@ -1,6 +1,3 @@
-AS = require("alpha_simprini")
-_ = require "underscore"
-
AS.Binding.Many = AS.Binding.extend ({def}) ->
@willGroupBindings = true
View
4 ...lpha_simprini/client/binding/model.coffee → ...lpha_simprini/client/binding/model.coffee
@@ -1,7 +1,3 @@
-AS = require("alpha_simprini")
-_ = require "underscore"
-$ = require "jquery"
-
AS.Binding.Model = AS.Object.extend ({def}) ->
def initialize: (@context, @model, @content=$([])) ->
@styles = {}
View
4 lib/alpha_simprini/client/binding/one.coffee → src/alpha_simprini/client/binding/one.coffee
@@ -1,7 +1,3 @@
-AS = require("alpha_simprini")
-_ = require "underscore"
-jQuery = require "jquery"
-
AS.Binding.One = AS.Binding.Field.extend ({delegate, include, def, defs}) ->
def makeContent: ->
AS.Binding.Container.new(@container[0])
View
3 ...pha_simprini/client/binding/select.coffee → ...pha_simprini/client/binding/select.coffee
@@ -1,6 +1,3 @@
-AS = require("alpha_simprini")
-_ = require "underscore"
-
AS.Binding.Select = AS.Binding.Input.extend ({def}) ->
def initialize: ->
@_super.apply(this, arguments)
View
3 ...lpha_simprini/client/binding_group.coffee → ...lpha_simprini/client/binding_group.coffee
@@ -1,6 +1,3 @@
-AS = require("alpha_simprini")
-_ = require "underscore"
-
AS.BindingGroup = AS.Object.extend ({def}) ->
def initialize: (@parentGroup) ->
View
4 lib/alpha_simprini/client/dom.coffee → src/alpha_simprini/client/dom.coffee
@@ -1,7 +1,3 @@
-AS = require("alpha_simprini")
-_ = require "underscore"
-$ = require "jquery"
-
SVG =
ns: "http://www.w3.org/2000/svg"
View
4 ...pha_simprini/client/models/targets.coffee → ...pha_simprini/client/models/targets.coffee
@@ -1,7 +1,3 @@
-AS = require("alpha_simprini")
-$ = require("jquery")
-Taxi = require "taxi"
-
TOP = name:"TOP", toString: -> @name
MIDDLE = name:"MIDDLE", toString: -> @name
BOTTOM = name:"BOTTOM", toString: -> @name
View
5 lib/alpha_simprini/client/view.coffee → src/alpha_simprini/client/view.coffee
@@ -1,8 +1,3 @@
-AS = require("alpha_simprini")
-Taxi = require("taxi")
-_ = require("underscore")
-fleck = require("fleck")
-
AS.View = AS.DOM.extend ({delegate, include, def, defs}) ->
include Taxi.Mixin
include AS.Callbacks
View
3 lib/alpha_simprini/client/view_events.coffee → src/alpha_simprini/client/view_events.coffee
@@ -1,6 +1,3 @@
-AS = require("alpha_simprini")
-_ = require "underscore"
-
AS.ViewEvents = AS.Object.extend ({def}) ->
EVENT_SPLITTER = /^(@?[\w:]+)\s*(.*)$/
View
6 lib/alpha_simprini/client/view_model.coffee → src/alpha_simprini/client/view_model.coffee
@@ -1,9 +1,3 @@
-AS = require "alpha_simprini"
-_ = require "underscore"
-jQuery = require "jQuery"
-Pathology = require "pathology"
-Taxi = require("taxi")
-
AS.ViewModel = AS.Object.extend ({delegate, include, def, defs}) ->
delegate 'readPath', 'writePath', to: 'model'
View
1 ...alpha_simprini/client/views/canvas.coffee → ...alpha_simprini/client/views/canvas.coffee
@@ -1,2 +1 @@
-AS = require "alpha_simprini"
class AS.Views.Canvas extends AS.Views.Panel
View
4 ...alpha_simprini/client/views/dialog.coffee → ...alpha_simprini/client/views/dialog.coffee
@@ -1,6 +1,4 @@
-AS = require "alpha_simprini"
-_ = require "underscore"
-knead = require "knead"
+require "knead"
AS.Views.Dialog = AS.Views.Panel.extend ({delegate, include, def, defs}) ->
def initialize: ->
View
1 lib/alpha_simprini/client/views/panel.coffee → src/alpha_simprini/client/views/panel.coffee
@@ -1,2 +1 @@
-AS = require "alpha_simprini"
AS.Views.Panel = AS.View.extend()
View
3 ...alpha_simprini/client/views/region.coffee → ...alpha_simprini/client/views/region.coffee
@@ -1,6 +1,3 @@
-AS = require "alpha_simprini"
-_ = require "underscore"
-
sum = (array) -> _.reduce(array, ((memo, num) -> memo + num), 0)
AS.Views.Region = AS.View.extend ({def}) ->
View
1 lib/alpha_simprini/client/views/stage.coffee → src/alpha_simprini/client/views/stage.coffee
@@ -1,4 +1,3 @@
-AS = require "alpha_simprini"
AS.Views.Stage = AS.Views.Panel.extend ({delegate, include, def, defs}) ->
def canvas_class: AS.Views.Canvas
def initialize: (config) ->
View
4 lib/alpha_simprini/core.coffee → src/alpha_simprini/core.coffee
@@ -1,6 +1,6 @@
-AS = require "alpha_simprini"
+require "alpha_simprini"
Core = AS.part("Core")
-_ = require "underscore"
+require "underscore"
Core.require """
logging
View
11 lib/alpha_simprini/core/callbacks.coffee → src/alpha_simprini/core/callbacks.coffee
@@ -1,5 +1,4 @@
-AS = require("alpha_simprini")
-{upperCamelize} = require("fleck")
+# {upperCamelize} = require("fleck")
AS.Callbacks = AS.Module.extend ({def, defs}) ->
defs defineCallbacks: (all) ->
@@ -10,13 +9,13 @@ AS.Callbacks = AS.Module.extend ({def, defs}) ->
@["#{key}#{upperCamelize callback}"] = (fn) ->
@pushInheritableItem("#{key}#{upperCamelize callback}_callbacks", fn)
+ def runCallbacks: (name) ->
+ for callback in @constructor["#{name}_callbacks"] || []
+ callback.call(null, this)
# @::runCallbacks.doc =
# params: [
# ["name", String, true]
# ]
# desc: """
#
- # """
- def runCallbacks: (name) ->
- for callback in @constructor["#{name}_callbacks"] || []
- callback.call(null, this)
+ # """
View
93 lib/alpha_simprini/core/collection.coffee → src/alpha_simprini/core/collection.coffee
@@ -1,42 +1,31 @@
-AS = require("alpha_simprini")
-Taxi = require("taxi")
-_ = require("underscore")
{extend, isString} = _
AS.Collection = AS.Object.extend ({def, include, delegate}) ->
include Taxi.Mixin
delegate AS.COLLECTION_DELEGATES, to: "models"
- # @::initialize.doc =
- # params: [
- # ["@models", [AS.Model], false, default: []]
- # ["options", Object, false, default: {}]
- # ]
- # desc: """
- #
- # """
def initialize: (@models=[], options = {}) ->
extend this, options
@length = 0
@byId = {}
@byCid = {}
@models = _([]).chain()
@add(model) for model in @models
-
- # @::model.doc =
+ # @::initialize.doc =
+ # params: [
+ # ["@models", [AS.Model], false, default: []]
+ # ["options", Object, false, default: {}]
+ # ]
# desc: """
#
# """
- def model: -> AS.Model
- # @::add.doc =
- # params: [
- # ["model", [AS.Model, String, Object], false, default: {}]
- # ["options", Object, false, default: {}]
- # ]
+ def model: -> AS.Model
+ # @::model.doc =
# desc: """
#
# """
+
def add: (model={}, options={}) ->
# Allow for passing both Model and ViewModels in
model = model.model if model.model and model.model.id
@@ -50,15 +39,15 @@ AS.Collection = AS.Object.extend ({def, include, delegate}) ->
@_add(model, options)
model
-
- # @::build.doc =
- # private: true
+ # @::add.doc =
# params: [
- # ["model", [AS.Model, String, Object], true]
+ # ["model", [AS.Model, String, Object], false, default: {}]
+ # ["options", Object, false, default: {}]
# ]
# desc: """
#
# """
+
def build: (model) ->
if isString(model) and constructor = @model?()
return constructor.find(model)
@@ -72,16 +61,15 @@ AS.Collection = AS.Object.extend ({def, include, delegate}) ->
data = _.clone(model)
ctor.new(data)
-
- # @::_add.doc =
+ # @::build.doc =
# private: true
# params: [
- # ["model", AS.Model, true]
- # ["options", Object, false, default: {}]
+ # ["model", [AS.Model, String, Object], true]
# ]
# desc: """
#
# """
+
def _add: (model, options={}) ->
options.at ?= this.length
index = options.at
@@ -95,25 +83,26 @@ AS.Collection = AS.Object.extend ({def, include, delegate}) ->
context: this
model.trigger "add", this, options
-
- # @::at.doc =
+ # @::_add.doc =
+ # private: true
# params: [
- # ["index", Number, true]
+ # ["model", AS.Model, true]
+ # ["options", Object, false, default: {}]
# ]
# desc: """
#
# """
+
def at: (index) ->
@models.value()[index]
-
- # @::remove.doc =
+ # @::at.doc =
# params: [
- # ["model", AS.Model, true]
- # ["options", Object, false, default: {}]
+ # ["index", Number, true]
# ]
# desc: """
#
# """
+
def remove: (model, options={}) ->
# Allow for passing both Model and ViewModels in
model = model.model
@@ -122,16 +111,15 @@ AS.Collection = AS.Object.extend ({def, include, delegate}) ->
model[@inverse].set(null) if @inverse
result
-
- # @::_remove.doc =
- # private: true
+ # @::remove.doc =
# params: [
# ["model", AS.Model, true]
- # ["options", {}, false, default: {}]
+ # ["options", Object, false, default: {}]
# ]
# desc: """
#
# """
+
def _remove: (model, options={}) ->
options.at = @models.indexOf(model).value()
@length--
@@ -142,7 +130,18 @@ AS.Collection = AS.Object.extend ({def, include, delegate}) ->
model.unbind
event: "all"
namespace: @objectId()
+ # @::_remove.doc =
+ # private: true
+ # params: [
+ # ["model", AS.Model, true]
+ # ["options", {}, false, default: {}]
+ # ]
+ # desc: """
+ #
+ # """
+ def filter: (filterBy) ->
+ AS.FilteredCollection.new(this, filterBy)
# @::filter.doc =
# params: [
# ["filterBy", {}, true]
@@ -151,9 +150,9 @@ AS.Collection = AS.Object.extend ({def, include, delegate}) ->
# desc: """
#
# """
- def filter: (filterBy) ->
- AS.FilteredCollection.new(this, filterBy)
+ def groupBy: (key, metaData) ->
+ AS.Models.Grouping.new(this, key, metaData)
# @::groupBy.doc =
# params: [
# ["key", String, true]
@@ -162,9 +161,13 @@ AS.Collection = AS.Object.extend ({def, include, delegate}) ->
# desc: """
#
# """
- def groupBy: (key, metaData) ->
- AS.Models.Grouping.new(this, key, metaData)
+ # # When an event is triggered from a model, it is bubbled up through the collection.
+ def _onModelEvent: (event, model, collection, options) ->
+ return unless isString(event)
+ return if (event is "add" or event is "remove") and (this isnt collection)
+ @_remove(model, options) if event is "destroy"
+ @trigger.apply(this, arguments)
# @::_onModelEvent.doc =
# private: true
# params: [
@@ -176,11 +179,5 @@ AS.Collection = AS.Object.extend ({def, include, delegate}) ->
# desc: """
#
# """
- # # When an event is triggered from a model, it is bubbled up through the collection.
- def _onModelEvent: (event, model, collection, options) ->
- return unless isString(event)
- return if (event is "add" or event is "remove") and (this isnt collection)
- @_remove(model, options) if event is "destroy"
- @trigger.apply(this, arguments)
# def pluck: (name) -> @map (item) -> item[name]()
View
58 ..._simprini/core/filtered_collection.coffee → ..._simprini/core/filtered_collection.coffee
@@ -11,21 +11,11 @@
# set: ->
# add: ->
# remove: ->
-AS = require "alpha_simprini"
-Taxi = require "taxi"
-{extend, isString, isFunction, isArray} = require "underscore"
+{extend, isString, isFunction, isArray} = _
AS.FilteredCollection = AS.Collection.extend ({delegate, include, def, defs}) ->
delegate 'add', 'remove', to: 'parent'
- # @::initialize.doc =
- # params: [
- # ["@parent", AS.Collection, true]
- # ["conditions", Object, false, default: {}]
- # ]
- # desc: """
- #
- # """
def initialize: (@parent, conditions={}) ->
@_super()
@@ -56,56 +46,57 @@ AS.FilteredCollection = AS.Collection.extend ({delegate, include, def, defs}) ->
namespace: @objectId()
@reFilter()
-
- # @::determinePlacementInSelf.doc =
+ # @::initialize.doc =
# params: [
- # ["model", AS.Model, true]
+ # ["@parent", AS.Collection, true]
+ # ["conditions", Object, false, default: {}]
# ]
# desc: """
#
# """
+
def determinePlacementInSelf: (model) ->
if @filter(model) is true
@addToSelf(model)
else
@removeFromSelf(model)
-
- # @::addToSelf.doc =
+ # @::determinePlacementInSelf.doc =
# params: [
- # [model, AS.Model, true]
+ # ["model", AS.Model, true]
# ]
# desc: """
#
# """
+
def addToSelf: (model) ->
return if @models.include(model).value()
@_add(model)
-
- # @::removeFromSelf.doc =
+ # @::addToSelf.doc =
# params: [
- # [model, AS.Modle, true]
+ # [model, AS.Model, true]
# ]
# desc: """
#
# """
+
def removeFromSelf: (model) ->
return unless @models.include(model).value()
@_remove(model)
-
- # @::reFilter.doc =
+ # @::removeFromSelf.doc =
+ # params: [
+ # [model, AS.Modle, true]
+ # ]
# desc: """
#
# """
+
def reFilter: ->
@parent.each (model) => @determinePlacementInSelf(model)
-
- # @::setConditions.doc =
- # params: [
- # ["conditions", Object, true]
- # ]
+ # @::reFilter.doc =
# desc: """
#
# """
+
def setConditions: (conditions) ->
@conditions.unbind()
@conditions.set(key, value) for key, value of conditions
@@ -114,14 +105,14 @@ AS.FilteredCollection = AS.Collection.extend ({delegate, include, def, defs}) ->
handler: @reFilter
context: this
@reFilter()
-
- # @::filter.doc =
+ # @::setConditions.doc =
# params: [
- # ["model", AS.Model, true]
+ # ["conditions", Object, true]
# ]
# desc: """
#
# """
+
def filter: (model) ->
for key, value of @conditions.toObject()
modelValue = model[key].get()
@@ -131,6 +122,13 @@ AS.FilteredCollection = AS.Collection.extend ({delegate, include, def, defs}) ->
return false unless modelValue in testValue
true
+ # @::filter.doc =
+ # params: [
+ # ["model", AS.Model, true]
+ # ]
+ # desc: """
+ #
+ # """
View
3 ...pha_simprini/core/instance_methods.coffee → ...pha_simprini/core/instance_methods.coffee
@@ -1,6 +1,3 @@
-AS = require("alpha_simprini")
-_ = require "underscore"
-
SKIP_METHODS = [
'objectId'
'readPath'
View
2 lib/alpha_simprini/core/logging.coffee → src/alpha_simprini/core/logging.coffee
@@ -1,5 +1,3 @@
-AS = require("alpha_simprini")
-
AS.warn = ->
console.warn.apply(console, arguments)
View
56 lib/alpha_simprini/core/model.coffee → src/alpha_simprini/core/model.coffee
@@ -1,6 +1,4 @@
-AS = require("alpha_simprini")
-{uniqueId, toArray, keys} = _ = require("underscore")
-Taxi = require("taxi")
+{uniqueId, toArray, keys} = _
AS.All = byCid: {}, byId: {}, byIdRef: {}
@@ -16,6 +14,8 @@ AS.Model = AS.Object.extend ({delegate, include, def, defs}) ->
'initialize'
]
+ defs find: (id) ->
+ AS.All.byId[id] or @new(id:id)
# @find.doc =
# params: [
# ["id", String, true]
@@ -25,16 +25,7 @@ AS.Model = AS.Object.extend ({delegate, include, def, defs}) ->
# If a model exsist by the `id` it is retrieved from an identity map.
# Otherwise a model is created with `id`.
# """
- defs find: (id) ->
- AS.All.byId[id] or @new(id:id)
- # @::initialize.doc =
- # params: [
- # ["attributes", Object, false, default: {}]
- # ]
- # desc: """
- #
- # """
def initialize: (attributes={}) ->
attributes.id ?= AS.uniq()
@model = this
@@ -43,19 +34,20 @@ AS.Model = AS.Object.extend ({delegate, include, def, defs}) ->
@setId(id)
@set(attributes)
@runCallbacks 'afterInitialize'
-
- # @::properties.doc =
+ # @::initialize.doc =
+ # params: [
+ # ["attributes", Object, false, default: {}]
+ # ]
# desc: """
+ #
# """
+
def properties: ->
@[name] for name in keys(@constructor.properties)
-
- # @::set.doc =
- # params: [
- # ["attributes", Object, true]
- # ]
+ # @::properties.doc =
# desc: """
# """
+
def set: (attributes) ->
for key, value of attributes
continue if key is "_type"
@@ -64,13 +56,13 @@ AS.Model = AS.Object.extend ({delegate, include, def, defs}) ->
else
property = @[key]
@[key]?.set(value)
-
- # @::setId.doc =
+ # @::set.doc =
# params: [
- # ["id", String, true]
+ # ["attributes", Object, true]
# ]
# desc: """
# """
+
def setId: (id) ->
if @id
delete AS.All.byId[@id]
@@ -86,23 +78,27 @@ AS.Model = AS.Object.extend ({delegate, include, def, defs}) ->
# Don't trigger 'change', this must be specifically listened for.
@trigger("change:id")
-
- # @::destroy.doc =
+ # @::setId.doc =
+ # params: [
+ # ["id", String, true]
+ # ]
# desc: """
# """
+
def destroy: ->
@trigger("destroy")
+ # @::destroy.doc =
+ # desc: """
+ # """
+ def trigger: ->
+ args = toArray(arguments)
+ args.splice(1, 0, this)
+ @_super.apply this, args
# @::trigger.doc =
# params: [
# ["event", String, true]
# ["..."]
# ]
# desc: """
# """
- def trigger: ->
- args = toArray(arguments)
- args.splice(1, 0, this)
- @_super.apply this, args
-
-
View
3 ...alpha_simprini/core/model/dendrite.coffee → ...alpha_simprini/core/model/dendrite.coffee
@@ -1,6 +1,3 @@
-AS = require "alpha_simprini"
-_ = require "underscore"
-
AS.Model.Dendrite = AS.Object.extend ({delegate, include, def, defs}) ->
def initialize: (@observer, @notifier, @config={}) ->
@callback = _.bind(@callback, this)
View
5 lib/alpha_simprini/core/model/rest.coffee → src/alpha_simprini/core/model/rest.coffee
@@ -1,7 +1,4 @@
-AS = require "alpha_simprini"
-{camelize, underscore, pluralize, singularize} = require "fleck"
-_ = require "underscore"
-$ = require "jquery"
+{camelize, underscore, pluralize, singularize} = fleck
convertKeys = (object) ->
converted = {}
View
5 lib/alpha_simprini/core/model/share.coffee → src/alpha_simprini/core/model/share.coffee
@@ -1,7 +1,6 @@
-AS = require "alpha_simprini"
-_ = require "underscore"
{keys} = _
-ShareJS = require("share").client
+require("share")
+ShareJS = share.client
AS.ShareJSURL = "http://#{window?.location.host or 'localhost'}/sjs"
View
4 lib/alpha_simprini/core/model/store.coffee → src/alpha_simprini/core/model/store.coffee
@@ -1,6 +1,4 @@
-AS = require("alpha_simprini")
-Taxi = require("taxi")
-{extend, clone} = require("underscore")
+{extend, clone} = _
AS.Model.Store = AS.Object.extend ({delegate, include, def, defs}) ->
include Taxi.Mixin
View
3 lib/alpha_simprini/core/model/synapse.coffee → src/alpha_simprini/core/model/synapse.coffee
@@ -1,6 +1,3 @@
-AS = require "alpha_simprini"
-_ = require "underscore"
-
AS.Model.AbstractSynapse = AS.Object.extend ({delegate, include, def, defs}) ->
defs create: (raw) ->
if raw.constructor.Synapse
View
35 lib/alpha_simprini/core/models/file.coffee → src/alpha_simprini/core/models/file.coffee
@@ -1,7 +1,4 @@
-AS = require "alpha_simprini"
-_ = require("underscore")
-$ = require "jquery"
-camelize = require("fleck").upperCamelize
+camelize = fleck.upperCamelize
AS.Models.File = AS.Model.extend ({delegate, include, def, defs}) ->
defs familyClasses: AS.Map.new(-> this)
@@ -52,10 +49,6 @@ AS.Models.File = AS.Model.extend ({delegate, include, def, defs}) ->
# konstructor = class_for_mime()
# # pass
- # @::initialize.doc =
- # desc: """
- #
- # """
def initialize: ->
@_super.apply(this, arguments)
if file = @file.get()
@@ -67,35 +60,39 @@ AS.Models.File = AS.Model.extend ({delegate, include, def, defs}) ->
# @mime MIME(image.attr "src")
# @name image.attr("title") or image.attr("alt") or $.url(image.attr("src")).attr("file") or "Untitled Image"
# @bytes 0
-
- # @::read.doc =
- # params: [
- # ["callback", Function, true]
- # ]
+ # @::initialize.doc =
# desc: """
#
# """
+
def read: (callback) ->
# return callback(@dataURL) if @dataURL
if @file.get()
@readFile(callback)
# else if @image()
# @readCanvas(callback)
-
- # @::readFile.doc =
+ # @::read.doc =
# params: [
# ["callback", Function, true]
# ]
# desc: """
#
# """
+
def readFile: (callback) ->
reader = new @FileReader
reader.onload = (event) ->
@dataURL = event.target.result
callback(@dataURL)
reader.readAsDataURL(@file.get())
callback
+ # @::readFile.doc =
+ # params: [
+ # ["callback", Function, true]
+ # ]
+ # desc: """
+ #
+ # """
# def readCanvas: (callback) ->
# image = new Image
@@ -110,10 +107,6 @@ AS.Models.File = AS.Model.extend ({delegate, include, def, defs}) ->
# console.warn "FIXME: portable image proxy port"
# image.src = "http://catalogs.dev/?proxy_uri=#{@image().src}"
- # @::upload.doc =
- # desc: """
- #
- # """
def upload: ->
formdata = new FormData
formdata.append "image[image]", @file.get()
@@ -128,6 +121,10 @@ AS.Models.File = AS.Model.extend ({delegate, include, def, defs}) ->
success: (data, status, xhr) =>
@url.set xhr.getResponseHeader("Location")
@trigger("uploaded")
+ # @::upload.doc =
+ # desc: """
+ #
+ # """
# Default File/FileReader implementaiton
# if unavailable you'll have to provide your own.
View
2 lib/alpha_simprini/core/models/group.coffee → src/alpha_simprini/core/models/group.coffee
@@ -1,5 +1,3 @@
-AS = require "alpha_simprini"
-
AS.Models.Group = AS.Model.extend ({delegate, include, def, defs}) ->
@property "metaData"
@field "name"
View
33 ...lpha_simprini/core/models/grouping.coffee → ...lpha_simprini/core/models/grouping.coffee
@@ -1,16 +1,6 @@
-AS = require "alpha_simprini"
AS.Models.Grouping = AS.Model.extend ({delegate, include, def, defs}) ->
@hasMany 'groups'
- # @::initialize.doc =
- # params: [
- # ["@backingCollection", AS.Collection, true]
- # ["@groupByProperty", String, true]
- # ["@metaData", Object, false, default: {}]
- # ]
- # desc: """
- #
- # """
def initialize: (@backingCollection, @groupByProperty, @metaData={}) ->
@_super()
@groupMap = AS.Map.new()
@@ -34,14 +24,16 @@ AS.Models.Grouping = AS.Model.extend ({delegate, include, def, defs}) ->
context: this
@backingCollection.each (item) => @addToGroup(item)
-
- # @::addToGroup.doc =
+ # @::initialize.doc =
# params: [
- # ["item", AS.Model, true]
+ # ["@backingCollection", AS.Collection, true]
+ # ["@groupByProperty", String, true]
+ # ["@metaData", Object, false, default: {}]
# ]
# desc: """
#
# """
+
def addToGroup: (item) ->
name = item[@groupByProperty].get()
unless group = @groupMap.get(name)
@@ -51,28 +43,35 @@ AS.Models.Grouping = AS.Model.extend ({delegate, include, def, defs}) ->
@itemMap.set item, group
group.members.add(item)
-
- # @::removeFromGroup.doc =
+ # @::addToGroup.doc =
# params: [
# ["item", AS.Model, true]
# ]
# desc: """
#
# """
+
def removeFromGroup: (item) ->
return unless group = @itemMap.get(item)
group.members.remove(item)
-
- # @::determineNewGroup.doc =
+ # @::removeFromGroup.doc =
# params: [
# ["item", AS.Model, true]
# ]
# desc: """
#
# """
+
def determineNewGroup: (item) ->
@removeFromGroup(item)
@addToGroup(item)
+ # @::determineNewGroup.doc =
+ # params: [
+ # ["item", AS.Model, true]
+ # ]
+ # desc: """
+ #
+ # """
# @currentUser.labors.groupBy "endDateGroup", (group) ->
# @text group.name
View
21 ...re/models/multiple_selection_model.coffee → ...re/models/multiple_selection_model.coffee
@@ -1,40 +1,39 @@
-AS = require "alpha_simprini"
AS.Models.MultipleSelectionModel = AS.Model.extend ({def}) ->
@hasMany "items"
- # @::initialize.doc =
- # desc: """
- #
- # """
def initialize: ->
@_super()
@items.bind "add", (item) => @trigger("add", item)
@items.bind "remove", (item) => @trigger("remove", item)
+ # @::initialize.doc =
+ # desc: """
+ #
+ # """
+ def select: (item) ->
+ @items.add(item)
# @::select.doc =
# params: [
# ["item", AS.Model, true]
# ]
# desc: """
#
# """
- def select: (item) ->
- @items.add(item)
+ def deselect: (item) ->
+ @items.remove(item)
# @::deselect.doc =
# params: [
# ["item", AS.Model, true]
# ]
# desc: """
#
# """
- def deselect: (item) ->
- @items.remove(item)
+ def clear: ->
+ @items.each @items.remove, @items
# @::clear.doc =
# desc: """
#
# """
- def clear: ->
- @items.each @items.remove, @items
View
21 .../core/models/radio_selection_model.coffee → .../core/models/radio_selection_model.coffee
@@ -1,29 +1,28 @@
-AS = require "alpha_simprini"
AS.Models.RadioSelectionModel = AS.Model.extend ({def}) ->
@property 'selected'
- # @::initialize.doc =
- # params: [
- # ["options", Object, false, default: {}]
- # ]
- # desc: """
- #
- # """
def initialize: (options={}) ->
@property = options.property
@_super()
@select undefined
-
- # @::select.doc =
+ # @::initialize.doc =
# params: [
- # ["item", "*", true]
+ # ["options", Object, false, default: {}]
# ]
# desc: """
#
# """
+
def select: (item) ->
if @property
@selected.get()?[@property].set(null)
item?[@property].set(true)
@selected.set(item)
+ # @::select.doc =
+ # params: [
+ # ["item", "*", true]
+ # ]
+ # desc: """
+ #
+ # """
View
3 ...imprini/core/properties/belongs_to.coffee → ...imprini/core/properties/belongs_to.coffee
@@ -1,6 +1,3 @@
-AS = require "alpha_simprini"
-_ = require "underscore"
-
AS.Model.BelongsTo = AS.Model.HasOne.extend()
AS.Model.BelongsTo.Instance = AS.Model.HasOne.Instance.extend ({delegate, include, def, defs}) ->
@Synapse = AS.Model.Field.Instance.Synapse.extend ({delegate, include, def, defs}) ->
View
50 ...pha_simprini/core/properties/field.coffee → ...pha_simprini/core/properties/field.coffee
@@ -1,6 +1,4 @@
-AS = require("alpha_simprini")
-_ = require("underscore")
-{isBoolean, isString} = require "underscore"
+{isBoolean, isString} = _
# TODO: Field is generic. reuse it.
@@ -54,6 +52,9 @@ AS.Model.Field = AS.Property.extend ({delegate, include, def, defs}) ->
Casters.set AS.Enum, AS.Enum
+ def initialize: (@name, @_constructor, @options={}) ->
+ @options.name = @name
+ @_constructor.writeInheritableValue 'properties', @name, this
# @::initialize.doc =
# params: [
# ["@name", String, true]
@@ -63,20 +64,19 @@ AS.Model.Field = AS.Property.extend ({delegate, include, def, defs}) ->
# desc: """
#
# """
- def initialize: (@name, @_constructor, @options={}) ->
- @options.name = @name
- @_constructor.writeInheritableValue 'properties', @name, this
+ def instance: (object) -> @constructor.Instance.new(object, @options)
# @::instance.doc =
# params: [
# ["object", AS.Model, true]
# ]
# desc: """
#
# """
- def instance: (object) -> @constructor.Instance.new(object, @options)
@Instance = AS.Property.Instance.extend ({def}) ->
+ def initialize: (@object, @options={}) ->
+ @options.type ?= String
# @::initialize.doc =
# params: [
# ["@object", AS.Model, true]
@@ -85,16 +85,7 @@ AS.Model.Field = AS.Property.extend ({delegate, include, def, defs}) ->
# desc: """
#
# """
- def initialize: (@object, @options={}) ->
- @options.type ?= String
- # @::syncWith.doc =
- # params: [
- # ["share", "ShareJS.Doc", true]
- # ]
- # desc: """
- #
- # """
def syncWith: (share) ->
@share = share.at(@options.name)
@share.set("") unless @share.get()?
@@ -105,33 +96,33 @@ AS.Model.Field = AS.Property.extend ({delegate, include, def, defs}) ->
@synapse.observe(@shareSynapse)
@synapse.notify(@shareSynapse)
-
- # @::stopSync.doc =
+ # @::syncWith.doc =
+ # params: [
+ # ["share", "ShareJS.Doc", true]
+ # ]
# desc: """
#
# """
+
def stopSync: ->
@synapse?.stopObserving()
@synapse?.stopNotifying()
-
- # @::get.doc =
- # return: "*"
+ # @::stopSync.doc =
# desc: """
#
# """
+
def get: ->
if @value isnt undefined
value = Casters.get(@options.type).read(@value, @options)
else
@options.default
-
- # @::set.doc =
- # params: [
- # ["value", "*", true]
- # ]
+ # @::get.doc =
+ # return: "*"
# desc: """
#
# """
+
def set: (value) ->
writeValue = Casters.get(@options.type).write(value, @options)
return @value if writeValue is @value
@@ -141,6 +132,13 @@ AS.Model.Field = AS.Property.extend ({delegate, include, def, defs}) ->
@trigger("change")
@triggerDependants()
@value
+ # @::set.doc =
+ # params: [
+ # ["value", "*", true]
+ # ]
+ # desc: """
+ #
+ # """
@Synapse = AS.Model.Synapse.extend ({delegate, include, def, defs}) ->
delegate 'get', 'set', to: 'raw'
View
73 ..._simprini/core/properties/has_many.coffee → ..._simprini/core/properties/has_many.coffee
@@ -1,45 +1,35 @@
-AS = require("alpha_simprini")
-_ = require("underscore")
-
AS.Model.HasMany = AS.Model.Field.extend ({delegate, include, def, defs}) ->
def couldBe: (test) ->
return true if @options.model?() in (test.ancestors or [])
@_super.apply(this, arguments)
AS.Model.HasMany.Instance = AS.Model.Field.Instance.extend ({def, delegate}) ->
delegate AS.COLLECTION_DELEGATES, to: "backingCollection"
- delegate 'groupBy', 'bind', 'trigger' 'unbind', to: "backingCollection"
+ delegate 'groupBy', 'bind', 'trigger', 'unbind', to: "backingCollection"
+ def inspect: ->
+ "#{@options.name}: [#{@backingCollection.length}]}"
# @::inspect.doc =
# return: String
# desc: """
#
# """
- def inspect: ->
- "#{@options.name}: [#{@backingCollection.length}]}"
- # @::initialize.doc =
- # params: [
- # ["@object", AS.Model, true]
- # ["@options", Obect, false, default: {}]
- # ]
- # desc: """
- #
- # """
def initialize: (@object, @options={}) ->
@model = @options.model
@options.source = @object if @options.inverse
@backingCollection = AS.Collection.new(undefined, @options)
@bind('change', (=> @triggerDependants()), this)
-
- # @::syncWith.doc =
+ # @::initialize.doc =
# params: [
- # ["share", "ShareJS.Doc", true]
+ # ["@object", AS.Model, true]
+ # ["@options", Obect, false, default: {}]
# ]
# desc: """
#
# """
+
def syncWith: (share) ->
console.log "syncWith", @toString()
@share = share.at(@options.name)
@@ -53,36 +43,47 @@ AS.Model.HasMany.Instance = AS.Model.Field.Instance.extend ({def, delegate}) ->
@synapse.observe(@shareSynapse)
_.each alreadyThere, (item) => @shareSynapse.insert(item, {})
@synapse.notify(@shareSynapse)
+ # @::syncWith.doc =
+ # params: [
+ # ["share", "ShareJS.Doc", true]
+ # ]
+ # desc: """
+ #
+ # """
+ def objects: ->
+ @backingCollection.models.value()
# @::objects.doc =
# return: [AS.Model]
# desc: """
#
# """
- def objects: ->
- @backingCollection.models.value()
+ def bindToPathSegment: (segment) ->
+ segment.binds this, "add", segment.insertCallback
+ segment.binds this, "remove", segment.removeCallback
# @::bindToPathSegment.doc =
# params: [
# ["segment", Taxi.Segment, true]
# ]
# desc: """
#
# """
- def bindToPathSegment: (segment) ->
- segment.binds this, "add", segment.insertCallback
- segment.binds this, "remove", segment.removeCallback
+ def set: (models) ->
+ @backingCollection.add(model) for model in models
# @::set.doc =
# params: [
- # ["models", [[AS.Model, String, Object], true]
+ # ["models", [[AS.Model, String, Object]], true]
# ]
# desc: """
#
# """
- def set: (models) ->
- @backingCollection.add(model) for model in models
+ def add: (model, options) ->
+ added = @backingCollection.add(model, options)
+ @triggerDependants()
+ return added
# @::add.doc =
# params: [
# ["model", AS.Model, true]
@@ -91,11 +92,8 @@ AS.Model.HasMany.Instance = AS.Model.Field.Instance.extend ({def, delegate}) ->
# desc: """
#
# """
- def add: (model, options) ->
- added = @backingCollection.add(model, options)
- @triggerDependants()
- return added
+ def at: (index) -> @backingCollection.at.apply(@backingCollection, arguments)
# @::at.doc =
# params: [
# ["index", Number, true]
@@ -104,8 +102,11 @@ AS.Model.HasMany.Instance = AS.Model.Field.Instance.extend ({def, delegate}) ->
# desc: """
#
# """
- def at: (index) -> @backingCollection.at.apply(@backingCollection, arguments)
+ def remove: (model) ->
+ removed = @backingCollection.remove.apply(@backingCollection, arguments)
+ @triggerDependants()
+ return removed
# @::remove.doc =
# params: [
# ["model", AS.Model, true]
@@ -114,11 +115,9 @@ AS.Model.HasMany.Instance = AS.Model.Field.Instance.extend ({def, delegate}) ->
# desc: """
#
# """
- def remove: (model) ->
- removed = @backingCollection.remove.apply(@backingCollection, arguments)
- @triggerDependants()
- return removed
+ def pluck: (key) ->
+ @map (item) -> item[key].get()
# @::pluc.doc =
# params: [
# ["key", String, true]
@@ -127,16 +126,14 @@ AS.Model.HasMany.Instance = AS.Model.Field.Instance.extend ({def, delegate}) ->
# desc: """
#
# """
- def pluck: (key) ->
- @map (item) -> item[key].get()
+ def any: ->
+ _.any @backingCollection
# @::any.doc =
# return: Boolean
# desc: """
#
# """
- def any: ->
- _.any @backingCollection
@Synapse = AS.Model.CollectionSynapse.extend ({delegate, include, def, defs}) ->
def insert: (item, options) ->
View
93 src/alpha_simprini/core/properties/has_one.coffee
@@ -0,0 +1,93 @@
+AS.Model.HasOne = AS.Model.Field.extend ({delegate, include, def, defs}) ->
+ def couldBe: (test) ->
+ return true if test in @options.model?().ancestors
+ @_super.apply(this, arguments)
+ # @::couldBe.doc =
+ # params: [
+ # ["test", undefined, true]
+ # ]
+ # desc: """
+ #
+ # """
+
+AS.Model.HasOne.Instance = AS.Model.Field.Instance.extend ({def}) ->
+ def initialize: (@object, @options) ->
+ @options.model ?= -> AS.Model
+ @model = @options.model
+ @namespace = ".#{_.uniqueId()}"
+ @_super.apply(this, arguments)
+ @bind "destroy", => @set(null)
+ # @::initialize.doc =
+ # params: [
+ # ["@object", AS.Model, true]
+ # ["@options", Object, true]
+ # ]
+ # desc: """
+ #
+ # """
+
+ def get: ->
+ @value
+ # @::get.doc =
+ # return: [AS.Model, null]
+ # desc: """
+ #
+ # """
+
+ def set: (value) ->
+ value = value.model if value?.model
+ return @value if value is @value
+
+ if _.isString(value) and (konstructor = @model()) isnt AS.Model
+ value = konstructor.find(value)
+ else if _.isString(value)
+ value = AS.All.byId[value]
+ else if value instanceof AS.Model
+ value = value
+ else if _.isObject(value)
+ value = @options.model().new(value)
+
+ @value?.unbind(@namespace)
+
+ # TODO: test inverse
+
+ if @value and @options.inverse and @value[@options.inverse]
+ @value[@options.inverse].remove(@object) if @value[@options.inverse].include(@object).value()
+
+ @value = value
+
+ if @value and @options.inverse and @value[@options.inverse]
+ @value[@options.inverse].add(@object) unless @value[@options.inverse].include(@object).value()
+
+ # this looks neccessory for path bindings, but not so good for view bindings yeesh
+ # @value?.bind "all#{@namespace}", _.bind(@trigger, this)
+
+ @object.trigger("change")
+ @object.trigger("change:#{@options.name}")
+ @trigger("change")
+ @triggerDependants()
+ @value
+ # @::set.doc =
+ # params: [
+ # ["value", AS.Model]
+ # ]
+ # desc: """
+ #
+ # """
+
+ @Syna