cornerstone-source 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. data/.gitignore +22 -0
  2. data/Gemfile +4 -0
  3. data/LICENSE +22 -0
  4. data/README.md +20 -0
  5. data/Rakefile +8 -0
  6. data/config.rb +79 -0
  7. data/config.ru +4 -0
  8. data/cornerstone.gemspec +22 -0
  9. data/doc_scraper.rb +51 -0
  10. data/game.js +4293 -0
  11. data/lib/assets/javascripts/cornerstone.js +4719 -0
  12. data/lib/cornerstone.rb +11 -0
  13. data/lib/cornerstone/rails.rb +5 -0
  14. data/lib/cornerstone/sprockets.rb +2 -0
  15. data/lib/cornerstone/version.rb +3 -0
  16. data/manifest.json +15 -0
  17. data/pixie.json +12 -0
  18. data/source/javascripts/_cornerstone/_object_extensions.js.coffee +108 -0
  19. data/source/javascripts/_cornerstone/array_extensions.js.coffee +570 -0
  20. data/source/javascripts/_cornerstone/bindable.js.coffee +125 -0
  21. data/source/javascripts/_cornerstone/command_stack.js.coffee +36 -0
  22. data/source/javascripts/_cornerstone/core_object.js.coffee +183 -0
  23. data/source/javascripts/_cornerstone/function_extensions.js.coffee +60 -0
  24. data/source/javascripts/_cornerstone/logging.js.coffee +19 -0
  25. data/source/javascripts/_cornerstone/matrix.js.coffee +337 -0
  26. data/source/javascripts/_cornerstone/number_extensions.js.coffee +491 -0
  27. data/source/javascripts/_cornerstone/point.js.coffee +641 -0
  28. data/source/javascripts/_cornerstone/random.js.coffee +86 -0
  29. data/source/javascripts/_cornerstone/rectangle.js.coffee +35 -0
  30. data/source/javascripts/_cornerstone/string_extensions.js.coffee +232 -0
  31. data/source/javascripts/_cornerstone/stubs.js.coffee +1042 -0
  32. data/source/javascripts/_cornerstone/uuid.js +96 -0
  33. data/source/javascripts/_test/array_extensions.coffee +173 -0
  34. data/source/javascripts/_test/bindable.coffee +68 -0
  35. data/source/javascripts/_test/command_stack.coffee +99 -0
  36. data/source/javascripts/_test/core_object.coffee +95 -0
  37. data/source/javascripts/_test/function_extensions.coffee +50 -0
  38. data/source/javascripts/_test/logging.coffee +7 -0
  39. data/source/javascripts/_test/matrix.coffee +174 -0
  40. data/source/javascripts/_test/number_extensions.coffee +138 -0
  41. data/source/javascripts/_test/object_extensions.coffee +53 -0
  42. data/source/javascripts/_test/point.coffee +196 -0
  43. data/source/javascripts/_test/random.coffee +22 -0
  44. data/source/javascripts/_test/rectangle.coffee +70 -0
  45. data/source/javascripts/_test/string_extensions.coffee +59 -0
  46. data/source/javascripts/cornerstone.js.coffee +1 -0
  47. data/source/javascripts/cornerstone_tests.js.coffee +2 -0
  48. data/source/test.html.haml +13 -0
  49. data/vendor/javascripts/qunit.js +1275 -0
  50. data/vendor/stylesheets/qunit.css.sass +115 -0
  51. metadata +141 -0
