keydown 0.7.1 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (137) hide show
  1. data/.gitignore +2 -0
  2. data/.travis.yml +3 -0
  3. data/LICENSE +1 -1
  4. data/README.md +16 -15
  5. data/VERSION +1 -1
  6. data/keydown.gemspec +9 -6
  7. data/lib/keydown.rb +9 -22
  8. data/lib/keydown/html_helpers.rb +12 -0
  9. data/lib/keydown/{lib/slide.rb → slide.rb} +16 -19
  10. data/lib/keydown/{lib/slidedeck.rb → slidedeck.rb} +20 -5
  11. data/lib/keydown/tasks.rb +5 -0
  12. data/lib/keydown/tasks/base.rb +15 -0
  13. data/lib/keydown/tasks/generate.rb +5 -1
  14. data/lib/keydown/tasks/slides.rb +1 -1
  15. data/lib/version.rb +1 -1
  16. data/spec/lib/html_helpers_spec.rb +26 -0
  17. data/spec/lib/slide_spec.rb +29 -17
  18. data/spec/lib/slidedeck_spec.rb +41 -13
  19. data/spec/spec_helper.rb +2 -6
  20. data/spec/tasks/generate_spec.rb +41 -20
  21. data/spec/tasks/slides_spec.rb +83 -44
  22. data/templates/deck.js/code.html.haml +1 -0
  23. data/templates/deck.js/index.html.haml +54 -0
  24. data/templates/deck.js/slide.html.haml +6 -0
  25. data/templates/generate/css/%presentation_name%.css +12 -1
  26. data/templates/generate/deck.js/core/deck.core.css +394 -0
  27. data/templates/generate/deck.js/core/deck.core.js +461 -0
  28. data/templates/generate/deck.js/core/deck.core.scss +432 -0
  29. data/templates/generate/deck.js/extensions/codemirror/CONTRIBUTORS.txt +2 -0
  30. data/templates/generate/deck.js/extensions/codemirror/MIT-LICENSE.txt +21 -0
  31. data/templates/generate/deck.js/extensions/codemirror/README.md +120 -0
  32. data/templates/generate/deck.js/extensions/codemirror/VERSION.txt +1 -0
  33. data/templates/generate/deck.js/extensions/codemirror/codemirror.js +21 -0
  34. data/templates/generate/deck.js/extensions/codemirror/deck.codemirror.css +89 -0
  35. data/templates/generate/deck.js/extensions/codemirror/deck.codemirror.js +213 -0
  36. data/templates/generate/deck.js/extensions/codemirror/deck.codemirror.scss +107 -0
  37. data/templates/generate/deck.js/extensions/codemirror/mode/clike/clike.js +247 -0
  38. data/templates/generate/deck.js/extensions/codemirror/mode/clike/index.html +102 -0
  39. data/templates/generate/deck.js/extensions/codemirror/mode/clojure/clojure.js +207 -0
  40. data/templates/generate/deck.js/extensions/codemirror/mode/clojure/index.html +85 -0
  41. data/templates/generate/deck.js/extensions/codemirror/mode/coffeescript/LICENSE +22 -0
  42. data/templates/generate/deck.js/extensions/codemirror/mode/coffeescript/coffeescript.js +325 -0
  43. data/templates/generate/deck.js/extensions/codemirror/mode/coffeescript/index.html +722 -0
  44. data/templates/generate/deck.js/extensions/codemirror/mode/css/css.js +124 -0
  45. data/templates/generate/deck.js/extensions/codemirror/mode/css/index.html +56 -0
  46. data/templates/generate/deck.js/extensions/codemirror/mode/diff/diff.css +3 -0
  47. data/templates/generate/deck.js/extensions/codemirror/mode/diff/diff.js +13 -0
  48. data/templates/generate/deck.js/extensions/codemirror/mode/diff/index.html +99 -0
  49. data/templates/generate/deck.js/extensions/codemirror/mode/haskell/haskell.js +242 -0
  50. data/templates/generate/deck.js/extensions/codemirror/mode/haskell/index.html +60 -0
  51. data/templates/generate/deck.js/extensions/codemirror/mode/htmlmixed/htmlmixed.js +79 -0
  52. data/templates/generate/deck.js/extensions/codemirror/mode/htmlmixed/index.html +52 -0
  53. data/templates/generate/deck.js/extensions/codemirror/mode/javascript/index.html +78 -0
  54. data/templates/generate/deck.js/extensions/codemirror/mode/javascript/javascript.js +348 -0
  55. data/templates/generate/deck.js/extensions/codemirror/mode/lua/index.html +72 -0
  56. data/templates/generate/deck.js/extensions/codemirror/mode/lua/lua.js +138 -0
  57. data/templates/generate/deck.js/extensions/codemirror/mode/php/index.html +49 -0
  58. data/templates/generate/deck.js/extensions/codemirror/mode/php/php.js +115 -0
  59. data/templates/generate/deck.js/extensions/codemirror/mode/plsql/index.html +63 -0
  60. data/templates/generate/deck.js/extensions/codemirror/mode/plsql/plsql.js +217 -0
  61. data/templates/generate/deck.js/extensions/codemirror/mode/python/LICENSE.txt +21 -0
  62. data/templates/generate/deck.js/extensions/codemirror/mode/python/index.html +123 -0
  63. data/templates/generate/deck.js/extensions/codemirror/mode/python/python.js +321 -0
  64. data/templates/generate/deck.js/extensions/codemirror/mode/r/LICENSE +24 -0
  65. data/templates/generate/deck.js/extensions/codemirror/mode/r/index.html +74 -0
  66. data/templates/generate/deck.js/extensions/codemirror/mode/r/r.js +141 -0
  67. data/templates/generate/deck.js/extensions/codemirror/mode/rst/index.html +526 -0
  68. data/templates/generate/deck.js/extensions/codemirror/mode/rst/rst.css +75 -0
  69. data/templates/generate/deck.js/extensions/codemirror/mode/rst/rst.js +333 -0
  70. data/templates/generate/deck.js/extensions/codemirror/mode/ruby/LICENSE +24 -0
  71. data/templates/generate/deck.js/extensions/codemirror/mode/ruby/index.html +172 -0
  72. data/templates/generate/deck.js/extensions/codemirror/mode/ruby/ruby.js +195 -0
  73. data/templates/generate/deck.js/extensions/codemirror/mode/scheme/index.html +65 -0
  74. data/templates/generate/deck.js/extensions/codemirror/mode/scheme/scheme.js +202 -0
  75. data/templates/generate/deck.js/extensions/codemirror/mode/smalltalk/index.html +56 -0
  76. data/templates/generate/deck.js/extensions/codemirror/mode/smalltalk/smalltalk.js +122 -0
  77. data/templates/generate/deck.js/extensions/codemirror/mode/sparql/index.html +41 -0
  78. data/templates/generate/deck.js/extensions/codemirror/mode/sparql/sparql.js +143 -0
  79. data/templates/generate/deck.js/extensions/codemirror/mode/stex/index.html +96 -0
  80. data/templates/generate/deck.js/extensions/codemirror/mode/stex/stex.js +167 -0
  81. data/templates/generate/deck.js/extensions/codemirror/mode/velocity/index.html +103 -0
  82. data/templates/generate/deck.js/extensions/codemirror/mode/velocity/velocity.js +146 -0
  83. data/templates/generate/deck.js/extensions/codemirror/mode/xml/index.html +42 -0
  84. data/templates/generate/deck.js/extensions/codemirror/mode/xml/xml.js +231 -0
  85. data/templates/generate/deck.js/extensions/codemirror/mode/xmlpure/index.html +60 -0
  86. data/templates/generate/deck.js/extensions/codemirror/mode/xmlpure/xmlpure.js +481 -0
  87. data/templates/generate/deck.js/extensions/codemirror/mode/yaml/index.html +68 -0
  88. data/templates/generate/deck.js/extensions/codemirror/mode/yaml/yaml.js +95 -0
  89. data/templates/generate/deck.js/extensions/codemirror/themes/cobalt.css +17 -0
  90. data/templates/generate/deck.js/extensions/codemirror/themes/default.css +19 -0
  91. data/templates/generate/deck.js/extensions/codemirror/themes/elegant.css +9 -0
  92. data/templates/generate/deck.js/extensions/codemirror/themes/neat.css +8 -0
  93. data/templates/generate/deck.js/extensions/codemirror/themes/night.css +20 -0
  94. data/templates/generate/deck.js/extensions/goto/deck.goto.css +41 -0
  95. data/templates/generate/deck.js/extensions/goto/deck.goto.html +6 -0
  96. data/templates/generate/deck.js/extensions/goto/deck.goto.js +118 -0
  97. data/templates/generate/deck.js/extensions/goto/deck.goto.scss +46 -0
  98. data/templates/generate/deck.js/extensions/hash/deck.hash.css +13 -0
  99. data/templates/generate/deck.js/extensions/hash/deck.hash.html +2 -0
  100. data/templates/generate/deck.js/extensions/hash/deck.hash.js +125 -0
  101. data/templates/generate/deck.js/extensions/hash/deck.hash.scss +15 -0
  102. data/templates/generate/deck.js/extensions/menu/deck.menu.css +24 -0
  103. data/templates/generate/deck.js/extensions/menu/deck.menu.js +127 -0
  104. data/templates/generate/deck.js/extensions/menu/deck.menu.scss +29 -0
  105. data/templates/generate/deck.js/extensions/navigation/deck.navigation.css +43 -0
  106. data/templates/generate/deck.js/extensions/navigation/deck.navigation.html +3 -0
  107. data/templates/generate/deck.js/extensions/navigation/deck.navigation.js +83 -0
  108. data/templates/generate/deck.js/extensions/navigation/deck.navigation.scss +56 -0
  109. data/templates/generate/deck.js/extensions/scale/deck.scale.css +16 -0
  110. data/templates/generate/deck.js/extensions/scale/deck.scale.js +155 -0
  111. data/templates/generate/deck.js/extensions/scale/deck.scale.scss +17 -0
  112. data/templates/generate/deck.js/extensions/status/deck.status.css +14 -0
  113. data/templates/generate/deck.js/extensions/status/deck.status.html +6 -0
  114. data/templates/generate/deck.js/extensions/status/deck.status.js +42 -0
  115. data/templates/generate/deck.js/extensions/status/deck.status.scss +16 -0
  116. data/templates/generate/deck.js/support/jquery.1.6.4.min.js +4 -0
  117. data/templates/generate/deck.js/support/modernizr.custom.js +4 -0
  118. data/templates/generate/deck.js/themes/style/neon.css +114 -0
  119. data/templates/generate/deck.js/themes/style/neon.scss +139 -0
  120. data/templates/generate/deck.js/themes/style/swiss.css +75 -0
  121. data/templates/generate/deck.js/themes/style/swiss.scss +91 -0
  122. data/templates/generate/deck.js/themes/style/web-2.0.css +187 -0
  123. data/templates/generate/deck.js/themes/style/web-2.0.scss +214 -0
  124. data/templates/generate/deck.js/themes/transition/fade.css +44 -0
  125. data/templates/generate/deck.js/themes/transition/fade.scss +70 -0
  126. data/templates/generate/deck.js/themes/transition/horizontal-slide.css +79 -0
  127. data/templates/generate/deck.js/themes/transition/horizontal-slide.scss +94 -0
  128. data/templates/generate/deck.js/themes/transition/vertical-slide.css +97 -0
  129. data/templates/generate/deck.js/themes/transition/vertical-slide.scss +116 -0
  130. data/templates/keydown.css.erb +27 -23
  131. metadata +171 -32
  132. data/Gemfile.lock +0 -41
  133. data/templates/generate/css/rocks.css +0 -392
  134. data/templates/generate/css/syntax_highlighting.css +0 -135
  135. data/templates/generate/js/rocks.js +0 -419
  136. data/templates/rocks/index.rhtml +0 -132
  137. data/templates/rocks/slide.rhtml +0 -10
