mobile_template 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (211) hide show
  1. data/.gitignore +17 -0
  2. data/Gemfile +4 -0
  3. data/LICENSE +22 -0
  4. data/README.md +28 -0
  5. data/Rakefile +3 -0
  6. data/bin/mobile_template +71 -0
  7. data/lib/mobile_template/version.rb +4 -0
  8. data/lib/mobile_template.rb +5 -0
  9. data/mobile_template.gemspec +21 -0
  10. data/templates/assets/Gemfile +4 -0
  11. data/templates/assets/config.rb +96 -0
  12. data/templates/assets/config.ru +4 -0
  13. data/templates/assets/source/images/vendor/ajax-loader.gif +0 -0
  14. data/templates/assets/source/images/vendor/ajax-loader.png +0 -0
  15. data/templates/assets/source/images/vendor/icons-18-black.png +0 -0
  16. data/templates/assets/source/images/vendor/icons-18-white.png +0 -0
  17. data/templates/assets/source/images/vendor/icons-36-black.png +0 -0
  18. data/templates/assets/source/images/vendor/icons-36-white.png +0 -0
  19. data/templates/assets/source/index.html.erb +2 -0
  20. data/templates/assets/source/javascripts/app/index.js.coffee +2 -0
  21. data/templates/assets/source/javascripts/application.js.coffee +5 -0
  22. data/templates/assets/source/javascripts/vendor/cordova.js +4841 -0
  23. data/templates/assets/source/javascripts/vendor/jquery.js +9267 -0
  24. data/templates/assets/source/javascripts/vendor/jquery.mobile.js +7410 -0
  25. data/templates/assets/source/layout.erb +24 -0
  26. data/templates/assets/source/stylesheets/application.css.scss +2 -0
  27. data/templates/assets/source/stylesheets/vendor/jquery.mobile.css.scss +1872 -0
  28. data/templates/cordova_android/.gitignore +18 -0
  29. data/templates/cordova_android/LICENSE +202 -0
  30. data/templates/cordova_android/NOTICE +5 -0
  31. data/templates/cordova_android/README.md +95 -0
  32. data/templates/cordova_android/VERSION +1 -0
  33. data/templates/cordova_android/bin/BOOM +4 -0
  34. data/templates/cordova_android/bin/autotest +2 -0
  35. data/templates/cordova_android/bin/bench +29 -0
  36. data/templates/cordova_android/bin/create +46 -0
  37. data/templates/cordova_android/bin/create.bat +1 -0
  38. data/templates/cordova_android/bin/create.js +88 -0
  39. data/templates/cordova_android/bin/create.xml +79 -0
  40. data/templates/cordova_android/bin/node_modules/.bin/cake +7 -0
  41. data/templates/cordova_android/bin/node_modules/.bin/coffee +7 -0
  42. data/templates/cordova_android/bin/node_modules/.bin/nodeunit +120 -0
  43. data/templates/cordova_android/bin/node_modules/coffee-script/.npmignore +11 -0
  44. data/templates/cordova_android/bin/node_modules/coffee-script/LICENSE +22 -0
  45. data/templates/cordova_android/bin/node_modules/coffee-script/README +48 -0
  46. data/templates/cordova_android/bin/node_modules/coffee-script/Rakefile +78 -0
  47. data/templates/cordova_android/bin/node_modules/coffee-script/bin/cake +7 -0
  48. data/templates/cordova_android/bin/node_modules/coffee-script/bin/coffee +7 -0
  49. data/templates/cordova_android/bin/node_modules/coffee-script/extras/jsl.conf +44 -0
  50. data/templates/cordova_android/bin/node_modules/coffee-script/lib/browser.js +75 -0
  51. data/templates/cordova_android/bin/node_modules/coffee-script/lib/cake.js +76 -0
  52. data/templates/cordova_android/bin/node_modules/coffee-script/lib/coffee-script.js +135 -0
  53. data/templates/cordova_android/bin/node_modules/coffee-script/lib/command.js +301 -0
  54. data/templates/cordova_android/bin/node_modules/coffee-script/lib/grammar.js +591 -0
  55. data/templates/cordova_android/bin/node_modules/coffee-script/lib/helpers.js +66 -0
  56. data/templates/cordova_android/bin/node_modules/coffee-script/lib/index.js +8 -0
  57. data/templates/cordova_android/bin/node_modules/coffee-script/lib/lexer.js +656 -0
  58. data/templates/cordova_android/bin/node_modules/coffee-script/lib/nodes.js +2289 -0
  59. data/templates/cordova_android/bin/node_modules/coffee-script/lib/optparse.js +111 -0
  60. data/templates/cordova_android/bin/node_modules/coffee-script/lib/parser.js +676 -0
  61. data/templates/cordova_android/bin/node_modules/coffee-script/lib/repl.js +123 -0
  62. data/templates/cordova_android/bin/node_modules/coffee-script/lib/rewriter.js +363 -0
  63. data/templates/cordova_android/bin/node_modules/coffee-script/lib/scope.js +120 -0
  64. data/templates/cordova_android/bin/node_modules/coffee-script/package.json +27 -0
  65. data/templates/cordova_android/bin/node_modules/nodeunit/.gitignore +5 -0
  66. data/templates/cordova_android/bin/node_modules/nodeunit/.npmignore +3 -0
  67. data/templates/cordova_android/bin/node_modules/nodeunit/CONTRIBUTORS.md +60 -0
  68. data/templates/cordova_android/bin/node_modules/nodeunit/LICENSE +19 -0
  69. data/templates/cordova_android/bin/node_modules/nodeunit/Makefile +126 -0
  70. data/templates/cordova_android/bin/node_modules/nodeunit/README.md +432 -0
  71. data/templates/cordova_android/bin/node_modules/nodeunit/bin/nodeunit +120 -0
  72. data/templates/cordova_android/bin/node_modules/nodeunit/bin/nodeunit.json +10 -0
  73. data/templates/cordova_android/bin/node_modules/nodeunit/deps/async.js +623 -0
  74. data/templates/cordova_android/bin/node_modules/nodeunit/deps/console.log.js +55 -0
  75. data/templates/cordova_android/bin/node_modules/nodeunit/deps/ejs.js +125 -0
  76. data/templates/cordova_android/bin/node_modules/nodeunit/deps/json2.js +483 -0
  77. data/templates/cordova_android/bin/node_modules/nodeunit/examples/browser/nodeunit.js +1757 -0
  78. data/templates/cordova_android/bin/node_modules/nodeunit/examples/browser/suite1.js +12 -0
  79. data/templates/cordova_android/bin/node_modules/nodeunit/examples/browser/suite2.js +13 -0
  80. data/templates/cordova_android/bin/node_modules/nodeunit/examples/browser/test.html +16 -0
  81. data/templates/cordova_android/bin/node_modules/nodeunit/img/example_fail.png +0 -0
  82. data/templates/cordova_android/bin/node_modules/nodeunit/img/example_pass.png +0 -0
  83. data/templates/cordova_android/bin/node_modules/nodeunit/index.js +3 -0
  84. data/templates/cordova_android/bin/node_modules/nodeunit/lib/assert.js +316 -0
  85. data/templates/cordova_android/bin/node_modules/nodeunit/lib/core.js +260 -0
  86. data/templates/cordova_android/bin/node_modules/nodeunit/lib/nodeunit.js +82 -0
  87. data/templates/cordova_android/bin/node_modules/nodeunit/lib/reporters/browser.js +119 -0
  88. data/templates/cordova_android/bin/node_modules/nodeunit/lib/reporters/default.js +123 -0
  89. data/templates/cordova_android/bin/node_modules/nodeunit/lib/reporters/html.js +107 -0
  90. data/templates/cordova_android/bin/node_modules/nodeunit/lib/reporters/index.js +9 -0
  91. data/templates/cordova_android/bin/node_modules/nodeunit/lib/reporters/junit.js +183 -0
  92. data/templates/cordova_android/bin/node_modules/nodeunit/lib/reporters/minimal.js +112 -0
  93. data/templates/cordova_android/bin/node_modules/nodeunit/lib/reporters/skip_passed.js +105 -0
  94. data/templates/cordova_android/bin/node_modules/nodeunit/lib/track.js +48 -0
  95. data/templates/cordova_android/bin/node_modules/nodeunit/lib/types.js +187 -0
  96. data/templates/cordova_android/bin/node_modules/nodeunit/lib/utils.js +209 -0
  97. data/templates/cordova_android/bin/node_modules/nodeunit/man1/nodeunit.1 +95 -0
  98. data/templates/cordova_android/bin/node_modules/nodeunit/nodelint.cfg +4 -0
  99. data/templates/cordova_android/bin/node_modules/nodeunit/package.json +56 -0
  100. data/templates/cordova_android/bin/node_modules/nodeunit/share/junit.xml.ejs +19 -0
  101. data/templates/cordova_android/bin/node_modules/nodeunit/share/license.js +11 -0
  102. data/templates/cordova_android/bin/node_modules/nodeunit/share/nodeunit.css +70 -0
  103. data/templates/cordova_android/bin/templates/project/.cordova/android/readme.md +1 -0
  104. data/templates/cordova_android/bin/templates/project/.cordova/readme.md +3 -0
  105. data/templates/cordova_android/bin/templates/project/cordova/create +36 -0
  106. data/templates/cordova_android/bin/templates/project/cordova/debug +9 -0
  107. data/templates/cordova_android/bin/templates/project/cordova/emulate +12 -0
  108. data/templates/cordova_android/bin/templates/project/cordova/log +3 -0
  109. data/templates/cordova_android/bin/templates/project/cordova/templates/Activity.java +16 -0
  110. data/templates/cordova_android/bin/templates/project/cordova/templates/project/AndroidManifest.xml +50 -0
  111. data/templates/cordova_android/bin/templates/project/cordova/templates/project/assets/www/index.html +42 -0
  112. data/templates/cordova_android/bin/templates/project/cordova/templates/project/assets/www/main.js +146 -0
  113. data/templates/cordova_android/bin/templates/project/cordova/templates/project/assets/www/master.css +96 -0
  114. data/templates/cordova_android/bin/templates/project/cordova/templates/project/res/drawable/icon.png +0 -0
  115. data/templates/cordova_android/bin/templates/project/cordova/templates/project/res/xml/cordova.xml +5 -0
  116. data/templates/cordova_android/bin/templates/project/cordova/templates/project/res/xml/plugins.xml +19 -0
  117. data/templates/cordova_android/bin/test +26 -0
  118. data/templates/cordova_android/bin/tests/autotest.coffee +4 -0
  119. data/templates/cordova_android/bin/tests/create.coffee +21 -0
  120. data/templates/cordova_android/bin/tests/debug.coffee +0 -0
  121. data/templates/cordova_android/bin/tests/test.coffee +0 -0
  122. data/templates/cordova_android/framework/.classpath +8 -0
  123. data/templates/cordova_android/framework/.project +33 -0
  124. data/templates/cordova_android/framework/AndroidManifest.xml +68 -0
  125. data/templates/cordova_android/framework/ant.properties +34 -0
  126. data/templates/cordova_android/framework/assets/js/accelerometer.js +137 -0
  127. data/templates/cordova_android/framework/assets/js/app.js +89 -0
  128. data/templates/cordova_android/framework/assets/js/battery.js +134 -0
  129. data/templates/cordova_android/framework/assets/js/camera.js +168 -0
  130. data/templates/cordova_android/framework/assets/js/capture.js +203 -0
  131. data/templates/cordova_android/framework/assets/js/compass.js +168 -0
  132. data/templates/cordova_android/framework/assets/js/contact.js +310 -0
  133. data/templates/cordova_android/framework/assets/js/cordova.android.js +4841 -0
  134. data/templates/cordova_android/framework/assets/js/cordova.js.base +924 -0
  135. data/templates/cordova_android/framework/assets/js/crypto.js +54 -0
  136. data/templates/cordova_android/framework/assets/js/device.js +83 -0
  137. data/templates/cordova_android/framework/assets/js/file.js +1082 -0
  138. data/templates/cordova_android/framework/assets/js/filetransfer.js +125 -0
  139. data/templates/cordova_android/framework/assets/js/geolocation.js +209 -0
  140. data/templates/cordova_android/framework/assets/js/header.txt +19 -0
  141. data/templates/cordova_android/framework/assets/js/media.js +233 -0
  142. data/templates/cordova_android/framework/assets/js/network.js +100 -0
  143. data/templates/cordova_android/framework/assets/js/notification.js +133 -0
  144. data/templates/cordova_android/framework/assets/js/position.js +100 -0
  145. data/templates/cordova_android/framework/assets/js/storage.js +439 -0
  146. data/templates/cordova_android/framework/assets/www/index.html +27 -0
  147. data/templates/cordova_android/framework/build.xml +216 -0
  148. data/templates/cordova_android/framework/libs/commons-codec-1.3.jar +0 -0
  149. data/templates/cordova_android/framework/proguard-project.txt +20 -0
  150. data/templates/cordova_android/framework/project.properties +14 -0
  151. data/templates/cordova_android/framework/res/drawable/icon.png +0 -0
  152. data/templates/cordova_android/framework/res/drawable/splash.png +0 -0
  153. data/templates/cordova_android/framework/res/layout/main.xml +29 -0
  154. data/templates/cordova_android/framework/res/values/strings.xml +23 -0
  155. data/templates/cordova_android/framework/res/xml/cordova.xml +37 -0
  156. data/templates/cordova_android/framework/res/xml/plugins.xml +37 -0
  157. data/templates/cordova_android/framework/src/com/phonegap/api/IPlugin.java +27 -0
  158. data/templates/cordova_android/framework/src/com/phonegap/api/LOG.java +28 -0
  159. data/templates/cordova_android/framework/src/com/phonegap/api/PhonegapActivity.java +28 -0
  160. data/templates/cordova_android/framework/src/com/phonegap/api/Plugin.java +27 -0
  161. data/templates/cordova_android/framework/src/com/phonegap/api/PluginManager.java +35 -0
  162. data/templates/cordova_android/framework/src/com/phonegap/api/PluginResult.java +53 -0
  163. data/templates/cordova_android/framework/src/org/apache/cordova/AccelListener.java +311 -0
  164. data/templates/cordova_android/framework/src/org/apache/cordova/App.java +198 -0
  165. data/templates/cordova_android/framework/src/org/apache/cordova/AudioHandler.java +364 -0
  166. data/templates/cordova_android/framework/src/org/apache/cordova/AudioPlayer.java +450 -0
  167. data/templates/cordova_android/framework/src/org/apache/cordova/AuthenticationToken.java +69 -0
  168. data/templates/cordova_android/framework/src/org/apache/cordova/BatteryListener.java +156 -0
  169. data/templates/cordova_android/framework/src/org/apache/cordova/CallbackServer.java +431 -0
  170. data/templates/cordova_android/framework/src/org/apache/cordova/CameraLauncher.java +500 -0
  171. data/templates/cordova_android/framework/src/org/apache/cordova/Capture.java +400 -0
  172. data/templates/cordova_android/framework/src/org/apache/cordova/CompassListener.java +308 -0
  173. data/templates/cordova_android/framework/src/org/apache/cordova/ContactAccessor.java +198 -0
  174. data/templates/cordova_android/framework/src/org/apache/cordova/ContactAccessorSdk5.java +1934 -0
  175. data/templates/cordova_android/framework/src/org/apache/cordova/ContactManager.java +113 -0
  176. data/templates/cordova_android/framework/src/org/apache/cordova/CordovaChromeClient.java +314 -0
  177. data/templates/cordova_android/framework/src/org/apache/cordova/CordovaWebViewClient.java +306 -0
  178. data/templates/cordova_android/framework/src/org/apache/cordova/Device.java +219 -0
  179. data/templates/cordova_android/framework/src/org/apache/cordova/DirectoryManager.java +161 -0
  180. data/templates/cordova_android/framework/src/org/apache/cordova/DroidGap.java +1417 -0
  181. data/templates/cordova_android/framework/src/org/apache/cordova/ExifHelper.java +165 -0
  182. data/templates/cordova_android/framework/src/org/apache/cordova/FileTransfer.java +458 -0
  183. data/templates/cordova_android/framework/src/org/apache/cordova/FileUploadResult.java +63 -0
  184. data/templates/cordova_android/framework/src/org/apache/cordova/FileUtils.java +1048 -0
  185. data/templates/cordova_android/framework/src/org/apache/cordova/GeoBroker.java +165 -0
  186. data/templates/cordova_android/framework/src/org/apache/cordova/GeoListener.java +133 -0
  187. data/templates/cordova_android/framework/src/org/apache/cordova/GpsListener.java +163 -0
  188. data/templates/cordova_android/framework/src/org/apache/cordova/HttpHandler.java +80 -0
  189. data/templates/cordova_android/framework/src/org/apache/cordova/LinearLayoutSoftKeyboardDetect.java +104 -0
  190. data/templates/cordova_android/framework/src/org/apache/cordova/NetworkListener.java +153 -0
  191. data/templates/cordova_android/framework/src/org/apache/cordova/NetworkManager.java +248 -0
  192. data/templates/cordova_android/framework/src/org/apache/cordova/Notification.java +366 -0
  193. data/templates/cordova_android/framework/src/org/apache/cordova/PreferenceNode.java +34 -0
  194. data/templates/cordova_android/framework/src/org/apache/cordova/PreferenceSet.java +62 -0
  195. data/templates/cordova_android/framework/src/org/apache/cordova/StandAlone.java +35 -0
  196. data/templates/cordova_android/framework/src/org/apache/cordova/Storage.java +239 -0
  197. data/templates/cordova_android/framework/src/org/apache/cordova/TempListener.java +112 -0
  198. data/templates/cordova_android/framework/src/org/apache/cordova/api/CordovaInterface.java +145 -0
  199. data/templates/cordova_android/framework/src/org/apache/cordova/api/IPlugin.java +116 -0
  200. data/templates/cordova_android/framework/src/org/apache/cordova/api/LOG.java +234 -0
  201. data/templates/cordova_android/framework/src/org/apache/cordova/api/Plugin.java +210 -0
  202. data/templates/cordova_android/framework/src/org/apache/cordova/api/PluginManager.java +359 -0
  203. data/templates/cordova_android/framework/src/org/apache/cordova/api/PluginResult.java +119 -0
  204. data/templates/cordova_android/framework/src/org/apache/cordova/file/EncodingException.java +28 -0
  205. data/templates/cordova_android/framework/src/org/apache/cordova/file/FileExistsException.java +28 -0
  206. data/templates/cordova_android/framework/src/org/apache/cordova/file/InvalidModificationException.java +29 -0
  207. data/templates/cordova_android/framework/src/org/apache/cordova/file/NoModificationAllowedException.java +28 -0
  208. data/templates/cordova_android/framework/src/org/apache/cordova/file/TypeMismatchException.java +29 -0
  209. data/templates/cordova_android/framework/test/org/apache/cordova/PreferenceNodeTest.java +53 -0
  210. data/templates/cordova_android/framework/test/org/apache/cordova/PreferenceSetTest.java +73 -0
  211. metadata +279 -0