@@ -0,0 +1,96 @@
1
+ /*!
2
+ Math.uuid.js (v1.4)
3
+ http://www.broofa.com
4
+ mailto:robert@broofa.com
5
+
6
+ Copyright (c) 2010 Robert Kieffer
7
+ Dual licensed under the MIT and GPL licenses.
8
+ */
9
+
10
+ /**
11
+ Generate a random uuid.
12
+
13
+ <code><pre>
14
+ // No arguments - returns RFC4122, version 4 ID
15
+ Math.uuid()
16
+ => "92329D39-6F5C-4520-ABFC-AAB64544E172"
17
+
18
+ // One argument - returns ID of the specified length
19
+ Math.uuid(15) // 15 character ID (default base=62)
20
+ => "VcydxgltxrVZSTV"
21
+
22
+ // Two arguments - returns ID of the specified length, and radix. (Radix must be <= 62)
23
+ Math.uuid(8, 2) // 8 character ID (base=2)
24
+ => "01001010"
25
+
26
+ Math.uuid(8, 10) // 8 character ID (base=10)
27
+ => "47473046"
28
+
29
+ Math.uuid(8, 16) // 8 character ID (base=16)
30
+ => "098F4D35"
31
+ </pre></code>
32
+
33
+ @name uuid
34
+ @methodOf Math
35
+ @param length The desired number of characters
36
+ @param radix The number of allowable values for each character.
37
+ */
38
+ (function() {
39
+ // Private array of chars to use
40
+ var CHARS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('');
41
+
42
+ Math.uuid = function (len, radix) {
43
+ var chars = CHARS, uuid = [];
44
+ radix = radix || chars.length;
45
+
46
+ if (len) {
47
+ // Compact form
48
+ for (var i = 0; i < len; i++) uuid[i] = chars[0 | Math.random()*radix];
49
+ } else {
50
+ // rfc4122, version 4 form
51
+ var r;
52
+
53
+ // rfc4122 requires these characters
54
+ uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';
55
+ uuid[14] = '4';
56
+
57
+ // Fill in random data. At i==19 set the high bits of clock sequence as
58
+ // per rfc4122, sec. 4.1.5
59
+ for (var i = 0; i < 36; i++) {
60
+ if (!uuid[i]) {
61
+ r = 0 | Math.random()*16;
62
+ uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r];
63
+ }
64
+ }
65
+ }
66
+
67
+ return uuid.join('');
68
+ };
69
+
70
+ // A more performant, but slightly bulkier, RFC4122v4 solution. We boost performance
71
+ // by minimizing calls to random()
72
+ Math.uuidFast = function() {
73
+ var chars = CHARS, uuid = new Array(36), rnd=0, r;
74
+ for (var i = 0; i < 36; i++) {
75
+ if (i==8 || i==13 || i==18 || i==23) {
76
+ uuid[i] = '-';
77
+ } else if (i==14) {
78
+ uuid[i] = '4';
79
+ } else {
80
+ if (rnd <= 0x02) rnd = 0x2000000 + (Math.random()*0x1000000)|0;
81
+ r = rnd & 0xf;
82
+ rnd = rnd >> 4;
83
+ uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r];
84
+ }
85
+ }
86
+ return uuid.join('');
87
+ };
88
+
89
+ // A more compact, but less performant, RFC4122v4 solution:
90
+ Math.uuidCompact = function() {
91
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
92
+ var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
93
+ return v.toString(16);
94
+ }).toUpperCase();
95
+ };
96
+ })();
@@ -0,0 +1,173 @@
1
+ module "Array"
2
+
3
+ test "#average", ->
4
+ equals [1, 3, 5, 7].average(), 4
5
+
6
+ test "#compact", ->
7
+ a = [0, 1, undefined, 2, null, 3, '', 4]
8
+
9
+ compacted = a.compact()
10
+
11
+ equals(compacted[0], 0)
12
+ equals(compacted[1], 1)
13
+ equals(compacted[2], 2)
14
+ equals(compacted[3], 3)
15
+ equals(compacted[4], '')
16
+ equals(compacted[5], 4)
17
+
18
+ test "#copy", ->
19
+ a = [1,2,3]
20
+ b = a.copy()
21
+
22
+ ok a != b, "Original array is not the same array as the copied one"
23
+ ok a.length == b.length, "Both arrays are the same size"
24
+ ok a[0] == b[0] && a[1] == b[1] && a[2] == b[2], "The elements of the two arrays are equal"
25
+
26
+ test "#flatten", ->
27
+ array = [[0,1], [2,3], [4,5]]
28
+
29
+ flattenedArray = array.flatten()
30
+
31
+ equals flattenedArray.length, 6, "Flattened array length should equal number of elements in sub-arrays"
32
+ equals flattenedArray.first(), 0, "First element should be first element in first sub-array"
33
+ equals flattenedArray.last(), 5, "Last element should be last element in last sub-array"
34
+
35
+ test "#rand", ->
36
+ array = [1,2,3]
37
+
38
+ ok array.indexOf(array.rand()) != -1, "Array includes randomly selected element"
39
+ ok [5].rand() == 5, "[5].rand() === 5"
40
+ ok [].rand() == undefined, "[].rand() === undefined"
41
+
42
+ test "#remove", ->
43
+ equals [1,2,3].remove(2), 2, "[1,2,3].remove(2) === 2"
44
+ equals [1,3].remove(2), undefined, "[1,3].remove(2) === undefined"
45
+ equals [1,3].remove(3), 3, "[1,3].remove(3) === 3"
46
+
47
+ array = [1,2,3]
48
+ array.remove(2)
49
+ ok array.length == 2, "array = [1,2,3]; array.remove(2); array.length === 2"
50
+ array.remove(3)
51
+ ok array.length == 1, "array = [1,3]; array.remove(3); array.length === 1"
52
+
53
+ test "#map", ->
54
+ equals [1].map((x) -> return x + 1 )[0], 2
55
+
56
+ test "#invoke", ->
57
+ results = ['hello', 'world', 'cool!'].invoke('substring', 0, 3)
58
+
59
+ equals results[0], "hel"
60
+ equals results[1], "wor"
61
+ equals results[2], "coo"
62
+
63
+ test "#each", ->
64
+ array = [1, 2, 3]
65
+ count = 0
66
+
67
+ equals array, array.each -> count++
68
+ equals array.length, count
69
+
70
+ test "#eachPair", ->
71
+ array = [1, 2, 3]
72
+ sum = 0
73
+
74
+ array.eachPair (a, b) ->
75
+ sum += a + b
76
+
77
+ equals(sum, 12)
78
+
79
+ test "#eachWithObject", ->
80
+ array = [1, 2, 3]
81
+
82
+ result = array.eachWithObject {}, (element, hash) ->
83
+ hash[element] = (element + 1).toString()
84
+
85
+ equals result[1], "2"
86
+ equals result[2], "3"
87
+ equals result[3], "4"
88
+
89
+ test "#shuffle", ->
90
+ array = [0, 1, 2, 3, 4, 5]
91
+
92
+ shuffledArray = array.shuffle()
93
+
94
+ shuffledArray.each (element) ->
95
+ ok array.indexOf(element) >= 0, "Every element in shuffled array is in orig array"
96
+
97
+ array.each (element) ->
98
+ ok shuffledArray.indexOf(element) >= 0, "Every element in orig array is in shuffled array"
99
+
100
+ test "#first", ->
101
+ equals [2].first(), 2
102
+ equals [1, 2, 3].first(), 1
103
+ equals [].first(), undefined
104
+
105
+ test "#last", ->
106
+ equals [2].last(), 2
107
+ equals [1, 2, 3].last(), 3
108
+ equals [].first(), undefined
109
+
110
+ test "#extremes", ->
111
+ array = [-7, 1, 11, 94]
112
+
113
+ extremes = array.extremes()
114
+
115
+ equals extremes.min, -7, "Min is -7"
116
+ equals extremes.max, 94, "Max is 94"
117
+
118
+ extremes = array.extremes (value) ->
119
+ value.mod 11
120
+
121
+ equals extremes.min, 11
122
+ equals extremes.max, 94
123
+
124
+ test "#sum", ->
125
+ equals [].sum(), 0, "Empty array sums to zero"
126
+ equals [2].sum(), 2, "[2] sums to 2"
127
+ equals [1, 2, 3, 4, 5].sum(), 15, "[1, 2, 3, 4, 5] sums to 15"
128
+
129
+ test "#eachSlice", 6, ->
130
+ [1, 2, 3, 4, 5, 6].eachSlice 2, (array) ->
131
+ equals array[0] % 2, 1
132
+ equals array[1] % 2, 0
133
+
134
+ test "#without", ->
135
+ array = [1, 2, 3, 4]
136
+
137
+ excluded = array.without([2, 4])
138
+
139
+ equals excluded[0], 1
140
+ equals excluded[1], 3
141
+
142
+ test "#clear", ->
143
+ array = [1, 2, 3, 4]
144
+
145
+ equals array.length, 4
146
+ equals array[0], 1
147
+
148
+ array.clear()
149
+
150
+ equals array.length, 0
151
+ equals array[0], undefined
152
+
153
+ test "#wrap", ->
154
+ array = [0, 1, 2, 3, 4]
155
+
156
+ equals array.wrap(0), 0
157
+ equals array.wrap(-1), 4
158
+ equals array.wrap(2), 2
159
+
160
+ test "#zip", ->
161
+ a = [1, 2, 3]
162
+ b = [4, 5, 6]
163
+ c = [7, 8]
164
+
165
+ output = a.zip(b, c)
166
+
167
+ equals output[0][0], 1
168
+ equals output[0][1], 4
169
+ equals output[0][2], 7
170
+
171
+ equals output[2][2], undefined
172
+
173
+ module undefined
@@ -0,0 +1,68 @@
1
+ module "Bindable"
2
+
3
+ test "#bind and #trigger", 1, ->
4
+ o = Core().include("Bindable")
5
+
6
+ o.bind("test", -> ok true)
7
+
8
+ o.trigger("test")
9
+
10
+ test "Multiple bindings", 2, ->
11
+ o = Core().include(Bindable)
12
+
13
+ o.bind("test", -> ok true)
14
+ o.bind("test", -> ok true)
15
+
16
+ o.trigger("test")
17
+
18
+ test "#trigger arguments", ->
19
+ o = Core().include(Bindable)
20
+
21
+ param1 = "the message"
22
+ param2 = 3
23
+
24
+ o.bind "test", (p1, p2) ->
25
+ equal(p1, param1)
26
+ equal(p2, param2)
27
+
28
+ o.trigger "test", param1, param2
29
+
30
+ test "#unbind", ->
31
+ o = Core().include("Bindable")
32
+
33
+ callback = ->
34
+ ok false
35
+
36
+ o.bind "test", callback
37
+ # Unbind specific event
38
+ o.unbind "test", callback
39
+ o.trigger "test"
40
+
41
+ o.bind "test", callback
42
+ # Unbind all events
43
+ o.unbind "test"
44
+ o.trigger "test"
45
+
46
+ test "#trigger namespace", 1, ->
47
+ o = Core().include("Bindable")
48
+ o.bind "test.TestNamespace", ->
49
+ ok true
50
+
51
+ o.trigger "test"
52
+
53
+ o.unbind ".TestNamespace"
54
+ o.trigger "test"
55
+
56
+ test "#unbind namespaced", 1, ->
57
+ o = Core().include("Bindable")
58
+
59
+ o.bind "test.TestNamespace", ->
60
+ ok true
61
+
62
+ o.trigger "test"
63
+
64
+ o.unbind ".TestNamespace", ->
65
+ o.trigger "test"
66
+
67
+ module()
68
+
@@ -0,0 +1,99 @@
1
+ module "CommandStack"
2
+
3
+ test "undo on an empty stack returns undefined", ->
4
+ commandStack = CommandStack()
5
+
6
+ equals commandStack.undo(), undefined
7
+
8
+ test "redo on an empty stack returns undefined", ->
9
+ commandStack = CommandStack()
10
+
11
+ equals commandStack.redo(), undefined
12
+
13
+ test "executes commands", 1, ->
14
+ command =
15
+ execute: ->
16
+ ok true, "command executed"
17
+
18
+ commandStack = CommandStack()
19
+
20
+ commandStack.execute command
21
+
22
+ test "can undo", 1, ->
23
+ command =
24
+ execute: ->
25
+ undo: ->
26
+ ok true, "command executed"
27
+
28
+ commandStack = CommandStack()
29
+ commandStack.execute command
30
+
31
+ commandStack.undo()
32
+
33
+ test "can redo", 2, ->
34
+ command =
35
+ execute: ->
36
+ ok true, "command executed"
37
+ undo: ->
38
+
39
+ commandStack = CommandStack()
40
+ commandStack.execute command
41
+
42
+ commandStack.undo()
43
+ commandStack.redo()
44
+
45
+ test "executes redone command once on redo", 4, ->
46
+ command =
47
+ execute: ->
48
+ ok true, "command executed"
49
+ undo: ->
50
+
51
+ commandStack = CommandStack()
52
+ commandStack.execute command
53
+
54
+ commandStack.undo()
55
+ commandStack.redo()
56
+
57
+ equals commandStack.redo(), undefined
58
+ equals commandStack.redo(), undefined
59
+
60
+ test "command is returned when undone", ->
61
+ command =
62
+ execute: ->
63
+ undo: ->
64
+
65
+ commandStack = CommandStack()
66
+ commandStack.execute command
67
+
68
+ equals commandStack.undo(), command, "Undone command is returned"
69
+
70
+ test "command is returned when redone", ->
71
+ command =
72
+ execute: ->
73
+ undo: ->
74
+
75
+ commandStack = CommandStack()
76
+ commandStack.execute command
77
+ commandStack.undo()
78
+
79
+ equals commandStack.redo(), command, "Redone command is returned"
80
+
81
+ test "cannot redo an obsolete future", ->
82
+ Command = ->
83
+ execute: ->
84
+ undo: ->
85
+
86
+ commandStack = CommandStack()
87
+ commandStack.execute Command()
88
+ commandStack.execute Command()
89
+
90
+ commandStack.undo()
91
+ commandStack.undo()
92
+
93
+ equals commandStack.canRedo(), true
94
+
95
+ commandStack.execute Command()
96
+
97
+ equals commandStack.canRedo(), false
98
+
99
+ module()
@@ -0,0 +1,95 @@
1
+ module "Core"
2
+
3
+ test "#extend", ->
4
+ o = Core()
5
+
6
+ o.extend
7
+ test: "jawsome"
8
+
9
+ equals o.test, "jawsome"
10
+
11
+ test "#attrAccessor", ->
12
+ o = Core
13
+ test: "my_val"
14
+
15
+ o.attrAccessor("test")
16
+
17
+ equals o.test(), "my_val"
18
+ equals o.test("new_val"), o
19
+ equals o.test(), "new_val"
20
+
21
+ test "#attrReader", ->
22
+ o = Core
23
+ test: "my_val"
24
+
25
+ o.attrReader("test")
26
+
27
+ equals o.test(), "my_val"
28
+ equals o.test("new_val"), "my_val"
29
+ equals o.test(), "my_val"
30
+
31
+ test "#include", ->
32
+ o = Core
33
+ test: "my_val"
34
+
35
+ M = (I, self) ->
36
+ self.attrReader "test"
37
+
38
+ test2: "cool"
39
+
40
+ ret = o.include M
41
+
42
+ equals ret, o, "Should return self"
43
+
44
+ equals o.test(), "my_val"
45
+ equals o.test2, "cool"
46
+
47
+ test "#include same module twice", 1, ->
48
+ window.M = (I, self) ->
49
+ ok(true)
50
+
51
+ test: true
52
+
53
+ o = Core()
54
+
55
+ o.include(M)
56
+ o.include(M)
57
+
58
+ test "#include multiple", ->
59
+ o = Core
60
+ test: "my_val"
61
+
62
+ M = (I, self) ->
63
+ self.attrReader "test"
64
+
65
+ test2: "cool"
66
+
67
+ M2 = (I, self) ->
68
+ test2: "coolio"
69
+
70
+ o.include M, M2
71
+
72
+ equals o.test2, "coolio"
73
+
74
+ test "#include string", ->
75
+ window.TestM = (I, self) ->
76
+ self.attrReader "test"
77
+
78
+ test2: "cool"
79
+
80
+ o = Core
81
+ test: "my_val"
82
+
83
+ o.include "TestM"
84
+
85
+ equals o.test(), "my_val"
86
+
87
+ test "#send", ->
88
+ o = Core
89
+ test: true
90
+
91
+ o.send("attrAccessor", "test")
92
+
93
+ ok(o.test())
94
+
95
+ module undefined