@@ -0,0 +1,722 @@
1
+ <!doctype html>
2
+ <html>
3
+ <head>
4
+ <title>CodeMirror 2: CoffeeScript mode</title>
5
+ <link rel="stylesheet" href="../../lib/codemirror.css">
6
+ <script src="../../lib/codemirror.js"></script>
7
+ <script src="coffeescript.js"></script>
8
+ <link rel="stylesheet" href="../../theme/default.css">
9
+ <style>.CodeMirror {border-top: 1px solid silver; border-bottom: 1px solid silver;}</style>
10
+ <link rel="stylesheet" href="../../css/docs.css">
11
+ </head>
12
+ <body>
13
+ <h1>CodeMirror 2: CoffeeScript mode</h1>
14
+ <form><textarea id="code" name="code">
15
+ # CoffeeScript mode for CodeMirror
16
+ # Copyright (c) 2011 Jeff Pickhardt, released under
17
+ # the MIT License.
18
+ #
19
+ # Modified from the Python CodeMirror mode, which also is
20
+ # under the MIT License Copyright (c) 2010 Timothy Farrell.
21
+ #
22
+ # The following script, Underscore.coffee, is used to
23
+ # demonstrate CoffeeScript mode for CodeMirror.
24
+ #
25
+ # To download CoffeeScript mode for CodeMirror, go to:
26
+ # https://github.com/pickhardt/coffeescript-codemirror-mode
27
+
28
+ # **Underscore.coffee
29
+ # (c) 2011 Jeremy Ashkenas, DocumentCloud Inc.**
30
+ # Underscore is freely distributable under the terms of the
31
+ # [MIT license](http://en.wikipedia.org/wiki/MIT_License).
32
+ # Portions of Underscore are inspired by or borrowed from
33
+ # [Prototype.js](http://prototypejs.org/api), Oliver Steele's
34
+ # [Functional](http://osteele.com), and John Resig's
35
+ # [Micro-Templating](http://ejohn.org).
36
+ # For all details and documentation:
37
+ # http://documentcloud.github.com/underscore/
38
+
39
+
40
+ # Baseline setup
41
+ # --------------
42
+
43
+ # Establish the root object, `window` in the browser, or `global` on the server.
44
+ root = this
45
+
46
+
47
+ # Save the previous value of the `_` variable.
48
+ previousUnderscore = root._
49
+
50
+
51
+ # Establish the object that gets thrown to break out of a loop iteration.
52
+ # `StopIteration` is SOP on Mozilla.
53
+ breaker = if typeof(StopIteration) is 'undefined' then '__break__' else StopIteration
54
+
55
+
56
+ # Helper function to escape **RegExp** contents, because JS doesn't have one.
57
+ escapeRegExp = (string) -> string.replace(/([.*+?^${}()|[\]\/\\])/g, '\\$1')
58
+
59
+
60
+ # Save bytes in the minified (but not gzipped) version:
61
+ ArrayProto = Array.prototype
62
+ ObjProto = Object.prototype
63
+
64
+
65
+ # Create quick reference variables for speed access to core prototypes.
66
+ slice = ArrayProto.slice
67
+ unshift = ArrayProto.unshift
68
+ toString = ObjProto.toString
69
+ hasOwnProperty = ObjProto.hasOwnProperty
70
+ propertyIsEnumerable = ObjProto.propertyIsEnumerable
71
+
72
+
73
+ # All **ECMA5** native implementations we hope to use are declared here.
74
+ nativeForEach = ArrayProto.forEach
75
+ nativeMap = ArrayProto.map
76
+ nativeReduce = ArrayProto.reduce
77
+ nativeReduceRight = ArrayProto.reduceRight
78
+ nativeFilter = ArrayProto.filter
79
+ nativeEvery = ArrayProto.every
80
+ nativeSome = ArrayProto.some
81
+ nativeIndexOf = ArrayProto.indexOf
82
+ nativeLastIndexOf = ArrayProto.lastIndexOf
83
+ nativeIsArray = Array.isArray
84
+ nativeKeys = Object.keys
85
+
86
+
87
+ # Create a safe reference to the Underscore object for use below.
88
+ _ = (obj) -> new wrapper(obj)
89
+
90
+
91
+ # Export the Underscore object for **CommonJS**.
92
+ if typeof(exports) != 'undefined' then exports._ = _
93
+
94
+
95
+ # Export Underscore to global scope.
96
+ root._ = _
97
+
98
+
99
+ # Current version.
100
+ _.VERSION = '1.1.0'
101
+
102
+
103
+ # Collection Functions
104
+ # --------------------
105
+
106
+ # The cornerstone, an **each** implementation.
107
+ # Handles objects implementing **forEach**, arrays, and raw objects.
108
+ _.each = (obj, iterator, context) ->
109
+ try
110
+ if nativeForEach and obj.forEach is nativeForEach
111
+ obj.forEach iterator, context
112
+ else if _.isNumber obj.length
113
+ iterator.call context, obj[i], i, obj for i in [0...obj.length]
114
+ else
115
+ iterator.call context, val, key, obj for own key, val of obj
116
+ catch e
117
+ throw e if e isnt breaker
118
+ obj
119
+
120
+
121
+ # Return the results of applying the iterator to each element. Use JavaScript
122
+ # 1.6's version of **map**, if possible.
123
+ _.map = (obj, iterator, context) ->
124
+ return obj.map(iterator, context) if nativeMap and obj.map is nativeMap
125
+ results = []
126
+ _.each obj, (value, index, list) ->
127
+ results.push iterator.call context, value, index, list
128
+ results
129
+
130
+
131
+ # **Reduce** builds up a single result from a list of values. Also known as
132
+ # **inject**, or **foldl**. Uses JavaScript 1.8's version of **reduce**, if possible.
133
+ _.reduce = (obj, iterator, memo, context) ->
134
+ if nativeReduce and obj.reduce is nativeReduce
135
+ iterator = _.bind iterator, context if context
136
+ return obj.reduce iterator, memo
137
+ _.each obj, (value, index, list) ->
138
+ memo = iterator.call context, memo, value, index, list
139
+ memo
140
+
141
+
142
+ # The right-associative version of **reduce**, also known as **foldr**. Uses
143
+ # JavaScript 1.8's version of **reduceRight**, if available.
144
+ _.reduceRight = (obj, iterator, memo, context) ->
145
+ if nativeReduceRight and obj.reduceRight is nativeReduceRight
146
+ iterator = _.bind iterator, context if context
147
+ return obj.reduceRight iterator, memo
148
+ reversed = _.clone(_.toArray(obj)).reverse()
149
+ _.reduce reversed, iterator, memo, context
150
+
151
+
152
+ # Return the first value which passes a truth test.
153
+ _.detect = (obj, iterator, context) ->
154
+ result = null
155
+ _.each obj, (value, index, list) ->
156
+ if iterator.call context, value, index, list
157
+ result = value
158
+ _.breakLoop()
159
+ result
160
+
161
+
162
+ # Return all the elements that pass a truth test. Use JavaScript 1.6's
163
+ # **filter**, if it exists.
164
+ _.filter = (obj, iterator, context) ->
165
+ return obj.filter iterator, context if nativeFilter and obj.filter is nativeFilter
166
+ results = []
167
+ _.each obj, (value, index, list) ->
168
+ results.push value if iterator.call context, value, index, list
169
+ results
170
+
171
+
172
+ # Return all the elements for which a truth test fails.
173
+ _.reject = (obj, iterator, context) ->
174
+ results = []
175
+ _.each obj, (value, index, list) ->
176
+ results.push value if not iterator.call context, value, index, list
177
+ results
178
+
179
+
180
+ # Determine whether all of the elements match a truth test. Delegate to
181
+ # JavaScript 1.6's **every**, if it is present.
182
+ _.every = (obj, iterator, context) ->
183
+ iterator ||= _.identity
184
+ return obj.every iterator, context if nativeEvery and obj.every is nativeEvery
185
+ result = true
186
+ _.each obj, (value, index, list) ->
187
+ _.breakLoop() unless (result = result and iterator.call(context, value, index, list))
188
+ result
189
+
190
+
191
+ # Determine if at least one element in the object matches a truth test. Use
192
+ # JavaScript 1.6's **some**, if it exists.
193
+ _.some = (obj, iterator, context) ->
194
+ iterator ||= _.identity
195
+ return obj.some iterator, context if nativeSome and obj.some is nativeSome
196
+ result = false
197
+ _.each obj, (value, index, list) ->
198
+ _.breakLoop() if (result = iterator.call(context, value, index, list))
199
+ result
200
+
201
+
202
+ # Determine if a given value is included in the array or object,
203
+ # based on `===`.
204
+ _.include = (obj, target) ->
205
+ return _.indexOf(obj, target) isnt -1 if nativeIndexOf and obj.indexOf is nativeIndexOf
206
+ return true for own key, val of obj when val is target
207
+ false
208
+
209
+
210
+ # Invoke a method with arguments on every item in a collection.
211
+ _.invoke = (obj, method) ->
212
+ args = _.rest arguments, 2
213
+ (if method then val[method] else val).apply(val, args) for val in obj
214
+
215
+
216
+ # Convenience version of a common use case of **map**: fetching a property.
217
+ _.pluck = (obj, key) ->
218
+ _.map(obj, (val) -> val[key])
219
+
220
+
221
+ # Return the maximum item or (item-based computation).
222
+ _.max = (obj, iterator, context) ->
223
+ return Math.max.apply(Math, obj) if not iterator and _.isArray(obj)
224
+ result = computed: -Infinity
225
+ _.each obj, (value, index, list) ->
226
+ computed = if iterator then iterator.call(context, value, index, list) else value
227
+ computed >= result.computed and (result = {value: value, computed: computed})
228
+ result.value
229
+
230
+
231
+ # Return the minimum element (or element-based computation).
232
+ _.min = (obj, iterator, context) ->
233
+ return Math.min.apply(Math, obj) if not iterator and _.isArray(obj)
234
+ result = computed: Infinity
235
+ _.each obj, (value, index, list) ->
236
+ computed = if iterator then iterator.call(context, value, index, list) else value
237
+ computed < result.computed and (result = {value: value, computed: computed})
238
+ result.value
239
+
240
+
241
+ # Sort the object's values by a criterion produced by an iterator.
242
+ _.sortBy = (obj, iterator, context) ->
243
+ _.pluck(((_.map obj, (value, index, list) ->
244
+ {value: value, criteria: iterator.call(context, value, index, list)}
245
+ ).sort((left, right) ->
246
+ a = left.criteria; b = right.criteria
247
+ if a < b then -1 else if a > b then 1 else 0
248
+ )), 'value')
249
+
250
+
251
+ # Use a comparator function to figure out at what index an object should
252
+ # be inserted so as to maintain order. Uses binary search.
253
+ _.sortedIndex = (array, obj, iterator) ->
254
+ iterator ||= _.identity
255
+ low = 0
256
+ high = array.length
257
+ while low < high
258
+ mid = (low + high) >> 1
259
+ if iterator(array[mid]) < iterator(obj) then low = mid + 1 else high = mid
260
+ low
261
+
262
+
263
+ # Convert anything iterable into a real, live array.
264
+ _.toArray = (iterable) ->
265
+ return [] if (!iterable)
266
+ return iterable.toArray() if (iterable.toArray)
267
+ return iterable if (_.isArray(iterable))
268
+ return slice.call(iterable) if (_.isArguments(iterable))
269
+ _.values(iterable)
270
+
271
+
272
+ # Return the number of elements in an object.
273
+ _.size = (obj) -> _.toArray(obj).length
274
+
275
+
276
+ # Array Functions
277
+ # ---------------
278
+
279
+ # Get the first element of an array. Passing `n` will return the first N
280
+ # values in the array. Aliased as **head**. The `guard` check allows it to work
281
+ # with **map**.
282
+ _.first = (array, n, guard) ->
283
+ if n and not guard then slice.call(array, 0, n) else array[0]
284
+
285
+
286
+ # Returns everything but the first entry of the array. Aliased as **tail**.
287
+ # Especially useful on the arguments object. Passing an `index` will return
288
+ # the rest of the values in the array from that index onward. The `guard`
289
+ # check allows it to work with **map**.
290
+ _.rest = (array, index, guard) ->
291
+ slice.call(array, if _.isUndefined(index) or guard then 1 else index)
292
+
293
+
294
+ # Get the last element of an array.
295
+ _.last = (array) -> array[array.length - 1]
296
+
297
+
298
+ # Trim out all falsy values from an array.
299
+ _.compact = (array) -> item for item in array when item
300
+
301
+
302
+ # Return a completely flattened version of an array.
303
+ _.flatten = (array) ->
304
+ _.reduce array, (memo, value) ->
305
+ return memo.concat(_.flatten(value)) if _.isArray value
306
+ memo.push value
307
+ memo
308
+ , []
309
+
310
+
311
+ # Return a version of the array that does not contain the specified value(s).
312
+ _.without = (array) ->
313
+ values = _.rest arguments
314
+ val for val in _.toArray(array) when not _.include values, val
315
+
316
+
317
+ # Produce a duplicate-free version of the array. If the array has already
318
+ # been sorted, you have the option of using a faster algorithm.
319
+ _.uniq = (array, isSorted) ->
320
+ memo = []
321
+ for el, i in _.toArray array
322
+ memo.push el if i is 0 || (if isSorted is true then _.last(memo) isnt el else not _.include(memo, el))
323
+ memo
324
+
325
+
326
+ # Produce an array that contains every item shared between all the
327
+ # passed-in arrays.
328
+ _.intersect = (array) ->
329
+ rest = _.rest arguments
330
+ _.select _.uniq(array), (item) ->
331
+ _.all rest, (other) ->
332
+ _.indexOf(other, item) >= 0
333
+
334
+
335
+ # Zip together multiple lists into a single array -- elements that share
336
+ # an index go together.
337
+ _.zip = ->
338
+ length = _.max _.pluck arguments, 'length'
339
+ results = new Array length
340
+ for i in [0...length]
341
+ results[i] = _.pluck arguments, String i
342
+ results
343
+
344
+
345
+ # If the browser doesn't supply us with **indexOf** (I'm looking at you, MSIE),
346
+ # we need this function. Return the position of the first occurrence of an
347
+ # item in an array, or -1 if the item is not included in the array.
348
+ _.indexOf = (array, item) ->
349
+ return array.indexOf item if nativeIndexOf and array.indexOf is nativeIndexOf
350
+ i = 0; l = array.length
351
+ while l - i
352
+ if array[i] is item then return i else i++
353
+ -1
354
+
355
+
356
+ # Provide JavaScript 1.6's **lastIndexOf**, delegating to the native function,
357
+ # if possible.
358
+ _.lastIndexOf = (array, item) ->
359
+ return array.lastIndexOf(item) if nativeLastIndexOf and array.lastIndexOf is nativeLastIndexOf
360
+ i = array.length
361
+ while i
362
+ if array[i] is item then return i else i--
363
+ -1
364
+
365
+
366
+ # Generate an integer Array containing an arithmetic progression. A port of
367
+ # [the native Python **range** function](http://docs.python.org/library/functions.html#range).
368
+ _.range = (start, stop, step) ->
369
+ a = arguments
370
+ solo = a.length <= 1
371
+ i = start = if solo then 0 else a[0]
372
+ stop = if solo then a[0] else a[1]
373
+ step = a[2] or 1
374
+ len = Math.ceil((stop - start) / step)
375
+ return [] if len <= 0
376
+ range = new Array len
377
+ idx = 0
378
+ loop
379
+ return range if (if step > 0 then i - stop else stop - i) >= 0
380
+ range[idx] = i
381
+ idx++
382
+ i+= step
383
+
384
+
385
+ # Function Functions
386
+ # ------------------
387
+
388
+ # Create a function bound to a given object (assigning `this`, and arguments,
389
+ # optionally). Binding with arguments is also known as **curry**.
390
+ _.bind = (func, obj) ->
391
+ args = _.rest arguments, 2
392
+ -> func.apply obj or root, args.concat arguments
393
+
394
+
395
+ # Bind all of an object's methods to that object. Useful for ensuring that
396
+ # all callbacks defined on an object belong to it.
397
+ _.bindAll = (obj) ->
398
+ funcs = if arguments.length > 1 then _.rest(arguments) else _.functions(obj)
399
+ _.each funcs, (f) -> obj[f] = _.bind obj[f], obj
400
+ obj
401
+
402
+
403
+ # Delays a function for the given number of milliseconds, and then calls
404
+ # it with the arguments supplied.
405
+ _.delay = (func, wait) ->
406
+ args = _.rest arguments, 2
407
+ setTimeout((-> func.apply(func, args)), wait)
408
+
409
+
410
+ # Memoize an expensive function by storing its results.
411
+ _.memoize = (func, hasher) ->
412
+ memo = {}
413
+ hasher or= _.identity
414
+ ->
415
+ key = hasher.apply this, arguments
416
+ return memo[key] if key of memo
417
+ memo[key] = func.apply this, arguments
418
+
419
+
420
+ # Defers a function, scheduling it to run after the current call stack has
421
+ # cleared.
422
+ _.defer = (func) ->
423
+ _.delay.apply _, [func, 1].concat _.rest arguments
424
+
425
+
426
+ # Returns the first function passed as an argument to the second,
427
+ # allowing you to adjust arguments, run code before and after, and
428
+ # conditionally execute the original function.
429
+ _.wrap = (func, wrapper) ->
430
+ -> wrapper.apply wrapper, [func].concat arguments
431
+
432
+
433
+ # Returns a function that is the composition of a list of functions, each
434
+ # consuming the return value of the function that follows.
435
+ _.compose = ->
436
+ funcs = arguments
437
+ ->
438
+ args = arguments
439
+ for i in [funcs.length - 1..0] by -1
440
+ args = [funcs[i].apply(this, args)]
441
+ args[0]
442
+
443
+
444
+ # Object Functions
445
+ # ----------------
446
+
447
+ # Retrieve the names of an object's properties.
448
+ _.keys = nativeKeys or (obj) ->
449
+ return _.range 0, obj.length if _.isArray(obj)
450
+ key for key, val of obj
451
+
452
+
453
+ # Retrieve the values of an object's properties.
454
+ _.values = (obj) ->
455
+ _.map obj, _.identity
456
+
457
+
458
+ # Return a sorted list of the function names available in Underscore.
459
+ _.functions = (obj) ->
460
+ _.filter(_.keys(obj), (key) -> _.isFunction(obj[key])).sort()
461
+
462
+
463
+ # Extend a given object with all of the properties in a source object.
464
+ _.extend = (obj) ->
465
+ for source in _.rest(arguments)
466
+ obj[key] = val for key, val of source
467
+ obj
468
+
469
+
470
+ # Create a (shallow-cloned) duplicate of an object.
471
+ _.clone = (obj) ->
472
+ return obj.slice 0 if _.isArray obj
473
+ _.extend {}, obj
474
+
475
+
476
+ # Invokes interceptor with the obj, and then returns obj.
477
+ # The primary purpose of this method is to "tap into" a method chain,
478
+ # in order to perform operations on intermediate results within
479
+ the chain.
480
+ _.tap = (obj, interceptor) ->
481
+ interceptor obj
482
+ obj
483
+
484
+
485
+ # Perform a deep comparison to check if two objects are equal.
486
+ _.isEqual = (a, b) ->
487
+ # Check object identity.
488
+ return true if a is b
489
+ # Different types?
490
+ atype = typeof(a); btype = typeof(b)
491
+ return false if atype isnt btype
492
+ # Basic equality test (watch out for coercions).
493
+ return true if `a == b`
494
+ # One is falsy and the other truthy.
495
+ return false if (!a and b) or (a and !b)
496
+ # One of them implements an `isEqual()`?
497
+ return a.isEqual(b) if a.isEqual
498
+ # Check dates' integer values.
499
+ return a.getTime() is b.getTime() if _.isDate(a) and _.isDate(b)
500
+ # Both are NaN?
501
+ return false if _.isNaN(a) and _.isNaN(b)
502
+ # Compare regular expressions.
503
+ if _.isRegExp(a) and _.isRegExp(b)
504
+ return a.source is b.source and
505
+ a.global is b.global and
506
+ a.ignoreCase is b.ignoreCase and
507
+ a.multiline is b.multiline
508
+ # If a is not an object by this point, we can't handle it.
509
+ return false if atype isnt 'object'
510
+ # Check for different array lengths before comparing contents.
511
+ return false if a.length and (a.length isnt b.length)
512
+ # Nothing else worked, deep compare the contents.
513
+ aKeys = _.keys(a); bKeys = _.keys(b)
514
+ # Different object sizes?
515
+ return false if aKeys.length isnt bKeys.length
516
+ # Recursive comparison of contents.
517
+ return false for key, val of a when !(key of b) or !_.isEqual(val, b[key])
518
+ true
519
+
520
+
521
+ # Is a given array or object empty?
522
+ _.isEmpty = (obj) ->
523
+ return obj.length is 0 if _.isArray(obj) or _.isString(obj)
524
+ return false for own key of obj
525
+ true
526
+
527
+
528
+ # Is a given value a DOM element?
529
+ _.isElement = (obj) -> obj and obj.nodeType is 1
530
+
531
+
532
+ # Is a given value an array?
533
+ _.isArray = nativeIsArray or (obj) -> !!(obj and obj.concat and obj.unshift and not obj.callee)
534
+
535
+
536
+ # Is a given variable an arguments object?
537
+ _.isArguments = (obj) -> obj and obj.callee
538
+
539
+
540
+ # Is the given value a function?
541
+ _.isFunction = (obj) -> !!(obj and obj.constructor and obj.call and obj.apply)
542
+
543
+
544
+ # Is the given value a string?
545
+ _.isString = (obj) -> !!(obj is '' or (obj and obj.charCodeAt and obj.substr))
546
+
547
+
548
+ # Is a given value a number?
549
+ _.isNumber = (obj) -> (obj is +obj) or toString.call(obj) is '[object Number]'
550
+
551
+
552
+ # Is a given value a boolean?
553
+ _.isBoolean = (obj) -> obj is true or obj is false
554
+
555
+
556
+ # Is a given value a Date?
557
+ _.isDate = (obj) -> !!(obj and obj.getTimezoneOffset and obj.setUTCFullYear)
558
+
559
+
560
+ # Is the given value a regular expression?
561
+ _.isRegExp = (obj) -> !!(obj and obj.exec and (obj.ignoreCase or obj.ignoreCase is false))
562
+
563
+
564
+ # Is the given value NaN -- this one is interesting. `NaN != NaN`, and
565
+ # `isNaN(undefined) == true`, so we make sure it's a number first.
566
+ _.isNaN = (obj) -> _.isNumber(obj) and window.isNaN(obj)
567
+
568
+
569
+ # Is a given value equal to null?
570
+ _.isNull = (obj) -> obj is null
571
+
572
+
573
+ # Is a given variable undefined?
574
+ _.isUndefined = (obj) -> typeof obj is 'undefined'
575
+
576
+
577
+ # Utility Functions
578
+ # -----------------
579
+
580
+ # Run Underscore.js in noConflict mode, returning the `_` variable to its
581
+ # previous owner. Returns a reference to the Underscore object.
582
+ _.noConflict = ->
583
+ root._ = previousUnderscore
584
+ this
585
+
586
+
587
+ # Keep the identity function around for default iterators.
588
+ _.identity = (value) -> value
589
+
590
+
591
+ # Run a function `n` times.
592
+ _.times = (n, iterator, context) ->
593
+ iterator.call context, i for i in [0...n]
594
+
595
+
596
+ # Break out of the middle of an iteration.
597
+ _.breakLoop = -> throw breaker
598
+
599
+
600
+ # Add your own custom functions to the Underscore object, ensuring that
601
+ # they're correctly added to the OOP wrapper as well.
602
+ _.mixin = (obj) ->
603
+ for name in _.functions(obj)
604
+ addToWrapper name, _[name] = obj[name]
605
+
606
+
607
+ # Generate a unique integer id (unique within the entire client session).
608
+ # Useful for temporary DOM ids.
609
+ idCounter = 0
610
+ _.uniqueId = (prefix) ->
611
+ (prefix or '') + idCounter++
612
+
613
+
614
+ # By default, Underscore uses **ERB**-style template delimiters, change the
615
+ # following template settings to use alternative delimiters.
616
+ _.templateSettings = {
617
+ start: '<%'
618
+ end: '%>'
619
+ interpolate: /<%=(.+?)%>/g
620
+ }
621
+
622
+
623
+ # JavaScript templating a-la **ERB**, pilfered from John Resig's
624
+ # *Secrets of the JavaScript Ninja*, page 83.
625
+ # Single-quote fix from Rick Strahl.
626
+ # With alterations for arbitrary delimiters, and to preserve whitespace.
627
+ _.template = (str, data) ->
628
+ c = _.templateSettings
629
+ endMatch = new RegExp("'(?=[^"+c.end.substr(0, 1)+"]*"+escapeRegExp(c.end)+")","g")
630
+ fn = new Function 'obj',
631
+ 'var p=[],print=function(){p.push.apply(p,arguments);};' +
632
+ 'with(obj||{}){p.push(\'' +
633
+ str.replace(/\r/g, '\\r')
634
+ .replace(/\n/g, '\\n')
635
+ .replace(/\t/g, '\\t')
636
+ .replace(endMatch,"���")
637
+ .split("'").join("\\'")
638
+ .split("���").join("'")
639
+ .replace(c.interpolate, "',$1,'")
640
+ .split(c.start).join("');")
641
+ .split(c.end).join("p.push('") +
642
+ "');}return p.join('');"
643
+ if data then fn(data) else fn
644
+
645
+
646
+ # Aliases
647
+ # -------
648
+
649
+ _.forEach = _.each
650
+ _.foldl = _.inject = _.reduce
651
+ _.foldr = _.reduceRight
652
+ _.select = _.filter
653
+ _.all = _.every
654
+ _.any = _.some
655
+ _.contains = _.include
656
+ _.head = _.first
657
+ _.tail = _.rest
658
+ _.methods = _.functions
659
+
660
+
661
+ # Setup the OOP Wrapper
662
+ # ---------------------
663
+
664
+ # If Underscore is called as a function, it returns a wrapped object that
665
+ # can be used OO-style. This wrapper holds altered versions of all the
666
+ # underscore functions. Wrapped objects may be chained.
667
+ wrapper = (obj) ->
668
+ this._wrapped = obj
669
+ this
670
+
671
+
672
+ # Helper function to continue chaining intermediate results.
673
+ result = (obj, chain) ->
674
+ if chain then _(obj).chain() else obj
675
+
676
+
677
+ # A method to easily add functions to the OOP wrapper.
678
+ addToWrapper = (name, func) ->
679
+ wrapper.prototype[name] = ->
680
+ args = _.toArray arguments
681
+ unshift.call args, this._wrapped
682
+ result func.apply(_, args), this._chain
683
+
684
+
685
+ # Add all ofthe Underscore functions to the wrapper object.
686
+ _.mixin _
687
+
688
+
689
+ # Add all mutator Array functions to the wrapper.
690
+ _.each ['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'], (name) ->
691
+ method = Array.prototype[name]
692
+ wrapper.prototype[name] = ->
693
+ method.apply(this._wrapped, arguments)
694
+ result(this._wrapped, this._chain)
695
+
696
+
697
+ # Add all accessor Array functions to the wrapper.
698
+ _.each ['concat', 'join', 'slice'], (name) ->
699
+ method = Array.prototype[name]
700
+ wrapper.prototype[name] = ->
701
+ result(method.apply(this._wrapped, arguments), this._chain)
702
+
703
+
704
+ # Start chaining a wrapped Underscore object.
705
+ wrapper::chain = ->
706
+ this._chain = true
707
+ this
708
+
709
+
710
+ # Extracts the result from a wrapped and chained object.
711
+ wrapper::value = -> this._wrapped
712
+ </textarea></form>
713
+ <script>
714
+ var editor = CodeMirror.fromTextArea(document.getElementById("code"), {});
715
+ </script>
716
+
717
+ <p><strong>MIME types defined:</strong> <code>text/x-coffeescript</code>.</p>
718
+
719
+ <p>The CoffeeScript mode was written by Jeff Pickhardt (<a href="LICENSE">license</a>).</p>
720
+
721
+ </body>
722
+ </html>