@@ -0,0 +1,623 @@
1
+ /*global setTimeout: false, console: false */
2
+ (function () {
3
+
4
+ var async = {};
5
+
6
+ // global on the server, window in the browser
7
+ var root = this,
8
+ previous_async = root.async;
9
+
10
+ if (typeof module !== 'undefined' && module.exports) {
11
+ module.exports = async;
12
+ }
13
+ else {
14
+ root.async = async;
15
+ }
16
+
17
+ async.noConflict = function () {
18
+ root.async = previous_async;
19
+ return async;
20
+ };
21
+
22
+ //// cross-browser compatiblity functions ////
23
+
24
+ var _forEach = function (arr, iterator) {
25
+ if (arr.forEach) {
26
+ return arr.forEach(iterator);
27
+ }
28
+ for (var i = 0; i < arr.length; i += 1) {
29
+ iterator(arr[i], i, arr);
30
+ }
31
+ };
32
+
33
+ var _map = function (arr, iterator) {
34
+ if (arr.map) {
35
+ return arr.map(iterator);
36
+ }
37
+ var results = [];
38
+ _forEach(arr, function (x, i, a) {
39
+ results.push(iterator(x, i, a));
40
+ });
41
+ return results;
42
+ };
43
+
44
+ var _reduce = function (arr, iterator, memo) {
45
+ if (arr.reduce) {
46
+ return arr.reduce(iterator, memo);
47
+ }
48
+ _forEach(arr, function (x, i, a) {
49
+ memo = iterator(memo, x, i, a);
50
+ });
51
+ return memo;
52
+ };
53
+
54
+ var _keys = function (obj) {
55
+ if (Object.keys) {
56
+ return Object.keys(obj);
57
+ }
58
+ var keys = [];
59
+ for (var k in obj) {
60
+ if (obj.hasOwnProperty(k)) {
61
+ keys.push(k);
62
+ }
63
+ }
64
+ return keys;
65
+ };
66
+
67
+ var _indexOf = function (arr, item) {
68
+ if (arr.indexOf) {
69
+ return arr.indexOf(item);
70
+ }
71
+ for (var i = 0; i < arr.length; i += 1) {
72
+ if (arr[i] === item) {
73
+ return i;
74
+ }
75
+ }
76
+ return -1;
77
+ };
78
+
79
+ //// exported async module functions ////
80
+
81
+ //// nextTick implementation with browser-compatible fallback ////
82
+ if (typeof process === 'undefined' || !(process.nextTick)) {
83
+ async.nextTick = function (fn) {
84
+ setTimeout(fn, 0);
85
+ };
86
+ }
87
+ else {
88
+ async.nextTick = process.nextTick;
89
+ }
90
+
91
+ async.forEach = function (arr, iterator, callback) {
92
+ if (!arr.length) {
93
+ return callback();
94
+ }
95
+ var completed = 0;
96
+ _forEach(arr, function (x) {
97
+ iterator(x, function (err) {
98
+ if (err) {
99
+ callback(err);
100
+ callback = function () {};
101
+ }
102
+ else {
103
+ completed += 1;
104
+ if (completed === arr.length) {
105
+ callback();
106
+ }
107
+ }
108
+ });
109
+ });
110
+ };
111
+
112
+ async.forEachSeries = function (arr, iterator, callback) {
113
+ if (!arr.length) {
114
+ return callback();
115
+ }
116
+ var completed = 0;
117
+ var iterate = function () {
118
+ iterator(arr[completed], function (err) {
119
+ if (err) {
120
+ callback(err);
121
+ callback = function () {};
122
+ }
123
+ else {
124
+ completed += 1;
125
+ if (completed === arr.length) {
126
+ callback();
127
+ }
128
+ else {
129
+ iterate();
130
+ }
131
+ }
132
+ });
133
+ };
134
+ iterate();
135
+ };
136
+
137
+
138
+ var doParallel = function (fn) {
139
+ return function () {
140
+ var args = Array.prototype.slice.call(arguments);
141
+ return fn.apply(null, [async.forEach].concat(args));
142
+ };
143
+ };
144
+ var doSeries = function (fn) {
145
+ return function () {
146
+ var args = Array.prototype.slice.call(arguments);
147
+ return fn.apply(null, [async.forEachSeries].concat(args));
148
+ };
149
+ };
150
+
151
+
152
+ var _asyncMap = function (eachfn, arr, iterator, callback) {
153
+ var results = [];
154
+ arr = _map(arr, function (x, i) {
155
+ return {index: i, value: x};
156
+ });
157
+ eachfn(arr, function (x, callback) {
158
+ iterator(x.value, function (err, v) {
159
+ results[x.index] = v;
160
+ callback(err);
161
+ });
162
+ }, function (err) {
163
+ callback(err, results);
164
+ });
165
+ };
166
+ async.map = doParallel(_asyncMap);
167
+ async.mapSeries = doSeries(_asyncMap);
168
+
169
+
170
+ // reduce only has a series version, as doing reduce in parallel won't
171
+ // work in many situations.
172
+ async.reduce = function (arr, memo, iterator, callback) {
173
+ async.forEachSeries(arr, function (x, callback) {
174
+ iterator(memo, x, function (err, v) {
175
+ memo = v;
176
+ callback(err);
177
+ });
178
+ }, function (err) {
179
+ callback(err, memo);
180
+ });
181
+ };
182
+ // inject alias
183
+ async.inject = async.reduce;
184
+ // foldl alias
185
+ async.foldl = async.reduce;
186
+
187
+ async.reduceRight = function (arr, memo, iterator, callback) {
188
+ var reversed = _map(arr, function (x) {
189
+ return x;
190
+ }).reverse();
191
+ async.reduce(reversed, memo, iterator, callback);
192
+ };
193
+ // foldr alias
194
+ async.foldr = async.reduceRight;
195
+
196
+ var _filter = function (eachfn, arr, iterator, callback) {
197
+ var results = [];
198
+ arr = _map(arr, function (x, i) {
199
+ return {index: i, value: x};
200
+ });
201
+ eachfn(arr, function (x, callback) {
202
+ iterator(x.value, function (v) {
203
+ if (v) {
204
+ results.push(x);
205
+ }
206
+ callback();
207
+ });
208
+ }, function (err) {
209
+ callback(_map(results.sort(function (a, b) {
210
+ return a.index - b.index;
211
+ }), function (x) {
212
+ return x.value;
213
+ }));
214
+ });
215
+ };
216
+ async.filter = doParallel(_filter);
217
+ async.filterSeries = doSeries(_filter);
218
+ // select alias
219
+ async.select = async.filter;
220
+ async.selectSeries = async.filterSeries;
221
+
222
+ var _reject = function (eachfn, arr, iterator, callback) {
223
+ var results = [];
224
+ arr = _map(arr, function (x, i) {
225
+ return {index: i, value: x};
226
+ });
227
+ eachfn(arr, function (x, callback) {
228
+ iterator(x.value, function (v) {
229
+ if (!v) {
230
+ results.push(x);
231
+ }
232
+ callback();
233
+ });
234
+ }, function (err) {
235
+ callback(_map(results.sort(function (a, b) {
236
+ return a.index - b.index;
237
+ }), function (x) {
238
+ return x.value;
239
+ }));
240
+ });
241
+ };
242
+ async.reject = doParallel(_reject);
243
+ async.rejectSeries = doSeries(_reject);
244
+
245
+ var _detect = function (eachfn, arr, iterator, main_callback) {
246
+ eachfn(arr, function (x, callback) {
247
+ iterator(x, function (result) {
248
+ if (result) {
249
+ main_callback(x);
250
+ }
251
+ else {
252
+ callback();
253
+ }
254
+ });
255
+ }, function (err) {
256
+ main_callback();
257
+ });
258
+ };
259
+ async.detect = doParallel(_detect);
260
+ async.detectSeries = doSeries(_detect);
261
+
262
+ async.some = function (arr, iterator, main_callback) {
263
+ async.forEach(arr, function (x, callback) {
264
+ iterator(x, function (v) {
265
+ if (v) {
266
+ main_callback(true);
267
+ main_callback = function () {};
268
+ }
269
+ callback();
270
+ });
271
+ }, function (err) {
272
+ main_callback(false);
273
+ });
274
+ };
275
+ // any alias
276
+ async.any = async.some;
277
+
278
+ async.every = function (arr, iterator, main_callback) {
279
+ async.forEach(arr, function (x, callback) {
280
+ iterator(x, function (v) {
281
+ if (!v) {
282
+ main_callback(false);
283
+ main_callback = function () {};
284
+ }
285
+ callback();
286
+ });
287
+ }, function (err) {
288
+ main_callback(true);
289
+ });
290
+ };
291
+ // all alias
292
+ async.all = async.every;
293
+
294
+ async.sortBy = function (arr, iterator, callback) {
295
+ async.map(arr, function (x, callback) {
296
+ iterator(x, function (err, criteria) {
297
+ if (err) {
298
+ callback(err);
299
+ }
300
+ else {
301
+ callback(null, {value: x, criteria: criteria});
302
+ }
303
+ });
304
+ }, function (err, results) {
305
+ if (err) {
306
+ return callback(err);
307
+ }
308
+ else {
309
+ var fn = function (left, right) {
310
+ var a = left.criteria, b = right.criteria;
311
+ return a < b ? -1 : a > b ? 1 : 0;
312
+ };
313
+ callback(null, _map(results.sort(fn), function (x) {
314
+ return x.value;
315
+ }));
316
+ }
317
+ });
318
+ };
319
+
320
+ async.auto = function (tasks, callback) {
321
+ callback = callback || function () {};
322
+ var keys = _keys(tasks);
323
+ if (!keys.length) {
324
+ return callback(null);
325
+ }
326
+
327
+ var completed = [];
328
+
329
+ var listeners = [];
330
+ var addListener = function (fn) {
331
+ listeners.unshift(fn);
332
+ };
333
+ var removeListener = function (fn) {
334
+ for (var i = 0; i < listeners.length; i += 1) {
335
+ if (listeners[i] === fn) {
336
+ listeners.splice(i, 1);
337
+ return;
338
+ }
339
+ }
340
+ };
341
+ var taskComplete = function () {
342
+ _forEach(listeners, function (fn) {
343
+ fn();
344
+ });
345
+ };
346
+
347
+ addListener(function () {
348
+ if (completed.length === keys.length) {
349
+ callback(null);
350
+ }
351
+ });
352
+
353
+ _forEach(keys, function (k) {
354
+ var task = (tasks[k] instanceof Function) ? [tasks[k]]: tasks[k];
355
+ var taskCallback = function (err) {
356
+ if (err) {
357
+ callback(err);
358
+ // stop subsequent errors hitting callback multiple times
359
+ callback = function () {};
360
+ }
361
+ else {
362
+ completed.push(k);
363
+ taskComplete();
364
+ }
365
+ };
366
+ var requires = task.slice(0, Math.abs(task.length - 1)) || [];
367
+ var ready = function () {
368
+ return _reduce(requires, function (a, x) {
369
+ return (a && _indexOf(completed, x) !== -1);
370
+ }, true);
371
+ };
372
+ if (ready()) {
373
+ task[task.length - 1](taskCallback);
374
+ }
375
+ else {
376
+ var listener = function () {
377
+ if (ready()) {
378
+ removeListener(listener);
379
+ task[task.length - 1](taskCallback);
380
+ }
381
+ };
382
+ addListener(listener);
383
+ }
384
+ });
385
+ };
386
+
387
+ async.waterfall = function (tasks, callback) {
388
+ if (!tasks.length) {
389
+ return callback();
390
+ }
391
+ callback = callback || function () {};
392
+ var wrapIterator = function (iterator) {
393
+ return function (err) {
394
+ if (err) {
395
+ callback(err);
396
+ callback = function () {};
397
+ }
398
+ else {
399
+ var args = Array.prototype.slice.call(arguments, 1);
400
+ var next = iterator.next();
401
+ if (next) {
402
+ args.push(wrapIterator(next));
403
+ }
404
+ else {
405
+ args.push(callback);
406
+ }
407
+ async.nextTick(function () {
408
+ iterator.apply(null, args);
409
+ });
410
+ }
411
+ };
412
+ };
413
+ wrapIterator(async.iterator(tasks))();
414
+ };
415
+
416
+ async.parallel = function (tasks, callback) {
417
+ callback = callback || function () {};
418
+ if (tasks.constructor === Array) {
419
+ async.map(tasks, function (fn, callback) {
420
+ if (fn) {
421
+ fn(function (err) {
422
+ var args = Array.prototype.slice.call(arguments, 1);
423
+ if (args.length <= 1) {
424
+ args = args[0];
425
+ }
426
+ callback.call(null, err, args || null);
427
+ });
428
+ }
429
+ }, callback);
430
+ }
431
+ else {
432
+ var results = {};
433
+ async.forEach(_keys(tasks), function (k, callback) {
434
+ tasks[k](function (err) {
435
+ var args = Array.prototype.slice.call(arguments, 1);
436
+ if (args.length <= 1) {
437
+ args = args[0];
438
+ }
439
+ results[k] = args;
440
+ callback(err);
441
+ });
442
+ }, function (err) {
443
+ callback(err, results);
444
+ });
445
+ }
446
+ };
447
+
448
+ async.series = function (tasks, callback) {
449
+ callback = callback || function () {};
450
+ if (tasks.constructor === Array) {
451
+ async.mapSeries(tasks, function (fn, callback) {
452
+ if (fn) {
453
+ fn(function (err) {
454
+ var args = Array.prototype.slice.call(arguments, 1);
455
+ if (args.length <= 1) {
456
+ args = args[0];
457
+ }
458
+ callback.call(null, err, args || null);
459
+ });
460
+ }
461
+ }, callback);
462
+ }
463
+ else {
464
+ var results = {};
465
+ async.forEachSeries(_keys(tasks), function (k, callback) {
466
+ tasks[k](function (err) {
467
+ var args = Array.prototype.slice.call(arguments, 1);
468
+ if (args.length <= 1) {
469
+ args = args[0];
470
+ }
471
+ results[k] = args;
472
+ callback(err);
473
+ });
474
+ }, function (err) {
475
+ callback(err, results);
476
+ });
477
+ }
478
+ };
479
+
480
+ async.iterator = function (tasks) {
481
+ var makeCallback = function (index) {
482
+ var fn = function () {
483
+ if (tasks.length) {
484
+ tasks[index].apply(null, arguments);
485
+ }
486
+ return fn.next();
487
+ };
488
+ fn.next = function () {
489
+ return (index < tasks.length - 1) ? makeCallback(index + 1): null;
490
+ };
491
+ return fn;
492
+ };
493
+ return makeCallback(0);
494
+ };
495
+
496
+ async.apply = function (fn) {
497
+ var args = Array.prototype.slice.call(arguments, 1);
498
+ return function () {
499
+ return fn.apply(
500
+ null, args.concat(Array.prototype.slice.call(arguments))
501
+ );
502
+ };
503
+ };
504
+
505
+ var _concat = function (eachfn, arr, fn, callback) {
506
+ var r = [];
507
+ eachfn(arr, function (x, cb) {
508
+ fn(x, function (err, y) {
509
+ r = r.concat(y || []);
510
+ cb(err);
511
+ });
512
+ }, function (err) {
513
+ callback(err, r);
514
+ });
515
+ };
516
+ async.concat = doParallel(_concat);
517
+ async.concatSeries = doSeries(_concat);
518
+
519
+ async.whilst = function (test, iterator, callback) {
520
+ if (test()) {
521
+ iterator(function (err) {
522
+ if (err) {
523
+ return callback(err);
524
+ }
525
+ async.whilst(test, iterator, callback);
526
+ });
527
+ }
528
+ else {
529
+ callback();
530
+ }
531
+ };
532
+
533
+ async.until = function (test, iterator, callback) {
534
+ if (!test()) {
535
+ iterator(function (err) {
536
+ if (err) {
537
+ return callback(err);
538
+ }
539
+ async.until(test, iterator, callback);
540
+ });
541
+ }
542
+ else {
543
+ callback();
544
+ }
545
+ };
546
+
547
+ async.queue = function (worker, concurrency) {
548
+ var workers = 0;
549
+ var tasks = [];
550
+ var q = {
551
+ concurrency: concurrency,
552
+ push: function (data, callback) {
553
+ tasks.push({data: data, callback: callback});
554
+ async.nextTick(q.process);
555
+ },
556
+ process: function () {
557
+ if (workers < q.concurrency && tasks.length) {
558
+ var task = tasks.splice(0, 1)[0];
559
+ workers += 1;
560
+ worker(task.data, function () {
561
+ workers -= 1;
562
+ if (task.callback) {
563
+ task.callback.apply(task, arguments);
564
+ }
565
+ q.process();
566
+ });
567
+ }
568
+ },
569
+ length: function () {
570
+ return tasks.length;
571
+ }
572
+ };
573
+ return q;
574
+ };
575
+
576
+ var _console_fn = function (name) {
577
+ return function (fn) {
578
+ var args = Array.prototype.slice.call(arguments, 1);
579
+ fn.apply(null, args.concat([function (err) {
580
+ var args = Array.prototype.slice.call(arguments, 1);
581
+ if (typeof console !== 'undefined') {
582
+ if (err) {
583
+ if (console.error) {
584
+ console.error(err);
585
+ }
586
+ }
587
+ else if (console[name]) {
588
+ _forEach(args, function (x) {
589
+ console[name](x);
590
+ });
591
+ }
592
+ }
593
+ }]));
594
+ };
595
+ };
596
+ async.log = _console_fn('log');
597
+ async.dir = _console_fn('dir');
598
+ /*async.info = _console_fn('info');
599
+ async.warn = _console_fn('warn');
600
+ async.error = _console_fn('error');*/
601
+
602
+ async.memoize = function (fn, hasher) {
603
+ var memo = {};
604
+ hasher = hasher || function (x) {
605
+ return x;
606
+ };
607
+ return function () {
608
+ var args = Array.prototype.slice.call(arguments);
609
+ var callback = args.pop();
610
+ var key = hasher.apply(null, args);
611
+ if (key in memo) {
612
+ callback.apply(null, memo[key]);
613
+ }
614
+ else {
615
+ fn.apply(null, args.concat([function () {
616
+ memo[key] = arguments;
617
+ callback.apply(null, arguments);
618
+ }]));
619
+ }
620
+ };
621
+ };
622
+
623
+ }());
@@ -0,0 +1,55 @@
1
+ /*
2
+ A console.log that won't leave you hanging when node exits
3
+ 90% of this file was ripped from node.js
4
+
5
+ License: see: https://github.com/joyent/node/blob/master/lib/console.js
6
+ */
7
+
8
+ // console object
9
+ var formatRegExp = /%[sdj]/g;
10
+ function format(f) {
11
+ var util = require('util');
12
+
13
+ if (typeof f !== 'string') {
14
+ var objects = [];
15
+ for (var i = 0; i < arguments.length; i++) {
16
+ objects.push(util.inspect(arguments[i]));
17
+ }
18
+ return objects.join(' ');
19
+ }
20
+
21
+
22
+ var i = 1;
23
+ var args = arguments;
24
+ var str = String(f).replace(formatRegExp, function(x) {
25
+ switch (x) {
26
+ case '%s': return String(args[i++]);
27
+ case '%d': return Number(args[i++]);
28
+ case '%j': return JSON.stringify(args[i++]);
29
+ default:
30
+ return x;
31
+ }
32
+ });
33
+ for (var len = args.length, x = args[i]; i < len; x = args[++i]) {
34
+ if (x === null || typeof x !== 'object') {
35
+ str += ' ' + x;
36
+ } else {
37
+ str += ' ' + util.inspect(x);
38
+ }
39
+ }
40
+ return str;
41
+ }
42
+
43
+ console.log = function() {
44
+ var res = process.stdout.write(format.apply(this, arguments) + '\n');
45
+
46
+ // this is the first time stdout got backed up
47
+ if (!res && !process.stdout.pendingWrite) {
48
+ process.stdout.pendingWrite = true;
49
+
50
+ // magic sauce: keep node alive until stdout has flushed
51
+ process.stdout.once('drain', function () {
52
+ process.stdout.draining = false;
53
+ });
54
+ }
55
+ };