alpha-simprini-engine 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +38 -0
- data/app/assets/javascripts/alpha_simprini.coffee +15 -0
- data/app/assets/javascripts/alpha_simprini/application.coffee +22 -0
- data/app/assets/javascripts/alpha_simprini/coffee_kup/binding.coffee +119 -0
- data/app/assets/javascripts/alpha_simprini/coffee_kup/helpers.coffee +17 -0
- data/app/assets/javascripts/alpha_simprini/coffee_kup/tags.coffee +7 -0
- data/app/assets/javascripts/alpha_simprini/collection.coffee +62 -0
- data/app/assets/javascripts/alpha_simprini/delegate.coffee +21 -0
- data/app/assets/javascripts/alpha_simprini/event.coffee +75 -0
- data/app/assets/javascripts/alpha_simprini/html.coffee +56 -0
- data/app/assets/javascripts/alpha_simprini/mixin.coffee +10 -0
- data/app/assets/javascripts/alpha_simprini/model.coffee +137 -0
- data/app/assets/javascripts/alpha_simprini/models/radio_selection_model.coffee +9 -0
- data/app/assets/javascripts/alpha_simprini/packer.coffee +93 -0
- data/app/assets/javascripts/alpha_simprini/template_helpers.coffee +8 -0
- data/app/assets/javascripts/alpha_simprini/view.coffee +182 -0
- data/app/assets/javascripts/alpha_simprini/views/canvas.coffee +2 -0
- data/app/assets/javascripts/alpha_simprini/views/horizontal_split.coffee +9 -0
- data/app/assets/javascripts/alpha_simprini/views/panel.coffee +2 -0
- data/app/assets/javascripts/alpha_simprini/views/splitter.coffee +2 -0
- data/app/assets/javascripts/alpha_simprini/views/stage.coffee +7 -0
- data/app/assets/javascripts/alpha_simprini/views/vertical_split.coffee +8 -0
- data/app/assets/javascripts/alpha_simprini/views/viewport.coffee +0 -0
- data/app/assets/javascripts/bundle.js +16416 -0
- data/app/assets/javascripts/lib/backbone.coffee +11 -0
- data/app/assets/javascripts/lib/koffeecup_backbone_databind.coffee +25 -0
- data/app/assets/javascripts/lib/module.coffee +15 -0
- data/app/assets/javascripts/lib/state_machine.coffee +33 -0
- data/app/assets/javascripts/lib/string.coffee +13 -0
- data/app/assets/javascripts/qunit.js +1513 -0
- data/app/assets/javascripts/test.coffee +4 -0
- data/app/assets/javascripts/test/alpha_simprini/coffee_kup/binding.coffee +118 -0
- data/app/assets/javascripts/test/alpha_simprini/coffee_kup/helpers.coffee +10 -0
- data/app/assets/javascripts/test/alpha_simprini/coffee_kup/tags.coffee +18 -0
- data/app/assets/javascripts/test/alpha_simprini/collection.coffee +7 -0
- data/app/assets/javascripts/test/alpha_simprini/event.coffee +43 -0
- data/app/assets/javascripts/test/alpha_simprini/model.coffee +63 -0
- data/app/assets/javascripts/test/alpha_simprini/view.coffee +72 -0
- data/app/assets/javascripts/test/alpha_simprini/views/canvas.coffee +8 -0
- data/app/assets/javascripts/test/alpha_simprini/views/horizontal_split.coffee +13 -0
- data/app/assets/javascripts/test/alpha_simprini/views/vertical_split.coffee +13 -0
- data/app/assets/javascripts/test/backbone/collection.js +345 -0
- data/app/assets/javascripts/test/backbone/events.js +86 -0
- data/app/assets/javascripts/test/backbone/model.js +426 -0
- data/app/assets/javascripts/test/backbone/view.js +137 -0
- data/app/assets/stylesheets/bootstrap.sass +6 -0
- data/app/assets/stylesheets/paneling.sass +2 -0
- data/app/assets/stylesheets/qunit.scss +228 -0
- data/app/assets/stylesheets/table.sass +10 -0
- data/app/assets/stylesheets/typography.sass +19 -0
- data/app/controllers/alpha_simprini/test_controller.rb +3 -0
- data/app/controllers/resources_controller.rb +7 -0
- data/app/views/alpha_simprini/test/root.rb +13 -0
- data/app/views/resources/base.rb +2 -0
- data/app/views/resources/edit.rb +9 -0
- data/app/views/resources/form.rb +26 -0
- data/app/views/resources/index.rb +41 -0
- data/app/views/resources/new.rb +9 -0
- data/app/views/resources/show.rb +42 -0
- data/app/views/resources/show_has_many.rb +28 -0
- data/config/locales/en.yml +4 -0
- data/config/routes.rb +3 -0
- data/lib/alpha-simprini-engine.rb +33 -0
- data/lib/alpha-simprini-engine/version.rb +3 -0
- data/lib/alpha_simprini/directive_processor.rb +77 -0
- data/lib/alpha_simprini/packer.rb +161 -0
- data/lib/alpha_simprini/page.rb +37 -0
- data/lib/tasks/alpha-simprini-engine_tasks.rake +4 -0
- data/test/alpha-simprini-engine_test.rb +7 -0
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/assets/javascripts/application.js +9 -0
- data/test/dummy/app/assets/stylesheets/application.css +7 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +42 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +27 -0
- data/test/dummy/config/environments/production.rb +51 -0
- data/test/dummy/config/environments/test.rb +39 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/inflections.rb +10 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +4 -0
- data/test/dummy/config/routes.rb +58 -0
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/log/development.log +800 -0
- data/test/dummy/public/404.html +26 -0
- data/test/dummy/public/422.html +26 -0
- data/test/dummy/public/500.html +26 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +6 -0
- data/test/dummy/tmp/cache/assets/C24/D70/sprockets%2F388a550030239f3784f207fa32954f64 +0 -0
- data/test/dummy/tmp/cache/assets/C34/620/sprockets%2F097ee8532856d48d70420c006f475889 +0 -0
- data/test/dummy/tmp/cache/assets/C6F/710/sprockets%2F908d18b0f21c18dad508851126164a41 +0 -0
- data/test/dummy/tmp/cache/assets/CA7/120/sprockets%2F35278a6c0150c40394fe02629c8b0eb9 +0 -0
- data/test/dummy/tmp/cache/assets/CDB/A80/sprockets%2F443b1c6e71b482fdd83b1833b7e27712 +0 -0
- data/test/dummy/tmp/cache/assets/CE3/FB0/sprockets%2F6d3f87a4232e0368bb86760780c5f1bd +0 -0
- data/test/dummy/tmp/cache/assets/D1C/160/sprockets%2F87876f7e55ebc78ae11c6c08a27f0605 +0 -0
- data/test/dummy/tmp/cache/assets/D26/6C0/sprockets%2F65bce2254bb3140a50326ea1654ea5df +0 -0
- data/test/dummy/tmp/cache/assets/D26/FA0/sprockets%2F1f50f59148df5f3e2ab889df381d9744 +0 -0
- data/test/dummy/tmp/cache/assets/D36/220/sprockets%2F841654b01d89eada195d7d1fe10b57b0 +0 -0
- data/test/dummy/tmp/cache/assets/D47/410/sprockets%2Ff1fe319eb4064bd5b861ac28f7d76555 +18122 -0
- data/test/dummy/tmp/cache/assets/D57/1E0/sprockets%2Fe267e3e1059799c429e4f5cfb95ec53c +0 -0
- data/test/dummy/tmp/cache/assets/D64/3E0/sprockets%2Fb49b7f8034b81ec601bc32fb127fbe08 +0 -0
- data/test/dummy/tmp/cache/assets/D65/850/sprockets%2F7a9b6a0e2d51adb43a1d3f859213e6b8 +15469 -0
- data/test/dummy/tmp/cache/assets/D6C/E30/sprockets%2Fcc7322b05ac2bef75e9f4f145d38117f +0 -0
- data/test/dummy/tmp/cache/assets/D7D/E00/sprockets%2Fce33b82451c73df1cfec69928b4f77b6 +0 -0
- data/test/dummy/tmp/cache/assets/D85/5D0/sprockets%2Fcf743946c378c148b19ce78eeaa9cc75 +0 -0
- data/test/dummy/tmp/cache/assets/DBB/560/sprockets%2F5a1d70cf7dd81a5ab5ce7a40a3a38d06 +0 -0
- data/test/dummy/tmp/cache/assets/DC1/670/sprockets%2Fefdfad0542298a1db90d24dc27ecc250 +0 -0
- data/test/dummy/tmp/cache/assets/DC5/1E0/sprockets%2F7517f22ad0f9dc13b8f0f6e0cc0e5de2 +0 -0
- data/test/dummy/tmp/cache/assets/DCC/220/sprockets%2F28d953c6ab9cc9a7db15600aabc6d77d +208 -0
- data/test/dummy/tmp/cache/assets/DCF/DF0/sprockets%2Ff0d3068f05825e1dfd9f5aaba946d3dc +0 -0
- data/test/dummy/tmp/cache/assets/DD3/0E0/sprockets%2F3e9e08a334bae7deadb5335f5e4f195f +0 -0
- data/test/dummy/tmp/cache/assets/DDB/980/sprockets%2Fbd2abc80a17c901e2f497f88f9be58cf +0 -0
- data/test/dummy/tmp/cache/assets/E00/ED0/sprockets%2Ffecf3bffeb200a47e96bd04cbc878076 +1535 -0
- data/test/dummy/tmp/cache/assets/EFB/560/sprockets%2Fbca0daf751c020cdeddabbefa51cb6ea +0 -0
- data/test/dummy/tmp/restart.txt +0 -0
- data/test/test_helper.rb +10 -0
- metadata +326 -0
@@ -0,0 +1,10 @@
|
|
1
|
+
# BITCHIN SWEET CoffeeScript/_ Mixin capability
|
2
|
+
module "AS", ->
|
3
|
+
class @Mixin
|
4
|
+
extends: (klass) ->
|
5
|
+
_.extend klass, @class_methods if @class_methods
|
6
|
+
_.extend klass::, @instance_methods if @instance_methods
|
7
|
+
@mixed_in.call(klass) if @mixed_in
|
8
|
+
|
9
|
+
constructor: (methods) ->
|
10
|
+
_.extend this, methods
|
@@ -0,0 +1,137 @@
|
|
1
|
+
module "AS", ->
|
2
|
+
@All =
|
3
|
+
byId: {}
|
4
|
+
byCid: {}
|
5
|
+
|
6
|
+
class @Model
|
7
|
+
AS.Event.extends(this)
|
8
|
+
|
9
|
+
@has_many: (name, config) ->
|
10
|
+
@relation(name)
|
11
|
+
(@has_manys ?= {})[name] = config
|
12
|
+
@field(name)
|
13
|
+
|
14
|
+
@has_one: (name, config) ->
|
15
|
+
@relation(name)
|
16
|
+
(@has_ones ?= {})[name] = config
|
17
|
+
|
18
|
+
@::[name] = (value) ->
|
19
|
+
if value is undefined
|
20
|
+
AS.All.byCid[@get_attribute(name)]
|
21
|
+
else
|
22
|
+
if value.cid
|
23
|
+
@set_attribute(name, value.cid)
|
24
|
+
else if _.isString(value)
|
25
|
+
@set_attribute(name, value)
|
26
|
+
else
|
27
|
+
if value._type
|
28
|
+
model = module(value._type)
|
29
|
+
else
|
30
|
+
model = AS.Model
|
31
|
+
@set_attribute name, (new model value).cid
|
32
|
+
|
33
|
+
@belongs_to: (name, config) ->
|
34
|
+
@relation(name)
|
35
|
+
(@belongs_tos ?= {})[name] = config
|
36
|
+
|
37
|
+
@::[name] = (value) ->
|
38
|
+
if value is undefined
|
39
|
+
AS.All.byCid[@get_attribute(name)]
|
40
|
+
else
|
41
|
+
if value.cid
|
42
|
+
@set_attribute(name, value.cid)
|
43
|
+
else if _.isString(value)
|
44
|
+
@set_attribute(name, value)
|
45
|
+
else
|
46
|
+
throw new Error(["Cannot set #{name} to unexpected value. Try passing a cid, or an object with a cid. Value was: ", value])
|
47
|
+
|
48
|
+
@relation: (name) ->
|
49
|
+
(@relations ?= []).push name
|
50
|
+
|
51
|
+
@field: (name, options={}) ->
|
52
|
+
# Reflection
|
53
|
+
@fields ?= {}
|
54
|
+
@fields[name] = options
|
55
|
+
|
56
|
+
# options.type ?= String
|
57
|
+
# options.type = Model.FieldTypes[option.type.name]
|
58
|
+
@::[name] = (value) ->
|
59
|
+
if value is undefined
|
60
|
+
@get_attribute(name)
|
61
|
+
else
|
62
|
+
@set_attribute(name, value)
|
63
|
+
|
64
|
+
@initialize_relations: (model) ->
|
65
|
+
|
66
|
+
constructor: (@attributes = {}) ->
|
67
|
+
@initialize()
|
68
|
+
|
69
|
+
initialize: () ->
|
70
|
+
@previous_attributes = @attributes
|
71
|
+
@id = @attributes.id
|
72
|
+
@cid = @id or _.uniqueId("c")
|
73
|
+
|
74
|
+
AS.All.byCid[@cid] = AS.All.byId[@id] = this
|
75
|
+
|
76
|
+
@initialize_has_many(name, config) for name, config of @constructor.has_manys
|
77
|
+
@initialize_has_one(name, config) for name, config of @constructor.has_ones
|
78
|
+
@initialize_belongs_to(name, config) for name, config of @constructor.belongs_tos
|
79
|
+
|
80
|
+
last: (attr) ->
|
81
|
+
[@attributes, @previous_attributes] = [@previous_attributes, @attributes]
|
82
|
+
last = @[attr]()
|
83
|
+
[@attributes, @previous_attributes] = [@previous_attributes, @attributes]
|
84
|
+
last
|
85
|
+
|
86
|
+
|
87
|
+
initialize_has_many: (name, config) ->
|
88
|
+
data = {}
|
89
|
+
class this["#{name}_collection_klass"] extends AS.Collection
|
90
|
+
this["#{name}_collection_klass"].model = -> config.model() if config.model
|
91
|
+
data[name] = new this["#{name}_collection_klass"](@[name]?())
|
92
|
+
@set data
|
93
|
+
|
94
|
+
initialize_has_one: (name, config) ->
|
95
|
+
@[name](@attributes[name])
|
96
|
+
|
97
|
+
initialize_belongs_to: (name, config) ->
|
98
|
+
# pass; not sure you have to do anything, this should be properly set already.
|
99
|
+
|
100
|
+
save: () ->
|
101
|
+
return false unless @changed()
|
102
|
+
@persist()
|
103
|
+
true
|
104
|
+
|
105
|
+
# Persisted is a callback here.
|
106
|
+
# Actual persistance will be handled by an observer. DEAL WITH IT IF YOU WANT IT.
|
107
|
+
persisted: ->
|
108
|
+
@previous_attributes = @attributes
|
109
|
+
|
110
|
+
changes: () ->
|
111
|
+
changed = {}
|
112
|
+
for key, value of @attributes
|
113
|
+
changed[key] = value unless @previous_attributes[value] is value
|
114
|
+
changed
|
115
|
+
|
116
|
+
# Blessed be backbone
|
117
|
+
changed: () -> _(@changes).chain().keys().any().value()
|
118
|
+
|
119
|
+
get: (attr) -> @[attr]()
|
120
|
+
|
121
|
+
set: (attrs) ->
|
122
|
+
@[key](value) for key, value of attrs
|
123
|
+
@trigger("change")
|
124
|
+
|
125
|
+
set_attribute: (name, value) ->
|
126
|
+
@attributes[name] = value
|
127
|
+
@trigger("change:#{name}")
|
128
|
+
value
|
129
|
+
|
130
|
+
get_attribute: (name) ->
|
131
|
+
@attributes?[name]
|
132
|
+
|
133
|
+
destroy: () ->
|
134
|
+
@trigger("destroy")
|
135
|
+
|
136
|
+
trigger: () ->
|
137
|
+
AS.Event.instance_methods.trigger.apply this, _(arguments).splice(1, 0, this)
|
@@ -0,0 +1,93 @@
|
|
1
|
+
module "AS.Heap", ->
|
2
|
+
@CLASS = 0x11
|
3
|
+
@ATTRIBUTES = 0x12
|
4
|
+
@CLASSES = 0x13
|
5
|
+
@OBJECTS = 0x14
|
6
|
+
@NAMED_OBJECTS = 0x15
|
7
|
+
@LITERALS = 0x16
|
8
|
+
|
9
|
+
class @NullClass
|
10
|
+
constructor: ->
|
11
|
+
|
12
|
+
@Classes =
|
13
|
+
PackedClass: Function
|
14
|
+
Array: Array
|
15
|
+
Numeric: Number
|
16
|
+
Fixnum: Number
|
17
|
+
String: String
|
18
|
+
Symbol: String
|
19
|
+
Hash: Object
|
20
|
+
NilClass: null
|
21
|
+
FalseClass: false
|
22
|
+
TrueClass: true
|
23
|
+
|
24
|
+
class @Unpacker
|
25
|
+
constructor: (hash) ->
|
26
|
+
@literals = hash[AS.Heap.LITERALS]
|
27
|
+
@classes = {}
|
28
|
+
|
29
|
+
for key, value of hash[AS.Heap.CLASSES]
|
30
|
+
@classes[value] = @resolve_class(key)
|
31
|
+
|
32
|
+
@packed_objects = hash[AS.Heap.OBJECTS]
|
33
|
+
@objects = {}
|
34
|
+
@named_objects = {}
|
35
|
+
|
36
|
+
@unpack_object(key) for key, value of @packed_objects
|
37
|
+
|
38
|
+
for key, value of hash[AS.Heap.NAMED_OBJECTS]
|
39
|
+
@named_objects[@unpack_object(key)] = @unpack_object(value)
|
40
|
+
|
41
|
+
resolve_class: (key) ->
|
42
|
+
unless (klass = AS.Heap.Classes[key]) is undefined
|
43
|
+
klass
|
44
|
+
else
|
45
|
+
throw new Error("Unresolved class with key #{key}")
|
46
|
+
|
47
|
+
|
48
|
+
allocate_object: (klass) ->
|
49
|
+
eval("function #{klass.name} () {this.constructor = klass; }")
|
50
|
+
ctor = eval klass.name
|
51
|
+
ctor.prototype = klass.prototype
|
52
|
+
ctor.__super__ = klass.__super__
|
53
|
+
object = new ctor
|
54
|
+
|
55
|
+
unpack_object: (key) ->
|
56
|
+
return @objects[key] if @objects[key]
|
57
|
+
value = @packed_objects[key]
|
58
|
+
attributes = value[AS.Heap.ATTRIBUTES]
|
59
|
+
klass = @classes[value[AS.Heap.CLASS]]
|
60
|
+
if klass == Object
|
61
|
+
object = @objects[key] = {}
|
62
|
+
for _key, _value of attributes
|
63
|
+
object[@unpack_object(_key)] = @unpack_object(_value)
|
64
|
+
object
|
65
|
+
# else if klass == Function
|
66
|
+
# console.log "FUCTIONCLASS", klass, @unpack_object(value)
|
67
|
+
else if klass == Array
|
68
|
+
@objects[key] = @unpack_object(item) for item in attributes
|
69
|
+
else if klass == Number
|
70
|
+
@objects[key] = @literals[attributes]
|
71
|
+
else if klass == String
|
72
|
+
@objects[key] = @literals[attributes]
|
73
|
+
else if klass == null
|
74
|
+
@objects[key] = null
|
75
|
+
else if klass == true
|
76
|
+
@objects[key] = true
|
77
|
+
else if klass == false
|
78
|
+
@objects[key] = false
|
79
|
+
else
|
80
|
+
object = @objects[key] = @allocate_object(klass)
|
81
|
+
for _key, _value of attributes
|
82
|
+
object[@unpack_object(_key).replace(/^@/, '')] = @unpack_object(_value)
|
83
|
+
object
|
84
|
+
|
85
|
+
# FIXME: TESTCASE
|
86
|
+
# class ThingClass
|
87
|
+
#
|
88
|
+
# constructor: (@ace, @b, @c, @t) ->
|
89
|
+
#
|
90
|
+
# AS.Heap.Classes.Thing = ThingClass
|
91
|
+
#
|
92
|
+
# 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"]}
|
93
|
+
# window.up=new AS.Heap.Unpacker(d)
|
@@ -0,0 +1,182 @@
|
|
1
|
+
# module "AS", ->
|
2
|
+
# class: (value) ->
|
3
|
+
# @el.removeClass(@prior)
|
4
|
+
# @el.addClass(value)
|
5
|
+
# @prior = value
|
6
|
+
#
|
7
|
+
# default: (value) ->
|
8
|
+
# @el.attr(value)
|
9
|
+
#
|
10
|
+
# class BindableElement
|
11
|
+
#
|
12
|
+
# constructor: (args) ->
|
13
|
+
# # body...
|
14
|
+
#
|
15
|
+
module "AS", ->
|
16
|
+
class @View extends @HTML
|
17
|
+
AS.Event.extends(this)
|
18
|
+
|
19
|
+
tag_name: "div"
|
20
|
+
|
21
|
+
_ensure_element: -> @el ?= $(@build_element())
|
22
|
+
|
23
|
+
constructor: (config={}) ->
|
24
|
+
@cid = _.uniqueId("c")
|
25
|
+
_.extend this, config
|
26
|
+
@_ensure_element()
|
27
|
+
@delegateEvents()
|
28
|
+
@initialize()
|
29
|
+
|
30
|
+
initialize: ->
|
31
|
+
|
32
|
+
binding: (model, field, fn) ->
|
33
|
+
if fn
|
34
|
+
model.bind "change:#{field}.#{@cid}", fn
|
35
|
+
fn() # call in place so data rendered now
|
36
|
+
else
|
37
|
+
content = $ @text -> model[field]()
|
38
|
+
model.bind "change:#{field}.#{@cid}", -> content.text model[field]()
|
39
|
+
|
40
|
+
# bind_style: () ->
|
41
|
+
#
|
42
|
+
#
|
43
|
+
# bind_attribute: (emitter, event, ) ->
|
44
|
+
#
|
45
|
+
|
46
|
+
unbind_from_collection: (collection) ->
|
47
|
+
$(@current_node).empty()
|
48
|
+
collection.unbind(".#{@cid}")
|
49
|
+
|
50
|
+
bind_to_selection_collection: (selection_model, collection, fn) ->
|
51
|
+
container = @current_node
|
52
|
+
|
53
|
+
selection_model.bind "change:selected", =>
|
54
|
+
selection = selection_model.selected()
|
55
|
+
previous_selection = selection_model.last('selected')
|
56
|
+
|
57
|
+
if previous_selection
|
58
|
+
@within_node container, ->
|
59
|
+
@unbind_from_collection previous_selection[collection]()
|
60
|
+
|
61
|
+
if selection
|
62
|
+
@within_node container, ->
|
63
|
+
@bind_to_collection selection[collection](), fn
|
64
|
+
|
65
|
+
bind_to_collection: (collection, fn) ->
|
66
|
+
byCid = {}
|
67
|
+
content_fn = (item) =>
|
68
|
+
byCid[item.cid] = $ fn.call(this, item)
|
69
|
+
|
70
|
+
container = $ @current_node
|
71
|
+
|
72
|
+
collection.models.each content_fn
|
73
|
+
|
74
|
+
collection.bind "add.#{@cid}", (item) =>
|
75
|
+
content = @dangling_content -> content_fn(item)
|
76
|
+
index = collection.indexOf(item).value()
|
77
|
+
siblings = container.children()
|
78
|
+
if siblings.get(0) is undefined or siblings.get(index) is undefined
|
79
|
+
container.append(content)
|
80
|
+
else
|
81
|
+
$(siblings.get(index)).before(content)
|
82
|
+
|
83
|
+
collection.bind "remove.#{@cid}", (item) =>
|
84
|
+
byCid[item.cid].remove()
|
85
|
+
delete byCid[item.cid]
|
86
|
+
|
87
|
+
klass_string: (parts=[]) ->
|
88
|
+
if @constructor is AS.View
|
89
|
+
parts.push "ASView"
|
90
|
+
parts.reverse().join " "
|
91
|
+
else
|
92
|
+
parts.push @constructor.name
|
93
|
+
@constructor.__super__.klass_string.call @constructor.__super__, parts
|
94
|
+
|
95
|
+
element_string: ->
|
96
|
+
base = "#{@tagName}.#{@klass_string()}"
|
97
|
+
|
98
|
+
if @model and @model.cid
|
99
|
+
base += "##{@model.cid}"
|
100
|
+
|
101
|
+
if @model and @model.constructor.name
|
102
|
+
base += ".#{@model.constructor.name}"
|
103
|
+
|
104
|
+
base
|
105
|
+
|
106
|
+
base_attributes: ->
|
107
|
+
attrs =
|
108
|
+
class: @klass_string()
|
109
|
+
id: @cid
|
110
|
+
|
111
|
+
build_element: ->
|
112
|
+
@current_node = @[@tag_name](@base_attributes())
|
113
|
+
|
114
|
+
event_splitter: /^(@?[\w:]+)(\{.*\})?\s*(.*)$/
|
115
|
+
|
116
|
+
delegateEvents: (events) ->
|
117
|
+
events ?= @events
|
118
|
+
events = events.call(this) if _.isFunction(events)
|
119
|
+
for key, method of events
|
120
|
+
if _.isString method
|
121
|
+
options = {}
|
122
|
+
else
|
123
|
+
options = method
|
124
|
+
method = options.method
|
125
|
+
delete options.method
|
126
|
+
|
127
|
+
throw new Error("Event \"#{events[key]}\" does not exist") unless method = @[method]
|
128
|
+
|
129
|
+
match = key.match @event_splitter
|
130
|
+
[__, event_name, guard, selector] = match
|
131
|
+
event_name += ".delegateEvents#{@cid}"
|
132
|
+
guard ?= "{}"
|
133
|
+
guard = guard.replace(/(\w+):/g, (__, match) -> "\"#{match}\":")
|
134
|
+
guard = JSON.parse(guard)
|
135
|
+
|
136
|
+
|
137
|
+
do (event_name, guard, key, method, options, selector) =>
|
138
|
+
_method = (event) =>
|
139
|
+
for key, value of guard
|
140
|
+
return unless event[key] is value
|
141
|
+
method.apply(this, arguments)
|
142
|
+
if selector is ''
|
143
|
+
@el.unbind event_name
|
144
|
+
@el.bind event_name, _method, options
|
145
|
+
else if selector[0] is '@'
|
146
|
+
@[selector.slice(1)]?.unbind event_name
|
147
|
+
@[selector.slice(1)]?.bind event_name, _method
|
148
|
+
else
|
149
|
+
$(selector, @el[0]).die event_name
|
150
|
+
$(selector, @el[0]).live event_name, _method, options
|
151
|
+
|
152
|
+
reset_cycle: (args...) ->
|
153
|
+
delete @_cycles[args.join()] if @_cycles
|
154
|
+
|
155
|
+
cycle: (args...) ->
|
156
|
+
@_cycles ?= {}
|
157
|
+
@_cycles[args.join()] ?= 0
|
158
|
+
count = @_cycles[args.join()] += 1
|
159
|
+
args[count % args.length]
|
160
|
+
|
161
|
+
toggle: ->
|
162
|
+
@button class:"toggle expand"
|
163
|
+
@button class:"toggle collapse"
|
164
|
+
|
165
|
+
field: (_label, options = {}, fn = ->) ->
|
166
|
+
if _.isFunction options
|
167
|
+
fn = options
|
168
|
+
options = {}
|
169
|
+
|
170
|
+
@div ->
|
171
|
+
@label _label
|
172
|
+
@input(options)
|
173
|
+
fn?.call(this)
|
174
|
+
|
175
|
+
choice: (_label, options = {}, fn = ->) ->
|
176
|
+
if _.isFunction options
|
177
|
+
fn = options
|
178
|
+
options = {}
|
179
|
+
options.type = "checkbox"
|
180
|
+
|
181
|
+
@field _label, options, fn
|
182
|
+
|