laces 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. data/CONTRIBUTING.md +38 -0
  2. data/Gemfile +3 -0
  3. data/Gemfile.lock +122 -0
  4. data/LICENSE +21 -0
  5. data/README.md +5 -0
  6. data/Rakefile +8 -0
  7. data/bin/laces +16 -0
  8. data/features/creating_a_heroku_app.feature +9 -0
  9. data/features/rake_clean.feature +21 -0
  10. data/features/skipping_clearance.feature +13 -0
  11. data/features/step_definitions/gem_steps.rb +5 -0
  12. data/features/step_definitions/heroku_steps.rb +3 -0
  13. data/features/step_definitions/shell_steps.rb +55 -0
  14. data/features/support/bin/heroku +5 -0
  15. data/features/support/env.rb +15 -0
  16. data/features/support/fake_heroku.rb +21 -0
  17. data/laces-0.0.1.gem +0 -0
  18. data/laces.gemspec +35 -0
  19. data/lib/laces/actions.rb +35 -0
  20. data/lib/laces/app_builder.rb +237 -0
  21. data/lib/laces/generators/app_generator.rb +111 -0
  22. data/lib/laces/version.rb +3 -0
  23. data/templates/.DS_Store +0 -0
  24. data/templates/Gemfile_template +76 -0
  25. data/templates/HEROKU_README.md +66 -0
  26. data/templates/Procfile +1 -0
  27. data/templates/README.md +81 -0
  28. data/templates/app/assets/imgs/glyphicons-halflings-white.png +0 -0
  29. data/templates/app/assets/imgs/glyphicons-halflings.png +0 -0
  30. data/templates/app/assets/javascripts/admin.coffee +20 -0
  31. data/templates/app/assets/javascripts/application.coffee +21 -0
  32. data/templates/app/assets/javascripts/lib/actinology.coffee +47 -0
  33. data/templates/app/assets/javascripts/lib/analytics.js +11 -0
  34. data/templates/app/assets/javascripts/lib/auth_token_sync.js +17 -0
  35. data/templates/app/assets/javascripts/lib/backbone-ui.js +2455 -0
  36. data/templates/app/assets/javascripts/lib/backbone.coffee +27 -0
  37. data/templates/app/assets/javascripts/lib/backbone/collection.js +249 -0
  38. data/templates/app/assets/javascripts/lib/backbone/events.js +64 -0
  39. data/templates/app/assets/javascripts/lib/backbone/helpers.js +68 -0
  40. data/templates/app/assets/javascripts/lib/backbone/history.js +144 -0
  41. data/templates/app/assets/javascripts/lib/backbone/model.js +291 -0
  42. data/templates/app/assets/javascripts/lib/backbone/router.coffee +45 -0
  43. data/templates/app/assets/javascripts/lib/backbone/sync.coffee +38 -0
  44. data/templates/app/assets/javascripts/lib/backbone/view.js +150 -0
  45. data/templates/app/assets/javascripts/lib/backbone_extended.coffee +276 -0
  46. data/templates/app/assets/javascripts/lib/bootstrap.js +1836 -0
  47. data/templates/app/assets/javascripts/lib/inflection.js +658 -0
  48. data/templates/app/assets/javascripts/lib/jquery-ui.js +343 -0
  49. data/templates/app/assets/javascripts/lib/jquery.hotkeys.js +102 -0
  50. data/templates/app/assets/javascripts/lib/jquery.js +4 -0
  51. data/templates/app/assets/javascripts/lib/milk.js.coffee +265 -0
  52. data/templates/app/assets/javascripts/lib/raw.js +143 -0
  53. data/templates/app/assets/javascripts/lib/strftime.js +732 -0
  54. data/templates/app/assets/javascripts/lib/throttle-debounce.js +251 -0
  55. data/templates/app/assets/javascripts/lib/timeago.js +148 -0
  56. data/templates/app/assets/javascripts/lib/underscore.js +28 -0
  57. data/templates/app/assets/styles/application.sass +21 -0
  58. data/templates/app/assets/styles/layouts/default.sass +15 -0
  59. data/templates/app/assets/styles/layouts/footer.sass +0 -0
  60. data/templates/app/assets/styles/layouts/forms.sass +34 -0
  61. data/templates/app/assets/styles/layouts/header.sass +0 -0
  62. data/templates/app/assets/styles/layouts/navigation.sass +0 -0
  63. data/templates/app/assets/styles/lib/backbone-ui.css +580 -0
  64. data/templates/app/assets/styles/lib/bootstrap.sass +4248 -0
  65. data/templates/app/assets/styles/pages/home.sass +0 -0
  66. data/templates/app/assets/styles/sessions/new.sass +0 -0
  67. data/templates/app/assets/styles/users/activate.sass +0 -0
  68. data/templates/app/assets/styles/users/new.sass +0 -0
  69. data/templates/app/assets/styles/users/suspended.sass +0 -0
  70. data/templates/app/controllers/app_controller.rb +14 -0
  71. data/templates/app/controllers/pages_controller.rb +2 -0
  72. data/templates/app/controllers/sessions_controller.rb +2 -0
  73. data/templates/app/controllers/templating_controller.rb +31 -0
  74. data/templates/app/controllers/users_controller.rb +2 -0
  75. data/templates/app/helpers/app_helper.rb +94 -0
  76. data/templates/app/helpers/users_helper.rb +53 -0
  77. data/templates/app/models/user.rb +9 -0
  78. data/templates/app/views/devise/confirmations/new.haml +9 -0
  79. data/templates/app/views/devise/passwords/edit.haml +11 -0
  80. data/templates/app/views/devise/passwords/new.haml +9 -0
  81. data/templates/app/views/devise/registrations/edit.haml +13 -0
  82. data/templates/app/views/devise/registrations/new.haml +8 -0
  83. data/templates/app/views/devise/sessions/_form.haml +7 -0
  84. data/templates/app/views/devise/sessions/new.haml +5 -0
  85. data/templates/app/views/devise/unlocks/new.haml +7 -0
  86. data/templates/app/views/layouts/_ascii.haml +0 -0
  87. data/templates/app/views/layouts/_column.haml +0 -0
  88. data/templates/app/views/layouts/_content.haml +1 -0
  89. data/templates/app/views/layouts/_extra.haml +0 -0
  90. data/templates/app/views/layouts/_footer.haml +9 -0
  91. data/templates/app/views/layouts/_head.haml +13 -0
  92. data/templates/app/views/layouts/_header.haml +6 -0
  93. data/templates/app/views/layouts/application.html.haml +16 -0
  94. data/templates/app/views/pages/home.haml +1 -0
  95. data/templates/config/app.yml +29 -0
  96. data/templates/config/application.erb +28 -0
  97. data/templates/config/database.yml +32 -0
  98. data/templates/config/initializers/devise.rb +232 -0
  99. data/templates/config/initializers/rabl_init.rb +4 -0
  100. data/templates/config/initializers/setup_mail.rb +13 -0
  101. data/templates/config/initializers/wrap_parameters.rb +12 -0
  102. data/templates/db/migrate/user_migration.rb +36 -0
  103. data/templates/laces_gitignore +9 -0
  104. data/templates/lib/development_mail_interceptor.rb +7 -0
  105. data/templates/lib/templating.rb +40 -0
  106. metadata +225 -0
