sugar-rails 1.2.5 → 1.2.5.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,520 @@
1
+ (function(context) {
2
+
3
+ /***
4
+ * String module
5
+ *
6
+ ***/
7
+
8
+
9
+ var globalContext,
10
+ plurals = [],
11
+ singulars = [],
12
+ uncountables = [],
13
+ humans = [],
14
+ acronyms = {},
15
+ Downcased,
16
+ Normalize,
17
+ Inflector;
18
+
19
+ globalContext = typeof global !== 'undefined' ? global : context;
20
+
21
+ function removeFromUncountablesAndAddTo(arr, rule, replacement) {
22
+ if(Object.isString(rule)) {
23
+ uncountables.remove(rule);
24
+ }
25
+ uncountables.remove(replacement)
26
+ arr.unshift({ rule: rule, replacement: replacement })
27
+ }
28
+
29
+ function paramMatchesType(param, type) {
30
+ return param == type || param == 'all' || !param;
31
+ }
32
+
33
+ function isUncountable(word) {
34
+ return uncountables.any(function(uncountable) {
35
+ return new RegExp('\\b' + uncountable + '$', 'i').test(word);
36
+ });
37
+ }
38
+
39
+ function inflect(word, pluralize) {
40
+ word = Object.isString(word) ? word.toString() : '';
41
+ if(word.isBlank() || isUncountable(word)) {
42
+ return word;
43
+ } else {
44
+ return runReplacements(word, pluralize ? plurals : singulars);
45
+ }
46
+ }
47
+
48
+ function runReplacements(word, table) {
49
+ table.each(function(inflection) {
50
+ if(word.match(inflection.rule)) {
51
+ word = word.replace(inflection.rule, inflection.replacement);
52
+ return false;
53
+ }
54
+ });
55
+ return word;
56
+ }
57
+
58
+ function capitalize(word) {
59
+ return word.replace(/^\W*[a-z]/, function(w){
60
+ return w.toUpperCase();
61
+ });
62
+ }
63
+
64
+ Inflector = {
65
+
66
+ /*
67
+ * Specifies a new acronym. An acronym must be specified as it will appear in a camelized string. An underscore
68
+ * string that contains the acronym will retain the acronym when passed to %camelize%, %humanize%, or %titleize%.
69
+ * A camelized string that contains the acronym will maintain the acronym when titleized or humanized, and will
70
+ * convert the acronym into a non-delimited single lowercase word when passed to String#underscore.
71
+ *
72
+ * Examples:
73
+ * String.Inflector.acronym('HTML')
74
+ * 'html'.titleize() -> 'HTML'
75
+ * 'html'.camelize() -> 'HTML'
76
+ * 'MyHTML'.underscore() -> 'my_html'
77
+ *
78
+ * The acronym, however, must occur as a delimited unit and not be part of another word for conversions to recognize it:
79
+ *
80
+ * String.Inflector.acronym('HTTP')
81
+ * 'my_http_delimited'.camelize() -> 'MyHTTPDelimited'
82
+ * 'https'.camelize() -> 'Https', not 'HTTPs'
83
+ * 'HTTPS'.underscore() -> 'http_s', not 'https'
84
+ *
85
+ * String.Inflector.acronym('HTTPS')
86
+ * 'https'.camelize() -> 'HTTPS'
87
+ * 'HTTPS'.underscore() -> 'https'
88
+ *
89
+ * Note: Acronyms that are passed to %pluralize% will no longer be recognized, since the acronym will not occur as
90
+ * a delimited unit in the pluralized result. To work around this, you must specify the pluralized form as an
91
+ * acronym as well:
92
+ *
93
+ * String.Inflector.acronym('API')
94
+ * 'api'.pluralize().camelize() -> 'Apis'
95
+ *
96
+ * String.Inflector.acronym('APIs')
97
+ * 'api'.pluralize().camelize() -> 'APIs'
98
+ *
99
+ * %acronym% may be used to specify any word that contains an acronym or otherwise needs to maintain a non-standard
100
+ * capitalization. The only restriction is that the word must begin with a capital letter.
101
+ *
102
+ * Examples:
103
+ * String.Inflector.acronym('RESTful')
104
+ * 'RESTful'.underscore() -> 'restful'
105
+ * 'RESTfulController'.underscore() -> 'restful_controller'
106
+ * 'RESTfulController'.titleize() -> 'RESTful Controller'
107
+ * 'restful'.camelize() -> 'RESTful'
108
+ * 'restful_controller'.camelize() -> 'RESTfulController'
109
+ *
110
+ * String.Inflector.acronym('McDonald')
111
+ * 'McDonald'.underscore() -> 'mcdonald'
112
+ * 'mcdonald'.camelize() -> 'McDonald'
113
+ */
114
+ 'acronym': function(word) {
115
+ acronyms[word.toLowerCase()] = word;
116
+ Inflector.acronymRegExp = new RegExp(Object.values(acronyms).join('|'), 'g');
117
+ },
118
+
119
+ /*
120
+ * Specifies a new pluralization rule and its replacement. The rule can either be a string or a regular expression.
121
+ * The replacement should always be a string that may include references to the matched data from the rule.
122
+ */
123
+ 'plural': function(rule, replacement) {
124
+ removeFromUncountablesAndAddTo(plurals, rule, replacement);
125
+ },
126
+
127
+ /*
128
+ * Specifies a new singularization rule and its replacement. The rule can either be a string or a regular expression.
129
+ * The replacement should always be a string that may include references to the matched data from the rule.
130
+ */
131
+ 'singular': function(rule, replacement) {
132
+ removeFromUncountablesAndAddTo(singulars, rule, replacement);
133
+ },
134
+
135
+ /*
136
+ * Specifies a new irregular that applies to both pluralization and singularization at the same time. This can only be used
137
+ * for strings, not regular expressions. You simply pass the irregular in singular and plural form.
138
+ *
139
+ * Examples:
140
+ * String.Inflector.irregular('octopus', 'octopi')
141
+ * String.Inflector.irregular('person', 'people')
142
+ */
143
+ 'irregular': function(singular, plural) {
144
+ var singularFirst = singular.first(),
145
+ singularRest = singular.from(1),
146
+ pluralFirst = plural.first(),
147
+ pluralRest = plural.from(1),
148
+ pluralFirstUpper = pluralFirst.toUpperCase(),
149
+ pluralFirstLower = pluralFirst.toLowerCase(),
150
+ singularFirstUpper = singularFirst.toUpperCase(),
151
+ singularFirstLower = singularFirst.toLowerCase();
152
+ uncountables.remove(singular)
153
+ uncountables.remove(plural)
154
+ if(singularFirstUpper == pluralFirstUpper) {
155
+ Inflector.plural(new RegExp('({1}){2}$'.assign(singularFirst, singularRest), 'i'), '$1' + pluralRest);
156
+ Inflector.plural(new RegExp('({1}){2}$'.assign(pluralFirst, pluralRest), 'i'), '$1' + pluralRest);
157
+ Inflector.singular(new RegExp('({1}){2}$'.assign(pluralFirst, pluralRest), 'i'), '$1' + singularRest);
158
+ } else {
159
+ Inflector.plural(new RegExp('{1}{2}$'.assign(singularFirstUpper, singularRest)), pluralFirstUpper + pluralRest);
160
+ Inflector.plural(new RegExp('{1}{2}$'.assign(singularFirstLower, singularRest)), pluralFirstLower + pluralRest);
161
+ Inflector.plural(new RegExp('{1}{2}$'.assign(pluralFirstUpper, pluralRest)), pluralFirstUpper + pluralRest);
162
+ Inflector.plural(new RegExp('{1}{2}$'.assign(pluralFirstLower, pluralRest)), pluralFirstLower + pluralRest);
163
+ Inflector.singular(new RegExp('{1}{2}$'.assign(pluralFirstUpper, pluralRest)), singularFirstUpper + singularRest);
164
+ Inflector.singular(new RegExp('{1}{2}$'.assign(pluralFirstLower, pluralRest)), singularFirstLower + singularRest);
165
+ }
166
+ },
167
+
168
+ /*
169
+ * Add uncountable words that shouldn't be attempted inflected.
170
+ *
171
+ * Examples:
172
+ * String.Inflector.uncountable('money')
173
+ * String.Inflector.uncountable('money', 'information')
174
+ * String.Inflector.uncountable(['money', 'information', 'rice'])
175
+ */
176
+ 'uncountable': function() {
177
+ uncountables.add(Array.create(arguments).flatten());
178
+ },
179
+
180
+ /*
181
+ * Specifies a humanized form of a string by a regular expression rule or by a string mapping.
182
+ * When using a regular expression based replacement, the normal humanize formatting is called after the replacement.
183
+ * When a string is used, the human form should be specified as desired (example: 'The name', not 'the_name')
184
+ *
185
+ * Examples:
186
+ * String.Inflector.human(/_cnt$/i, '_count')
187
+ * String.Inflector.human('legacy_col_person_name', 'Name')
188
+ */
189
+ 'human': function(rule, replacement) {
190
+ humans.unshift({ rule: rule, replacement: replacement })
191
+ },
192
+
193
+
194
+ /*
195
+ * Clears the loaded inflections within a given scope (default is 'all').
196
+ * Options are: 'all', 'plurals', 'singulars', 'uncountables', 'humans'.
197
+ *
198
+ * Examples:
199
+ * String.Inflector.clear('all')
200
+ * String.Inflector.clear('plurals')
201
+ */
202
+ 'clear': function(type) {
203
+ if(paramMatchesType(type, 'singulars')) singulars = [];
204
+ if(paramMatchesType(type, 'plurals')) plurals = [];
205
+ if(paramMatchesType(type, 'uncountables')) uncountables = [];
206
+ if(paramMatchesType(type, 'humans')) humans = [];
207
+ if(paramMatchesType(type, 'acronyms')) acronyms = {};
208
+ }
209
+
210
+ };
211
+
212
+ Downcased = [
213
+ 'and', 'or', 'nor', 'a', 'an', 'the', 'so', 'but', 'to', 'of', 'at',
214
+ 'by', 'from', 'into', 'on', 'onto', 'off', 'out', 'in', 'over',
215
+ 'with', 'for'
216
+ ];
217
+
218
+ Normalize = {
219
+ 'A': /[AⒶAÀÁÂẦẤẪẨÃĀĂẰẮẴẲȦǠÄǞẢÅǺǍȀȂẠẬẶḀĄȺⱯ]/g,
220
+ 'B': /[BⒷBḂḄḆɃƂƁ]/g,
221
+ 'C': /[CⒸCĆĈĊČÇḈƇȻꜾ]/g,
222
+ 'D': /[DⒹDḊĎḌḐḒḎĐƋƊƉꝹ]/g,
223
+ 'E': /[EⒺEÈÉÊỀẾỄỂẼĒḔḖĔĖËẺĚȄȆẸỆȨḜĘḘḚƐƎ]/g,
224
+ 'F': /[FⒻFḞƑꝻ]/g,
225
+ 'G': /[GⒼGǴĜḠĞĠǦĢǤƓꞠꝽꝾ]/g,
226
+ 'H': /[HⒽHĤḢḦȞḤḨḪĦⱧⱵꞍ]/g,
227
+ 'I': /[IⒾIÌÍÎĨĪĬİÏḮỈǏȈȊỊĮḬƗ]/g,
228
+ 'J': /[JⒿJĴɈ]/g,
229
+ 'K': /[KⓀKḰǨḲĶḴƘⱩꝀꝂꝄꞢ]/g,
230
+ 'L': /[LⓁLĿĹĽḶḸĻḼḺŁȽⱢⱠꝈꝆꞀ]/g,
231
+ 'M': /[MⓂMḾṀṂⱮƜ]/g,
232
+ 'N': /[NⓃNǸŃÑṄŇṆŅṊṈȠƝꞐꞤ]/g,
233
+ 'O': /[OⓄOÒÓÔỒỐỖỔÕṌȬṎŌṐṒŎȮȰÖȪỎŐǑȌȎƠỜỚỠỞỢỌỘǪǬØǾƆƟꝊꝌ]/g,
234
+ 'P': /[PⓅPṔṖƤⱣꝐꝒꝔ]/g,
235
+ 'Q': /[QⓆQꝖꝘɊ]/g,
236
+ 'R': /[RⓇRŔṘŘȐȒṚṜŖṞɌⱤꝚꞦꞂ]/g,
237
+ 'S': /[SⓈSẞŚṤŜṠŠṦṢṨȘŞⱾꞨꞄ]/g,
238
+ 'T': /[TⓉTṪŤṬȚŢṰṮŦƬƮȾꞆ]/g,
239
+ 'U': /[UⓊUÙÚÛŨṸŪṺŬÜǛǗǕǙỦŮŰǓȔȖƯỪỨỮỬỰỤṲŲṶṴɄ]/g,
240
+ 'V': /[VⓋVṼṾƲꝞɅ]/g,
241
+ 'W': /[WⓌWẀẂŴẆẄẈⱲ]/g,
242
+ 'X': /[XⓍXẊẌ]/g,
243
+ 'Y': /[YⓎYỲÝŶỸȲẎŸỶỴƳɎỾ]/g,
244
+ 'Z': /[ZⓏZŹẐŻŽẒẔƵȤⱿⱫꝢ]/g,
245
+ 'a': /[aⓐaẚàáâầấẫẩãāăằắẵẳȧǡäǟảåǻǎȁȃạậặḁąⱥɐ]/g,
246
+ 'b': /[bⓑbḃḅḇƀƃɓ]/g,
247
+ 'c': /[cⓒcćĉċčçḉƈȼꜿↄ]/g,
248
+ 'd': /[dⓓdḋďḍḑḓḏđƌɖɗꝺ]/g,
249
+ 'e': /[eⓔeèéêềếễểẽēḕḗĕėëẻěȅȇẹệȩḝęḙḛɇɛǝ]/g,
250
+ 'f': /[fⓕfḟƒꝼ]/g,
251
+ 'g': /[gⓖgǵĝḡğġǧģǥɠꞡᵹꝿ]/g,
252
+ 'h': /[hⓗhĥḣḧȟḥḩḫẖħⱨⱶɥ]/g,
253
+ 'i': /[iⓘiìíîĩīĭïḯỉǐȉȋịįḭɨı]/g,
254
+ 'j': /[jⓙjĵǰɉ]/g,
255
+ 'k': /[kⓚkḱǩḳķḵƙⱪꝁꝃꝅꞣ]/g,
256
+ 'l': /[lⓛlŀĺľḷḹļḽḻſłƚɫⱡꝉꞁꝇ]/g,
257
+ 'm': /[mⓜmḿṁṃɱɯ]/g,
258
+ 'n': /[nⓝnǹńñṅňṇņṋṉƞɲʼnꞑꞥ]/g,
259
+ 'o': /[oⓞoòóôồốỗổõṍȭṏōṑṓŏȯȱöȫỏőǒȍȏơờớỡởợọộǫǭøǿɔꝋꝍɵ]/g,
260
+ 'p': /[pⓟpṕṗƥᵽꝑꝓꝕ]/g,
261
+ 'q': /[qⓠqɋꝗꝙ]/g,
262
+ 'r': /[rⓡrŕṙřȑȓṛṝŗṟɍɽꝛꞧꞃ]/g,
263
+ 's': /[sⓢsśṥŝṡšṧṣṩșşȿꞩꞅẛ]/g,
264
+ 't': /[tⓣtṫẗťṭțţṱṯŧƭʈⱦꞇ]/g,
265
+ 'u': /[uⓤuùúûũṹūṻŭüǜǘǖǚủůűǔȕȗưừứữửựụṳųṷṵʉ]/g,
266
+ 'v': /[vⓥvṽṿʋꝟʌ]/g,
267
+ 'w': /[wⓦwẁẃŵẇẅẘẉⱳ]/g,
268
+ 'x': /[xⓧxẋẍ]/g,
269
+ 'y': /[yⓨyỳýŷỹȳẏÿỷẙỵƴɏỿ]/g,
270
+ 'z': /[zⓩzźẑżžẓẕƶȥɀⱬꝣ]/g,
271
+ 'AA': /[Ꜳ]/g,
272
+ 'AE': /[ÆǼǢ]/g,
273
+ 'AO': /[Ꜵ]/g,
274
+ 'AU': /[Ꜷ]/g,
275
+ 'AV': /[ꜸꜺ]/g,
276
+ 'AY': /[Ꜽ]/g,
277
+ 'DZ': /[DZDŽ]/g,
278
+ 'Dz': /[DzDž]/g,
279
+ 'LJ': /[LJ]/g,
280
+ 'Lj': /[Lj]/g,
281
+ 'NJ': /[NJ]/g,
282
+ 'Nj': /[Nj]/g,
283
+ 'OI': /[Ƣ]/g,
284
+ 'OO': /[Ꝏ]/g,
285
+ 'OU': /[Ȣ]/g,
286
+ 'TZ': /[Ꜩ]/g,
287
+ 'VY': /[Ꝡ]/g,
288
+ 'aa': /[ꜳ]/g,
289
+ 'ae': /[æǽǣ]/g,
290
+ 'ao': /[ꜵ]/g,
291
+ 'au': /[ꜷ]/g,
292
+ 'av': /[ꜹꜻ]/g,
293
+ 'ay': /[ꜽ]/g,
294
+ 'dz': /[dzdž]/g,
295
+ 'hv': /[ƕ]/g,
296
+ 'lj': /[lj]/g,
297
+ 'nj': /[nj]/g,
298
+ 'oi': /[ƣ]/g,
299
+ 'ou': /[ȣ]/g,
300
+ 'oo': /[ꝏ]/g,
301
+ 'ss': /[ß]/g,
302
+ 'tz': /[ꜩ]/g,
303
+ 'vy': /[ꝡ]/
304
+ };
305
+
306
+
307
+ Inflector.plural(/$/, 's');
308
+ Inflector.plural(/s$/gi, 's');
309
+ Inflector.plural(/(ax|test)is$/gi, '$1es');
310
+ Inflector.plural(/(octop|vir|fung|foc|radi|alumn)(i|us)$/gi, '$1i');
311
+ Inflector.plural(/(census|alias|status)$/gi, '$1es');
312
+ Inflector.plural(/(bu)s$/gi, '$1ses');
313
+ Inflector.plural(/(buffal|tomat)o$/gi, '$1oes');
314
+ Inflector.plural(/([ti])um$/gi, '$1a');
315
+ Inflector.plural(/([ti])a$/gi, '$1a');
316
+ Inflector.plural(/sis$/gi, 'ses');
317
+ Inflector.plural(/f+e?$/gi, 'ves');
318
+ Inflector.plural(/(cuff|roof)$/gi, '$1s');
319
+ Inflector.plural(/([ht]ive)$/gi, '$1s');
320
+ Inflector.plural(/([^aeiouy]o)$/gi, '$1es');
321
+ Inflector.plural(/([^aeiouy]|qu)y$/gi, '$1ies');
322
+ Inflector.plural(/(x|ch|ss|sh)$/gi, '$1es');
323
+ Inflector.plural(/(matr|vert|ind)(?:ix|ex)$/gi, '$1ices');
324
+ Inflector.plural(/([ml])ouse$/gi, '$1ice');
325
+ Inflector.plural(/([ml])ice$/gi, '$1ice');
326
+ Inflector.plural(/^(ox)$/gi, '$1en');
327
+ Inflector.plural(/^(oxen)$/gi, '$1');
328
+ Inflector.plural(/(quiz)$/gi, '$1zes');
329
+ Inflector.plural(/(phot|cant|hom|zer|pian|portic|pr|quart|kimon)o$/gi, '$1os');
330
+ Inflector.plural(/(craft)$/gi, '$1');
331
+ Inflector.plural(/[eo]{2}(th?)$/gi, 'ee$1');
332
+
333
+ Inflector.singular(/s$/gi, '');
334
+ Inflector.singular(/([pst][aiu]s)$/gi, '$1');
335
+ Inflector.singular(/([aeiouy])ss$/gi, '$1ss');
336
+ Inflector.singular(/(n)ews$/gi, '$1ews');
337
+ Inflector.singular(/([ti])a$/gi, '$1um');
338
+ Inflector.singular(/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/gi, '$1$2sis');
339
+ Inflector.singular(/(^analy)ses$/gi, '$1sis');
340
+ Inflector.singular(/(i)(f|ves)$/i, '$1fe');
341
+ Inflector.singular(/([aeolr]f?)(f|ves)$/i, '$1f');
342
+ Inflector.singular(/([ht]ive)s$/gi, '$1');
343
+ Inflector.singular(/([^aeiouy]|qu)ies$/gi, '$1y');
344
+ Inflector.singular(/(s)eries$/gi, '$1eries');
345
+ Inflector.singular(/(m)ovies$/gi, '$1ovie');
346
+ Inflector.singular(/(x|ch|ss|sh)es$/gi, '$1');
347
+ Inflector.singular(/([ml])(ous|ic)e$/gi, '$1ouse');
348
+ Inflector.singular(/(bus)(es)?$/gi, '$1');
349
+ Inflector.singular(/(o)es$/gi, '$1');
350
+ Inflector.singular(/(shoe)s?$/gi, '$1');
351
+ Inflector.singular(/(cris|ax|test)[ie]s$/gi, '$1is');
352
+ Inflector.singular(/(octop|vir|fung|foc|radi|alumn)(i|us)$/gi, '$1us');
353
+ Inflector.singular(/(census|alias|status)(es)?$/gi, '$1');
354
+ Inflector.singular(/^(ox)(en)?/gi, '$1');
355
+ Inflector.singular(/(vert|ind)(ex|ices)$/gi, '$1ex');
356
+ Inflector.singular(/(matr)(ix|ices)$/gi, '$1ix');
357
+ Inflector.singular(/(quiz)(zes)?$/gi, '$1');
358
+ Inflector.singular(/(database)s?$/gi, '$1');
359
+ Inflector.singular(/ee(th?)$/gi, 'oo$1');
360
+
361
+ Inflector.irregular('person', 'people');
362
+ Inflector.irregular('man', 'men');
363
+ Inflector.irregular('child', 'children');
364
+ Inflector.irregular('sex', 'sexes');
365
+ Inflector.irregular('move', 'moves');
366
+ Inflector.irregular('save', 'saves');
367
+ Inflector.irregular('save', 'saves');
368
+ Inflector.irregular('cow', 'kine');
369
+ Inflector.irregular('goose', 'geese');
370
+ Inflector.irregular('zombie', 'zombies');
371
+
372
+ Inflector.uncountable('equipment,information,rice,money,species,series,fish,sheep,jeans'.split(','));
373
+
374
+
375
+ String.extend({
376
+
377
+ /***
378
+ * @method pluralize()
379
+ * @returns String
380
+ * @short Returns the plural form of the word in the string.
381
+ * @example
382
+ *
383
+ * 'post'.pluralize() -> 'posts'
384
+ * 'octopus'.pluralize() -> 'octopi'
385
+ * 'sheep'.pluralize() -> 'sheep'
386
+ * 'words'.pluralize() -> 'words'
387
+ * 'CamelOctopus'.pluralize() -> 'CamelOctopi'
388
+ *
389
+ ***/
390
+ 'pluralize': function() {
391
+ return inflect(this, true);
392
+ },
393
+
394
+ /***
395
+ * @method singularize()
396
+ * @returns String
397
+ * @short The reverse of String#pluralize. Returns the singular form of a word in a string.
398
+ * @example
399
+ *
400
+ * 'posts'.singularize() -> 'post'
401
+ * 'octopi'.singularize() -> 'octopus'
402
+ * 'sheep'.singularize() -> 'sheep'
403
+ * 'word'.singularize() -> 'word'
404
+ * 'CamelOctopi'.singularize() -> 'CamelOctopus'
405
+ *
406
+ ***/
407
+ 'singularize': function() {
408
+ return inflect(this, false);
409
+ },
410
+
411
+ /***
412
+ * @method humanize()
413
+ * @returns String
414
+ * @short Creates a human readable string.
415
+ * @extra Capitalizes the first word and turns underscores into spaces and strips a trailing '_id', if any. Like String#titleize, this is meant for creating pretty output.
416
+ * @example
417
+ *
418
+ * 'employee_salary'.humanize() -> 'Employee salary'
419
+ * 'author_id'.humanize() -> 'Author'
420
+ *
421
+ ***/
422
+ 'humanize': function() {
423
+ var str = runReplacements(this, humans);
424
+ str = str.replace(/_id$/g, '');
425
+ str = str.replace(/(_)?([a-z\d]*)/gi, function(match, _, word){
426
+ return (_ ? ' ' : '') + (acronyms[word] || word.toLowerCase());
427
+ });
428
+ return capitalize(str);
429
+ },
430
+
431
+ /***
432
+ * @method titleize()
433
+ * @returns String
434
+ * @short Creates a title version of the string.
435
+ * @extra Capitalizes all the words and replaces some characters in the string to create a nicer looking title. String#titleize is meant for creating pretty output.
436
+ * @example
437
+ *
438
+ * 'man from the boondocks'.titleize() -> 'Man from the Boondocks'
439
+ * 'x-men: the last stand'.titleize() -> 'X Men: The Last Stand'
440
+ * 'TheManWithoutAPast'.titleize() -> 'The Man Without a Past'
441
+ * 'raiders_of_the_lost_ark'.titleize() -> 'Raiders of the Lost Ark'
442
+ *
443
+ ***/
444
+ 'titleize': function() {
445
+ var fullStopPunctuation = /[.:;!]$/, hasPunctuation, lastHadPunctuation, isFirstOrLast;
446
+ return this.spacify().humanize().words(function(word, index, words) {
447
+ hasPunctuation = fullStopPunctuation.test(word);
448
+ isFirstOrLast = index == 0 || index == words.length - 1 || hasPunctuation || lastHadPunctuation;
449
+ lastHadPunctuation = hasPunctuation;
450
+ if(isFirstOrLast || !Downcased.any(word)) {
451
+ return capitalize(word);
452
+ } else {
453
+ return word;
454
+ }
455
+ }).join(' ');
456
+ },
457
+
458
+ /***
459
+ * @method namespace()
460
+ * @returns Mixed
461
+ * @short Tries to find the namespace or property with the name specified in the string.
462
+ * @extra Namespacing begins at the global level and operates on every "." in the string. If any level returns %undefined% the result will be %undefined%.
463
+ * @example
464
+ *
465
+ * 'Path.To.Namespace'.namespace() -> Path.To.Namespace
466
+ *
467
+ ***/
468
+ 'namespace': function() {
469
+ var spaces = this.split('.'), scope = globalContext;
470
+ spaces.each(function(s) {
471
+ return !!(scope = scope[s]);
472
+ });
473
+ return scope;
474
+ },
475
+
476
+ /***
477
+ * @method parameterize()
478
+ * @returns String
479
+ * @short Replaces special characters in a string so that it may be used as part of a pretty URL.
480
+ * @example
481
+ *
482
+ * 'hell, no!'.parameterize() -> 'hell-no'
483
+ *
484
+ ***/
485
+ 'parameterize': function(separator) {
486
+ if(separator === undefined) separator = '-';
487
+ var str = this.normalize();
488
+ str = str.replace(/[^a-z0-9\-_]+/gi, separator)
489
+ if(separator) {
490
+ str = str.replace(new RegExp('^{sep}+|{sep}+$|({sep}){sep}+'.assign({ 'sep': RegExp.escape(separator) }), 'g'), '$1');
491
+ }
492
+ return str.toLowerCase();
493
+ },
494
+
495
+ /***
496
+ * @method normalize()
497
+ * @returns String
498
+ * @short Returns the string with accented and non-standard Latin-based characters converted into ASCII approximate equivalents.
499
+ * @example
500
+ *
501
+ * 'á'.normalize() -> 'a'
502
+ * 'Ménage à trois'.normalize() -> 'Menage a trois'
503
+ * 'Volkswagen'.normalize() -> 'Volkswagen'
504
+ * 'FULLWIDTH'.normalize() -> 'FULLWIDTH'
505
+ *
506
+ ***/
507
+ 'normalize': function() {
508
+ var str = this.toString();
509
+ Object.each(Normalize, function(base, reg) {
510
+ str = str.replace(reg, base);
511
+ });
512
+ return str;
513
+ }
514
+
515
+ });
516
+
517
+ String.Inflector = Inflector;
518
+ String.Inflector.acronyms = acronyms;
519
+
520
+ })(this);