sugar-rails 1.3.7 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +7 -0
  2. data/.ruby-gemset +1 -0
  3. data/.ruby-version +1 -0
  4. data/README.md +3 -50
  5. data/{vendor → app}/assets/javascripts/sugar-development.js +1914 -1225
  6. data/app/assets/javascripts/sugar-full.js +200 -0
  7. data/app/assets/javascripts/sugar.js +132 -0
  8. data/copy_release.sh +4 -7
  9. data/lib/sugar/rails/version.rb +2 -2
  10. metadata +16 -58
  11. data/.rvmrc +0 -1
  12. data/lib/generators/sugar/build/build_generator.rb +0 -107
  13. data/lib/generators/sugar/install/install_generator.rb +0 -35
  14. data/vendor/assets/javascripts/precompiled/development/array.js +0 -1203
  15. data/vendor/assets/javascripts/precompiled/development/core.js +0 -365
  16. data/vendor/assets/javascripts/precompiled/development/date.js +0 -2267
  17. data/vendor/assets/javascripts/precompiled/development/date_locales.js +0 -1179
  18. data/vendor/assets/javascripts/precompiled/development/date_ranges.js +0 -208
  19. data/vendor/assets/javascripts/precompiled/development/es5.js +0 -474
  20. data/vendor/assets/javascripts/precompiled/development/function.js +0 -224
  21. data/vendor/assets/javascripts/precompiled/development/inflections.js +0 -410
  22. data/vendor/assets/javascripts/precompiled/development/language.js +0 -383
  23. data/vendor/assets/javascripts/precompiled/development/number.js +0 -428
  24. data/vendor/assets/javascripts/precompiled/development/object.js +0 -419
  25. data/vendor/assets/javascripts/precompiled/development/regexp.js +0 -92
  26. data/vendor/assets/javascripts/precompiled/development/string.js +0 -894
  27. data/vendor/assets/javascripts/precompiled/minified/array.js +0 -18
  28. data/vendor/assets/javascripts/precompiled/minified/core.js +0 -9
  29. data/vendor/assets/javascripts/precompiled/minified/date.js +0 -44
  30. data/vendor/assets/javascripts/precompiled/minified/date_locales.js +0 -49
  31. data/vendor/assets/javascripts/precompiled/minified/date_ranges.js +0 -4
  32. data/vendor/assets/javascripts/precompiled/minified/es5.js +0 -8
  33. data/vendor/assets/javascripts/precompiled/minified/function.js +0 -4
  34. data/vendor/assets/javascripts/precompiled/minified/inflections.js +0 -11
  35. data/vendor/assets/javascripts/precompiled/minified/language.js +0 -19
  36. data/vendor/assets/javascripts/precompiled/minified/number.js +0 -5
  37. data/vendor/assets/javascripts/precompiled/minified/object.js +0 -6
  38. data/vendor/assets/javascripts/precompiled/minified/regexp.js +0 -2
  39. data/vendor/assets/javascripts/precompiled/minified/string.js +0 -12
  40. data/vendor/assets/javascripts/precompiled/readme.txt +0 -3
  41. data/vendor/assets/javascripts/sugar-full.js +0 -199
  42. data/vendor/assets/javascripts/sugar.js +0 -120