@@ -0,0 +1,658 @@
1
+ /*
2
+ Copyright (c) 2010 Ryan Schuft (ryan.schuft@gmail.com)
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ of this software and associated documentation files (the "Software"), to deal
6
+ in the Software without restriction, including without limitation the rights
7
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the Software is
9
+ furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in
12
+ all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
+ THE SOFTWARE.
21
+ */
22
+
23
+ /*
24
+ This code is based in part on the work done in Ruby to support
25
+ infection as part of Ruby on Rails in the ActiveSupport's Inflector
26
+ and Inflections classes. It was initally ported to Javascript by
27
+ Ryan Schuft (ryan.schuft@gmail.com) in 2007.
28
+
29
+ The code is available at http://code.google.com/p/inflection-js/
30
+
31
+ The basic usage is:
32
+ 1. Include this script on your web page.
33
+ 2. Call functions on any String object in Javascript
34
+
35
+ Currently implemented functions:
36
+
37
+ String.pluralize(plural) == String
38
+ renders a singular English language noun into its plural form
39
+ normal results can be overridden by passing in an alternative
40
+
41
+ String.singularize(singular) == String
42
+ renders a plural English language noun into its singular form
43
+ normal results can be overridden by passing in an alterative
44
+
45
+ String.camelize(lowFirstLetter) == String
46
+ renders a lower case underscored word into camel case
47
+ the first letter of the result will be upper case unless you pass true
48
+ also translates "/" into "::" (underscore does the opposite)
49
+
50
+ String.underscore() == String
51
+ renders a camel cased word into words seperated by underscores
52
+ also translates "::" back into "/" (camelize does the opposite)
53
+
54
+ String.humanize(lowFirstLetter) == String
55
+ renders a lower case and underscored word into human readable form
56
+ defaults to making the first letter capitalized unless you pass true
57
+
58
+ String.capitalize() == String
59
+ renders all characters to lower case and then makes the first upper
60
+
61
+ String.dasherize() == String
62
+ renders all underbars and spaces as dashes
63
+
64
+ String.titleize() == String
65
+ renders words into title casing (as for book titles)
66
+
67
+ String.demodulize() == String
68
+ renders class names that are prepended by modules into just the class
69
+
70
+ String.tableize() == String
71
+ renders camel cased singular words into their underscored plural form
72
+
73
+ String.classify() == String
74
+ renders an underscored plural word into its camel cased singular form
75
+
76
+ String.foreign_key(dropIdUbar) == String
77
+ renders a class name (camel cased singular noun) into a foreign key
78
+ defaults to seperating the class from the id with an underbar unless
79
+ you pass true
80
+
81
+ String.ordinalize() == String
82
+ renders all numbers found in the string into their sequence like "22nd"
83
+ */
84
+
85
+ /*
86
+ This sets up a container for some constants in its own namespace
87
+ We use the window (if available) to enable dynamic loading of this script
88
+ Window won't necessarily exist for non-browsers.
89
+ */
90
+ if (window && !window.InflectionJS)
91
+ {
92
+ window.InflectionJS = null;
93
+ }
94
+
95
+ /*
96
+ This sets up some constants for later use
97
+ This should use the window namespace variable if available
98
+ */
99
+ InflectionJS =
100
+ {
101
+ /*
102
+ This is a list of nouns that use the same form for both singular and plural.
103
+ This list should remain entirely in lower case to correctly match Strings.
104
+ */
105
+ uncountable_words: [
106
+ 'equipment', 'information', 'rice', 'money', 'species', 'series',
107
+ 'fish', 'sheep', 'moose', 'deer', 'news'
108
+ ],
109
+
110
+ /*
111
+ These rules translate from the singular form of a noun to its plural form.
112
+ */
113
+ plural_rules: [
114
+ [new RegExp('(m)an$', 'gi'), '$1en'],
115
+ [new RegExp('(cam)pus$', 'gi'), '$1puses'],
116
+ [new RegExp('(pe)rson$', 'gi'), '$1ople'],
117
+ [new RegExp('(child)$', 'gi'), '$1ren'],
118
+ [new RegExp('^(ox)$', 'gi'), '$1en'],
119
+ [new RegExp('(ax|test)is$', 'gi'), '$1es'],
120
+ [new RegExp('(octop|vir)us$', 'gi'), '$1i'],
121
+ [new RegExp('(alias|status)$', 'gi'), '$1es'],
122
+ [new RegExp('(bu)s$', 'gi'), '$1ses'],
123
+ [new RegExp('(buffal|tomat|potat)o$', 'gi'), '$1oes'],
124
+ [new RegExp('([ti])um$', 'gi'), '$1a'],
125
+ [new RegExp('sis$', 'gi'), 'ses'],
126
+ [new RegExp('(?:([^f])fe|([lr])f)$', 'gi'), '$1$2ves'],
127
+ [new RegExp('(hive)$', 'gi'), '$1s'],
128
+ [new RegExp('([^aeiouy]|qu)y$', 'gi'), '$1ies'],
129
+ [new RegExp('(x|ch|ss|sh)$', 'gi'), '$1es'],
130
+ [new RegExp('(matr|vert|ind)ix|ex$', 'gi'), '$1ices'],
131
+ [new RegExp('([m|l])ouse$', 'gi'), '$1ice'],
132
+ [new RegExp('(quiz)$', 'gi'), '$1zes'],
133
+ [new RegExp('s$', 'gi'), 's'],
134
+ [new RegExp('$', 'gi'), 's']
135
+ ],
136
+
137
+ /*
138
+ These rules translate from the plural form of a noun to its singular form.
139
+ */
140
+ singular_rules: [
141
+ [new RegExp('(m)en$', 'gi'), '$1an'],
142
+ [new RegExp('(cam)puses$', 'gi'), '$1pus'],
143
+ [new RegExp('(pe)ople$', 'gi'), '$1rson'],
144
+ [new RegExp('(child)ren$', 'gi'), '$1'],
145
+ [new RegExp('([ti])a$', 'gi'), '$1um'],
146
+ [new RegExp('((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$','gi'), '$1$2sis'],
147
+ [new RegExp('(hive)s$', 'gi'), '$1'],
148
+ [new RegExp('(tive)s$', 'gi'), '$1'],
149
+ [new RegExp('(curve)s$', 'gi'), '$1'],
150
+ [new RegExp('([lr])ves$', 'gi'), '$1f'],
151
+ [new RegExp('([^fo])ves$', 'gi'), '$1fe'],
152
+ [new RegExp('([^aeiouy]|qu)ies$', 'gi'), '$1y'],
153
+ [new RegExp('(s)eries$', 'gi'), '$1eries'],
154
+ [new RegExp('(m)ovies$', 'gi'), '$1ovie'],
155
+ [new RegExp('(x|ch|ss|sh)es$', 'gi'), '$1'],
156
+ [new RegExp('([m|l])ice$', 'gi'), '$1ouse'],
157
+ [new RegExp('(bus)es$', 'gi'), '$1'],
158
+ [new RegExp('(o)es$', 'gi'), '$1'],
159
+ [new RegExp('(shoe)s$', 'gi'), '$1'],
160
+ [new RegExp('(cris|ax|test)es$', 'gi'), '$1is'],
161
+ [new RegExp('(octop|vir)i$', 'gi'), '$1us'],
162
+ [new RegExp('(alias|status)es$', 'gi'), '$1'],
163
+ [new RegExp('^(ox)en', 'gi'), '$1'],
164
+ [new RegExp('(vert|ind)ices$', 'gi'), '$1ex'],
165
+ [new RegExp('(matr)ices$', 'gi'), '$1ix'],
166
+ [new RegExp('(quiz)zes$', 'gi'), '$1'],
167
+ [new RegExp('s$', 'gi'), '']
168
+ ],
169
+
170
+ /*
171
+ This is a list of words that should not be capitalized for title case
172
+ */
173
+ non_titlecased_words: [
174
+ 'and', 'or', 'nor', 'a', 'an', 'the', 'so', 'but', 'to', 'of', 'at',
175
+ 'by', 'from', 'into', 'on', 'onto', 'off', 'out', 'in', 'over',
176
+ 'with', 'for'
177
+ ],
178
+
179
+ /*
180
+ These are regular expressions used for converting between String formats
181
+ */
182
+ id_suffix: new RegExp('(_ids|_id)$', 'g'),
183
+ underbar: new RegExp('_', 'g'),
184
+ space_or_underbar: new RegExp('[\ _]', 'g'),
185
+ uppercase: new RegExp('([A-Z])', 'g'),
186
+ underbar_prefix: new RegExp('^_'),
187
+
188
+ /*
189
+ This is a helper method that applies rules based replacement to a String
190
+ Signature:
191
+ InflectionJS.apply_rules(str, rules, skip, override) == String
192
+ Arguments:
193
+ str - String - String to modify and return based on the passed rules
194
+ rules - Array: [RegExp, String] - Regexp to match paired with String to use for replacement
195
+ skip - Array: [String] - Strings to skip if they match
196
+ override - String (optional) - String to return as though this method succeeded (used to conform to APIs)
197
+ Returns:
198
+ String - passed String modified by passed rules
199
+ Examples:
200
+ InflectionJS.apply_rules("cows", InflectionJs.singular_rules) === 'cow'
201
+ */
202
+ apply_rules: function(str, rules, skip, override)
203
+ {
204
+ if (override)
205
+ {
206
+ str = override;
207
+ }
208
+ else
209
+ {
210
+ var ignore = (skip.indexOf(str.toLowerCase()) > -1);
211
+ if (!ignore)
212
+ {
213
+ for (var x = 0; x < rules.length; x++)
214
+ {
215
+ if (str.match(rules[x][0]))
216
+ {
217
+ str = str.replace(rules[x][0], rules[x][1]);
218
+ break;
219
+ }
220
+ }
221
+ }
222
+ }
223
+ return str;
224
+ }
225
+ };
226
+
227
+ /*
228
+ This lets us detect if an Array contains a given element
229
+ Signature:
230
+ Array.indexOf(item, fromIndex, compareFunc) == Integer
231
+ Arguments:
232
+ item - Object - object to locate in the Array
233
+ fromIndex - Integer (optional) - starts checking from this position in the Array
234
+ compareFunc - Function (optional) - function used to compare Array item vs passed item
235
+ Returns:
236
+ Integer - index position in the Array of the passed item
237
+ Examples:
238
+ ['hi','there'].indexOf("guys") === -1
239
+ ['hi','there'].indexOf("hi") === 0
240
+ */
241
+ if (!Array.prototype.indexOf)
242
+ {
243
+ Array.prototype.indexOf = function(item, fromIndex, compareFunc)
244
+ {
245
+ if (!fromIndex)
246
+ {
247
+ fromIndex = -1;
248
+ }
249
+ var index = -1;
250
+ for (var i = fromIndex; i < this.length; i++)
251
+ {
252
+ if (this[i] === item || compareFunc && compareFunc(this[i], item))
253
+ {
254
+ index = i;
255
+ break;
256
+ }
257
+ }
258
+ return index;
259
+ };
260
+ }
261
+
262
+ /*
263
+ You can override this list for all Strings or just one depending on if you
264
+ set the new values on prototype or on a given String instance.
265
+ */
266
+ if (!String.prototype._uncountable_words)
267
+ {
268
+ String.prototype._uncountable_words = InflectionJS.uncountable_words;
269
+ }
270
+
271
+ /*
272
+ You can override this list for all Strings or just one depending on if you
273
+ set the new values on prototype or on a given String instance.
274
+ */
275
+ if (!String.prototype._plural_rules)
276
+ {
277
+ String.prototype._plural_rules = InflectionJS.plural_rules;
278
+ }
279
+
280
+ /*
281
+ You can override this list for all Strings or just one depending on if you
282
+ set the new values on prototype or on a given String instance.
283
+ */
284
+ if (!String.prototype._singular_rules)
285
+ {
286
+ String.prototype._singular_rules = InflectionJS.singular_rules;
287
+ }
288
+
289
+ /*
290
+ You can override this list for all Strings or just one depending on if you
291
+ set the new values on prototype or on a given String instance.
292
+ */
293
+ if (!String.prototype._non_titlecased_words)
294
+ {
295
+ String.prototype._non_titlecased_words = InflectionJS.non_titlecased_words;
296
+ }
297
+
298
+ /*
299
+ This function adds plurilization support to every String object
300
+ Signature:
301
+ String.pluralize(plural) == String
302
+ Arguments:
303
+ plural - String (optional) - overrides normal output with said String
304
+ Returns:
305
+ String - singular English language nouns are returned in plural form
306
+ Examples:
307
+ "person".pluralize() == "people"
308
+ "octopus".pluralize() == "octopi"
309
+ "Hat".pluralize() == "Hats"
310
+ "person".pluralize("guys") == "guys"
311
+ */
312
+ if (!String.prototype.pluralize)
313
+ {
314
+ String.prototype.pluralize = function(plural)
315
+ {
316
+ return InflectionJS.apply_rules(
317
+ this,
318
+ this._plural_rules,
319
+ this._uncountable_words,
320
+ plural
321
+ );
322
+ };
323
+ }
324
+
325
+ /*
326
+ This function adds singularization support to every String object
327
+ Signature:
328
+ String.singularize(singular) == String
329
+ Arguments:
330
+ singular - String (optional) - overrides normal output with said String
331
+ Returns:
332
+ String - plural English language nouns are returned in singular form
333
+ Examples:
334
+ "people".singularize() == "person"
335
+ "octopi".singularize() == "octopus"
336
+ "Hats".singularize() == "Hat"
337
+ "guys".singularize("person") == "person"
338
+ */
339
+ if (!String.prototype.singularize)
340
+ {
341
+ String.prototype.singularize = function(singular)
342
+ {
343
+ return InflectionJS.apply_rules(
344
+ this,
345
+ this._singular_rules,
346
+ this._uncountable_words,
347
+ singular
348
+ );
349
+ };
350
+ }
351
+
352
+ /*
353
+ This function adds camelization support to every String object
354
+ Signature:
355
+ String.camelize(lowFirstLetter) == String
356
+ Arguments:
357
+ lowFirstLetter - boolean (optional) - default is to capitalize the first
358
+ letter of the results... passing true will lowercase it
359
+ Returns:
360
+ String - lower case underscored words will be returned in camel case
361
+ additionally '/' is translated to '::'
362
+ Examples:
363
+ "message_properties".camelize() == "MessageProperties"
364
+ "message_properties".camelize(true) == "messageProperties"
365
+ */
366
+ if (!String.prototype.camelize)
367
+ {
368
+ String.prototype.camelize = function(lowFirstLetter)
369
+ {
370
+ var str = this.toLowerCase();
371
+ var str_path = str.split('/');
372
+ for (var i = 0; i < str_path.length; i++)
373
+ {
374
+ var str_arr = str_path[i].split('_');
375
+ var initX = ((lowFirstLetter && i + 1 === str_path.length) ? (1) : (0));
376
+ for (var x = initX; x < str_arr.length; x++)
377
+ {
378
+ str_arr[x] = str_arr[x].charAt(0).toUpperCase() + str_arr[x].substring(1);
379
+ }
380
+ str_path[i] = str_arr.join('');
381
+ }
382
+ str = str_path.join('::');
383
+ return str;
384
+ };
385
+ }
386
+
387
+ /*
388
+ This function adds underscore support to every String object
389
+ Signature:
390
+ String.underscore() == String
391
+ Arguments:
392
+ N/A
393
+ Returns:
394
+ String - camel cased words are returned as lower cased and underscored
395
+ additionally '::' is translated to '/'
396
+ Examples:
397
+ "MessageProperties".camelize() == "message_properties"
398
+ "messageProperties".underscore() == "message_properties"
399
+ */
400
+ if (!String.prototype.underscore)
401
+ {
402
+ String.prototype.underscore = function()
403
+ {
404
+ var str = this;
405
+ var str_path = str.split('::');
406
+ for (var i = 0; i < str_path.length; i++)
407
+ {
408
+ str_path[i] = str_path[i].replace(InflectionJS.uppercase, '_$1');
409
+ str_path[i] = str_path[i].replace(InflectionJS.underbar_prefix, '');
410
+ }
411
+ str = str_path.join('/').toLowerCase();
412
+ return str;
413
+ };
414
+ }
415
+
416
+ /*
417
+ This function adds humanize support to every String object
418
+ Signature:
419
+ String.humanize(lowFirstLetter) == String
420
+ Arguments:
421
+ lowFirstLetter - boolean (optional) - default is to capitalize the first
422
+ letter of the results... passing true will lowercase it
423
+ Returns:
424
+ String - lower case underscored words will be returned in humanized form
425
+ Examples:
426
+ "message_properties".humanize() == "Message properties"
427
+ "message_properties".humanize(true) == "message properties"
428
+ */
429
+ if (!String.prototype.humanize)
430
+ {
431
+ String.prototype.humanize = function(lowFirstLetter)
432
+ {
433
+ var str = this.toLowerCase();
434
+ str = str.replace(InflectionJS.id_suffix, '');
435
+ str = str.replace(InflectionJS.underbar, ' ');
436
+ if (!lowFirstLetter)
437
+ {
438
+ str = str.capitalize();
439
+ }
440
+ return str;
441
+ };
442
+ }
443
+
444
+ /*
445
+ This function adds capitalization support to every String object
446
+ Signature:
447
+ String.capitalize() == String
448
+ Arguments:
449
+ N/A
450
+ Returns:
451
+ String - all characters will be lower case and the first will be upper
452
+ Examples:
453
+ "message_properties".capitalize() == "Message_properties"
454
+ "message properties".capitalize() == "Message properties"
455
+ */
456
+ if (!String.prototype.capitalize)
457
+ {
458
+ String.prototype.capitalize = function()
459
+ {
460
+ var str = this.toLowerCase();
461
+ str = str.substring(0, 1).toUpperCase() + str.substring(1);
462
+ return str;
463
+ };
464
+ }
465
+
466
+ /*
467
+ This function adds dasherization support to every String object
468
+ Signature:
469
+ String.dasherize() == String
470
+ Arguments:
471
+ N/A
472
+ Returns:
473
+ String - replaces all spaces or underbars with dashes
474
+ Examples:
475
+ "message_properties".capitalize() == "message-properties"
476
+ "Message Properties".capitalize() == "Message-Properties"
477
+ */
478
+ if (!String.prototype.dasherize)
479
+ {
480
+ String.prototype.dasherize = function()
481
+ {
482
+ var str = this;
483
+ str = str.replace(InflectionJS.space_or_underbar, '-');
484
+ return str;
485
+ };
486
+ }
487
+
488
+ /*
489
+ This function adds titleize support to every String object
490
+ Signature:
491
+ String.titleize() == String
492
+ Arguments:
493
+ N/A
494
+ Returns:
495
+ String - capitalizes words as you would for a book title
496
+ Examples:
497
+ "message_properties".titleize() == "Message Properties"
498
+ "message properties to keep".titleize() == "Message Properties to Keep"
499
+ */
500
+ if (!String.prototype.titleize)
501
+ {
502
+ String.prototype.titleize = function()
503
+ {
504
+ var str = this.toLowerCase();
505
+ str = str.replace(InflectionJS.underbar, ' ');
506
+ var str_arr = str.split(' ');
507
+ for (var x = 0; x < str_arr.length; x++)
508
+ {
509
+ var d = str_arr[x].split('-');
510
+ for (var i = 0; i < d.length; i++)
511
+ {
512
+ if (this._non_titlecased_words.indexOf(d[i].toLowerCase()) < 0)
513
+ {
514
+ d[i] = d[i].capitalize();
515
+ }
516
+ }
517
+ str_arr[x] = d.join('-');
518
+ }
519
+ str = str_arr.join(' ');
520
+ str = str.substring(0, 1).toUpperCase() + str.substring(1);
521
+ return str;
522
+ };
523
+ }
524
+
525
+ /*
526
+ This function adds demodulize support to every String object
527
+ Signature:
528
+ String.demodulize() == String
529
+ Arguments:
530
+ N/A
531
+ Returns:
532
+ String - removes module names leaving only class names (Ruby style)
533
+ Examples:
534
+ "Message::Bus::Properties".demodulize() == "Properties"
535
+ */
536
+ if (!String.prototype.demodulize)
537
+ {
538
+ String.prototype.demodulize = function()
539
+ {
540
+ var str = this;
541
+ var str_arr = str.split('::');
542
+ str = str_arr[str_arr.length - 1];
543
+ return str;
544
+ };
545
+ }
546
+
547
+ /*
548
+ This function adds tableize support to every String object
549
+ Signature:
550
+ String.tableize() == String
551
+ Arguments:
552
+ N/A
553
+ Returns:
554
+ String - renders camel cased words into their underscored plural form
555
+ Examples:
556
+ "MessageBusProperty".tableize() == "message_bus_properties"
557
+ */
558
+ if (!String.prototype.tableize)
559
+ {
560
+ String.prototype.tableize = function()
561
+ {
562
+ var str = this;
563
+ str = str.underscore().pluralize();
564
+ return str;
565
+ };
566
+ }
567
+
568
+ /*
569
+ This function adds classification support to every String object
570
+ Signature:
571
+ String.classify() == String
572
+ Arguments:
573
+ N/A
574
+ Returns:
575
+ String - underscored plural nouns become the camel cased singular form
576
+ Examples:
577
+ "message_bus_properties".classify() == "MessageBusProperty"
578
+ */
579
+ if (!String.prototype.classify)
580
+ {
581
+ String.prototype.classify = function()
582
+ {
583
+ var str = this;
584
+ str = str.camelize().singularize();
585
+ return str;
586
+ };
587
+ }
588
+
589
+ /*
590
+ This function adds foreign key support to every String object
591
+ Signature:
592
+ String.foreign_key(dropIdUbar) == String
593
+ Arguments:
594
+ dropIdUbar - boolean (optional) - default is to seperate id with an
595
+ underbar at the end of the class name, you can pass true to skip it
596
+ Returns:
597
+ String - camel cased singular class names become underscored with id
598
+ Examples:
599
+ "MessageBusProperty".foreign_key() == "message_bus_property_id"
600
+ "MessageBusProperty".foreign_key(true) == "message_bus_propertyid"
601
+ */
602
+ if (!String.prototype.foreign_key)
603
+ {
604
+ String.prototype.foreign_key = function(dropIdUbar)
605
+ {
606
+ var str = this;
607
+ str = str.demodulize().underscore() + ((dropIdUbar) ? ('') : ('_')) + 'id';
608
+ return str;
609
+ };
610
+ }
611
+
612
+ /*
613
+ This function adds ordinalize support to every String object
614
+ Signature:
615
+ String.ordinalize() == String
616
+ Arguments:
617
+ N/A
618
+ Returns:
619
+ String - renders all found numbers their sequence like "22nd"
620
+ Examples:
621
+ "the 1 pitch".ordinalize() == "the 1st pitch"
622
+ */
623
+ if (!String.prototype.ordinalize)
624
+ {
625
+ String.prototype.ordinalize = function()
626
+ {
627
+ var str = this;
628
+ var str_arr = str.split(' ');
629
+ for (var x = 0; x < str_arr.length; x++)
630
+ {
631
+ var i = parseInt(str_arr[x]);
632
+ if (i === NaN)
633
+ {
634
+ var ltd = str_arr[x].substring(str_arr[x].length - 2);
635
+ var ld = str_arr[x].substring(str_arr[x].length - 1);
636
+ var suf = "th";
637
+ if (ltd != "11" && ltd != "12" && ltd != "13")
638
+ {
639
+ if (ld === "1")
640
+ {
641
+ suf = "st";
642
+ }
643
+ else if (ld === "2")
644
+ {
645
+ suf = "nd";
646
+ }
647
+ else if (ld === "3")
648
+ {
649
+ suf = "rd";
650
+ }
651
+ }
652
+ str_arr[x] += suf;
653
+ }
654
+ }
655
+ str = str_arr.join(' ');
656
+ return str;
657
+ };
658
+ }