@@ -1,419 +0,0 @@
1
- /***
2
- * @package Object
3
- * @dependency core
4
- * @description Object manipulation, type checking (isNumber, isString, ...), extended objects with hash-like methods available as instance methods.
5
- *
6
- * Much thanks to kangax for his informative aricle about how problems with instanceof and constructor
7
- * http://perfectionkills.com/instanceof-considered-harmful-or-how-to-write-a-robust-isarray/
8
- *
9
- ***/
10
-
11
- var ObjectTypeMethods = 'isObject,isNaN'.split(',');
12
- var ObjectHashMethods = 'keys,values,select,reject,each,merge,clone,equal,watch,tap,has'.split(',');
13
-
14
- function setParamsObject(obj, param, value, deep) {
15
- var reg = /^(.+?)(\[.*\])$/, paramIsArray, match, allKeys, key;
16
- if(deep !== false && (match = param.match(reg))) {
17
- key = match[1];
18
- allKeys = match[2].replace(/^\[|\]$/g, '').split('][');
19
- allKeys.forEach(function(k) {
20
- paramIsArray = !k || k.match(/^\d+$/);
21
- if(!key && isArray(obj)) key = obj.length;
22
- if(!hasOwnProperty(obj, key)) {
23
- obj[key] = paramIsArray ? [] : {};
24
- }
25
- obj = obj[key];
26
- key = k;
27
- });
28
- if(!key && paramIsArray) key = obj.length.toString();
29
- setParamsObject(obj, key, value);
30
- } else if(value.match(/^[+-]?\d+(\.\d+)?$/)) {
31
- obj[param] = parseFloat(value);
32
- } else if(value === 'true') {
33
- obj[param] = true;
34
- } else if(value === 'false') {
35
- obj[param] = false;
36
- } else {
37
- obj[param] = value;
38
- }
39
- }
40
-
41
- function matchKey(key, match) {
42
- if(isRegExp(match)) {
43
- return match.test(key);
44
- } else if(isObjectPrimitive(match)) {
45
- return hasOwnProperty(match, key);
46
- } else {
47
- return key === string(match);
48
- }
49
- }
50
-
51
- function selectFromObject(obj, args, select) {
52
- var result = {}, match;
53
- iterateOverObject(obj, function(key, value) {
54
- match = false;
55
- flattenedArgs(args, function(arg) {
56
- if(matchKey(key, arg)) {
57
- match = true;
58
- }
59
- }, 1);
60
- if(match === select) {
61
- result[key] = value;
62
- }
63
- });
64
- return result;
65
- }
66
-
67
-
68
- /***
69
- * @method Object.is[Type](<obj>)
70
- * @returns Boolean
71
- * @short Returns true if <obj> is an object of that type.
72
- * @extra %isObject% will return false on anything that is not an object literal, including instances of inherited classes. Note also that %isNaN% will ONLY return true if the object IS %NaN%. It does not mean the same as browser native %isNaN%, which returns true for anything that is "not a number".
73
- *
74
- * @set
75
- * isArray
76
- * isObject
77
- * isBoolean
78
- * isDate
79
- * isFunction
80
- * isNaN
81
- * isNumber
82
- * isString
83
- * isRegExp
84
- *
85
- * @example
86
- *
87
- * Object.isArray([1,2,3]) -> true
88
- * Object.isDate(3) -> false
89
- * Object.isRegExp(/wasabi/) -> true
90
- * Object.isObject({ broken:'wear' }) -> true
91
- *
92
- ***/
93
- function buildTypeMethods() {
94
- extendSimilar(object, false, false, ClassNames, function(methods, name) {
95
- var method = 'is' + name;
96
- ObjectTypeMethods.push(method);
97
- methods[method] = function(obj) {
98
- return className(obj) === '[object '+name+']';
99
- }
100
- });
101
- }
102
-
103
- function buildObjectExtend() {
104
- extend(object, false, function(){ return arguments.length === 0; }, {
105
- 'extend': function() {
106
- var methods = ObjectTypeMethods.concat(ObjectHashMethods)
107
- if(typeof EnumerableMethods !== 'undefined') {
108
- methods = methods.concat(EnumerableMethods);
109
- }
110
- buildObjectInstanceMethods(methods, object);
111
- }
112
- });
113
- }
114
-
115
- extend(object, false, true, {
116
- /***
117
- * @method watch(<obj>, <prop>, <fn>)
118
- * @returns Nothing
119
- * @short Watches a property of <obj> and runs <fn> when it changes.
120
- * @extra <fn> is passed three arguments: the property <prop>, the old value, and the new value. The return value of [fn] will be set as the new value. This method is useful for things such as validating or cleaning the value when it is set. Warning: this method WILL NOT work in browsers that don't support %Object.defineProperty%. This notably includes IE 8 and below, and Opera. This is the only method in Sugar that is not fully compatible with all browsers. %watch% is available as an instance method on extended objects.
121
- * @example
122
- *
123
- * Object.watch({ foo: 'bar' }, 'foo', function(prop, oldVal, newVal) {
124
- * // Will be run when the property 'foo' is set on the object.
125
- * });
126
- * Object.extended().watch({ foo: 'bar' }, 'foo', function(prop, oldVal, newVal) {
127
- * // Will be run when the property 'foo' is set on the object.
128
- * });
129
- *
130
- ***/
131
- 'watch': function(obj, prop, fn) {
132
- if(!definePropertySupport) return;
133
- var value = obj[prop];
134
- object.defineProperty(obj, prop, {
135
- 'enumerable' : true,
136
- 'configurable': true,
137
- 'get': function() {
138
- return value;
139
- },
140
- 'set': function(to) {
141
- value = fn.call(obj, prop, value, to);
142
- }
143
- });
144
- }
145
- });
146
-
147
- extend(object, false, function(arg1, arg2) { return isFunction(arg2); }, {
148
-
149
- /***
150
- * @method keys(<obj>, [fn])
151
- * @returns Array
152
- * @short Returns an array containing the keys in <obj>. Optionally calls [fn] for each key.
153
- * @extra This method is provided for browsers that don't support it natively, and additionally is enhanced to accept the callback [fn]. Returned keys are in no particular order. %keys% is available as an instance method on extended objects.
154
- * @example
155
- *
156
- * Object.keys({ broken: 'wear' }) -> ['broken']
157
- * Object.keys({ broken: 'wear' }, function(key, value) {
158
- * // Called once for each key.
159
- * });
160
- * Object.extended({ broken: 'wear' }).keys() -> ['broken']
161
- *
162
- ***/
163
- 'keys': function(obj, fn) {
164
- var keys = object.keys(obj);
165
- keys.forEach(function(key) {
166
- fn.call(obj, key, obj[key]);
167
- });
168
- return keys;
169
- }
170
-
171
- });
172
-
173
- extend(object, false, false, {
174
-
175
- 'isObject': function(obj) {
176
- return isObject(obj);
177
- },
178
-
179
- 'isNaN': function(obj) {
180
- // This is only true of NaN
181
- return isNumber(obj) && obj.valueOf() !== obj.valueOf();
182
- },
183
-
184
- /***
185
- * @method equal(<a>, <b>)
186
- * @returns Boolean
187
- * @short Returns true if <a> and <b> are equal.
188
- * @extra %equal% in Sugar is "egal", meaning the values are equal if they are "not observably distinguishable". Note that on extended objects the name is %equals% for readability.
189
- * @example
190
- *
191
- * Object.equal({a:2}, {a:2}) -> true
192
- * Object.equal({a:2}, {a:3}) -> false
193
- * Object.extended({a:2}).equals({a:3}) -> false
194
- *
195
- ***/
196
- 'equal': function(a, b) {
197
- return isEqual(a, b);
198
- },
199
-
200
- /***
201
- * @method Object.extended(<obj> = {})
202
- * @returns Extended object
203
- * @short Creates a new object, equivalent to %new Object()% or %{}%, but with extended methods.
204
- * @extra See extended objects for more.
205
- * @example
206
- *
207
- * Object.extended()
208
- * Object.extended({ happy:true, pappy:false }).keys() -> ['happy','pappy']
209
- * Object.extended({ happy:true, pappy:false }).values() -> [true, false]
210
- *
211
- ***/
212
- 'extended': function(obj) {
213
- return new Hash(obj);
214
- },
215
-
216
- /***
217
- * @method merge(<target>, <source>, [deep] = false, [resolve] = true)
218
- * @returns Merged object
219
- * @short Merges all the properties of <source> into <target>.
220
- * @extra Merges are shallow unless [deep] is %true%. Properties of <source> will win in the case of conflicts, unless [resolve] is %false%. [resolve] can also be a function that resolves the conflict. In this case it will be passed 3 arguments, %key%, %targetVal%, and %sourceVal%, with the context set to <source>. This will allow you to solve conflict any way you want, ie. adding two numbers together, etc. %merge% is available as an instance method on extended objects.
221
- * @example
222
- *
223
- * Object.merge({a:1},{b:2}) -> { a:1, b:2 }
224
- * Object.merge({a:1},{a:2}, false, false) -> { a:1 }
225
- + Object.merge({a:1},{a:2}, false, function(key, a, b) {
226
- * return a + b;
227
- * }); -> { a:3 }
228
- * Object.extended({a:1}).merge({b:2}) -> { a:1, b:2 }
229
- *
230
- ***/
231
- 'merge': function(target, source, deep, resolve) {
232
- var key, val;
233
- // Strings cannot be reliably merged thanks to
234
- // their properties not being enumerable in < IE8.
235
- if(target && typeof source != 'string') {
236
- for(key in source) {
237
- if(!hasOwnProperty(source, key) || !target) continue;
238
- val = source[key];
239
- // Conflict!
240
- if(isDefined(target[key])) {
241
- // Do not merge.
242
- if(resolve === false) {
243
- continue;
244
- }
245
- // Use the result of the callback as the result.
246
- if(isFunction(resolve)) {
247
- val = resolve.call(source, key, target[key], source[key])
248
- }
249
- }
250
- // Deep merging.
251
- if(deep === true && val && isObjectPrimitive(val)) {
252
- if(isDate(val)) {
253
- val = new date(val.getTime());
254
- } else if(isRegExp(val)) {
255
- val = new regexp(val.source, getRegExpFlags(val));
256
- } else {
257
- if(!target[key]) target[key] = array.isArray(val) ? [] : {};
258
- object.merge(target[key], source[key], deep, resolve);
259
- continue;
260
- }
261
- }
262
- target[key] = val;
263
- }
264
- }
265
- return target;
266
- },
267
-
268
- /***
269
- * @method values(<obj>, [fn])
270
- * @returns Array
271
- * @short Returns an array containing the values in <obj>. Optionally calls [fn] for each value.
272
- * @extra Returned values are in no particular order. %values% is available as an instance method on extended objects.
273
- * @example
274
- *
275
- * Object.values({ broken: 'wear' }) -> ['wear']
276
- * Object.values({ broken: 'wear' }, function(value) {
277
- * // Called once for each value.
278
- * });
279
- * Object.extended({ broken: 'wear' }).values() -> ['wear']
280
- *
281
- ***/
282
- 'values': function(obj, fn) {
283
- var values = [];
284
- iterateOverObject(obj, function(k,v) {
285
- values.push(v);
286
- if(fn) fn.call(obj,v);
287
- });
288
- return values;
289
- },
290
-
291
- /***
292
- * @method clone(<obj> = {}, [deep] = false)
293
- * @returns Cloned object
294
- * @short Creates a clone (copy) of <obj>.
295
- * @extra Default is a shallow clone, unless [deep] is true. %clone% is available as an instance method on extended objects.
296
- * @example
297
- *
298
- * Object.clone({foo:'bar'}) -> { foo: 'bar' }
299
- * Object.clone() -> {}
300
- * Object.extended({foo:'bar'}).clone() -> { foo: 'bar' }
301
- *
302
- ***/
303
- 'clone': function(obj, deep) {
304
- var target;
305
- if(!isObjectPrimitive(obj)) return obj;
306
- if (obj instanceof Hash) {
307
- target = new Hash;
308
- } else {
309
- target = new obj.constructor;
310
- }
311
- return object.merge(target, obj, deep);
312
- },
313
-
314
- /***
315
- * @method Object.fromQueryString(<str>, [deep] = true)
316
- * @returns Object
317
- * @short Converts the query string of a URL into an object.
318
- * @extra If [deep] is %false%, conversion will only accept shallow params (ie. no object or arrays with %[]% syntax) as these are not universally supported.
319
- * @example
320
- *
321
- * Object.fromQueryString('foo=bar&broken=wear') -> { foo: 'bar', broken: 'wear' }
322
- * Object.fromQueryString('foo[]=1&foo[]=2') -> { foo: [1,2] }
323
- *
324
- ***/
325
- 'fromQueryString': function(str, deep) {
326
- var result = object.extended(), split;
327
- str = str && str.toString ? str.toString() : '';
328
- str.replace(/^.*?\?/, '').split('&').forEach(function(p) {
329
- var split = p.split('=');
330
- if(split.length !== 2) return;
331
- setParamsObject(result, split[0], decodeURIComponent(split[1]), deep);
332
- });
333
- return result;
334
- },
335
-
336
- /***
337
- * @method tap(<obj>, <fn>)
338
- * @returns Object
339
- * @short Runs <fn> and returns <obj>.
340
- * @extra A string can also be used as a shortcut to a method. This method is used to run an intermediary function in the middle of method chaining. As a standalone method on the Object class it doesn't have too much use. The power of %tap% comes when using extended objects or modifying the Object prototype with Object.extend().
341
- * @example
342
- *
343
- * Object.extend();
344
- * [2,4,6].map(Math.exp).tap(function(arr) {
345
- * arr.pop()
346
- * });
347
- * [2,4,6].map(Math.exp).tap('pop').map(Math.round); -> [7,55]
348
- *
349
- ***/
350
- 'tap': function(obj, arg) {
351
- var fn = arg;
352
- if(!isFunction(arg)) {
353
- fn = function() {
354
- if(arg) obj[arg]();
355
- }
356
- }
357
- fn.call(obj, obj);
358
- return obj;
359
- },
360
-
361
- /***
362
- * @method has(<obj>, <key>)
363
- * @returns Boolean
364
- * @short Checks if <obj> has <key> using hasOwnProperty from Object.prototype.
365
- * @extra This method is considered safer than %Object#hasOwnProperty% when using objects as hashes. See http://www.devthought.com/2012/01/18/an-object-is-not-a-hash/ for more.
366
- * @example
367
- *
368
- * Object.has({ foo: 'bar' }, 'foo') -> true
369
- * Object.has({ foo: 'bar' }, 'baz') -> false
370
- * Object.has({ hasOwnProperty: true }, 'foo') -> false
371
- *
372
- ***/
373
- 'has': function (obj, key) {
374
- return hasOwnProperty(obj, key);
375
- },
376
-
377
- /***
378
- * @method select(<obj>, <find>, ...)
379
- * @returns Object
380
- * @short Builds a new object containing the values specified in <find>.
381
- * @extra When <find> is a string, that single key will be selected. It can also be a regex, selecting any key that matches, or an object which will match if the key also exists in that object, effectively doing an "intersect" operation on that object. Multiple selections may also be passed as an array or directly as enumerated arguments. %select% is available as an instance method on extended objects.
382
- * @example
383
- *
384
- * Object.select({a:1,b:2}, 'a') -> {a:1}
385
- * Object.select({a:1,b:2}, /[a-z]/) -> {a:1,ba:2}
386
- * Object.select({a:1,b:2}, {a:1}) -> {a:1}
387
- * Object.select({a:1,b:2}, 'a', 'b') -> {a:1,b:2}
388
- * Object.select({a:1,b:2}, ['a', 'b']) -> {a:1,b:2}
389
- *
390
- ***/
391
- 'select': function (obj) {
392
- return selectFromObject(obj, arguments, true);
393
- },
394
-
395
- /***
396
- * @method reject(<obj>, <find>, ...)
397
- * @returns Object
398
- * @short Builds a new object containing all values except those specified in <find>.
399
- * @extra When <find> is a string, that single key will be rejected. It can also be a regex, rejecting any key that matches, or an object which will match if the key also exists in that object, effectively "subtracting" that object. Multiple selections may also be passed as an array or directly as enumerated arguments. %reject% is available as an instance method on extended objects.
400
- * @example
401
- *
402
- * Object.reject({a:1,b:2}, 'a') -> {b:2}
403
- * Object.reject({a:1,b:2}, /[a-z]/) -> {}
404
- * Object.reject({a:1,b:2}, {a:1}) -> {b:2}
405
- * Object.reject({a:1,b:2}, 'a', 'b') -> {}
406
- * Object.reject({a:1,b:2}, ['a', 'b']) -> {}
407
- *
408
- ***/
409
- 'reject': function (obj) {
410
- return selectFromObject(obj, arguments, false);
411
- }
412
-
413
- });
414
-
415
-
416
- buildTypeMethods();
417
- buildObjectExtend();
418
- buildObjectInstanceMethods(ObjectHashMethods, Hash);
419
-
@@ -1,92 +0,0 @@
1
-
2
- /***
3
- * @package RegExp
4
- * @dependency core
5
- * @description Escaping regexes and manipulating their flags.
6
- *
7
- * Note here that methods on the RegExp class like .exec and .test will fail in the current version of SpiderMonkey being
8
- * used by CouchDB when using shorthand regex notation like /foo/. This is the reason for the intermixed use of shorthand
9
- * and compiled regexes here. If you're using JS in CouchDB, it is safer to ALWAYS compile your regexes from a string.
10
- *
11
- ***/
12
-
13
- function uniqueRegExpFlags(flags) {
14
- return flags.split('').sort().join('').replace(/([gimy])\1+/g, '$1');
15
- }
16
-
17
- extend(regexp, false, false, {
18
-
19
- /***
20
- * @method RegExp.escape(<str> = '')
21
- * @returns String
22
- * @short Escapes all RegExp tokens in a string.
23
- * @example
24
- *
25
- * RegExp.escape('really?') -> 'really\?'
26
- * RegExp.escape('yes.') -> 'yes\.'
27
- * RegExp.escape('(not really)') -> '\(not really\)'
28
- *
29
- ***/
30
- 'escape': function(str) {
31
- return escapeRegExp(str);
32
- }
33
-
34
- });
35
-
36
- extend(regexp, true, false, {
37
-
38
- /***
39
- * @method getFlags()
40
- * @returns String
41
- * @short Returns the flags of the regex as a string.
42
- * @example
43
- *
44
- * /texty/gim.getFlags('testy') -> 'gim'
45
- *
46
- ***/
47
- 'getFlags': function() {
48
- return getRegExpFlags(this);
49
- },
50
-
51
- /***
52
- * @method setFlags(<flags>)
53
- * @returns RegExp
54
- * @short Sets the flags on a regex and retuns a copy.
55
- * @example
56
- *
57
- * /texty/.setFlags('gim') -> now has global, ignoreCase, and multiline set
58
- *
59
- ***/
60
- 'setFlags': function(flags) {
61
- return regexp(this.source, flags);
62
- },
63
-
64
- /***
65
- * @method addFlag(<flag>)
66
- * @returns RegExp
67
- * @short Adds <flag> to the regex.
68
- * @example
69
- *
70
- * /texty/.addFlag('g') -> now has global flag set
71
- *
72
- ***/
73
- 'addFlag': function(flag) {
74
- return this.setFlags(getRegExpFlags(this, flag));
75
- },
76
-
77
- /***
78
- * @method removeFlag(<flag>)
79
- * @returns RegExp
80
- * @short Removes <flag> from the regex.
81
- * @example
82
- *
83
- * /texty/g.removeFlag('g') -> now has global flag removed
84
- *
85
- ***/
86
- 'removeFlag': function(flag) {
87
- return this.setFlags(getRegExpFlags(this).replace(flag, ''));
88
- }
89
-
90
- });
91
-
92
-