rubyception 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README.md +30 -0
- data/Rakefile +42 -0
- data/app/assets/javascripts/rubyception/app.coffee +4 -0
- data/app/assets/javascripts/rubyception/application.coffee +17 -0
- data/app/assets/javascripts/rubyception/application.js +15 -0
- data/app/assets/javascripts/rubyception/collections/backtrace_lines.coffee +4 -0
- data/app/assets/javascripts/rubyception/collections/entries.coffee +3 -0
- data/app/assets/javascripts/rubyception/collections/lines.coffee +3 -0
- data/app/assets/javascripts/rubyception/init.coffee +10 -0
- data/app/assets/javascripts/rubyception/lib/backbone.js +1431 -0
- data/app/assets/javascripts/rubyception/lib/inflections.js +659 -0
- data/app/assets/javascripts/rubyception/lib/jenny.coffee +262 -0
- data/app/assets/javascripts/rubyception/lib/milk.coffee +261 -0
- data/app/assets/javascripts/rubyception/lib/mousetrap.js +7 -0
- data/app/assets/javascripts/rubyception/lib/underscore-min.js +32 -0
- data/app/assets/javascripts/rubyception/models/backtrace_line.coffee +2 -0
- data/app/assets/javascripts/rubyception/models/entry.coffee +2 -0
- data/app/assets/javascripts/rubyception/models/line.coffee +2 -0
- data/app/assets/javascripts/rubyception/routers/log.coffee +45 -0
- data/app/assets/javascripts/rubyception/shBrushSql.js +66 -0
- data/app/assets/javascripts/rubyception/shCore.js +17 -0
- data/app/assets/javascripts/rubyception/template.js +1 -0
- data/app/assets/javascripts/rubyception/views/backtrace_lines/backtrace_line.coffee +8 -0
- data/app/assets/javascripts/rubyception/views/backtrace_lines/index.coffee +16 -0
- data/app/assets/javascripts/rubyception/views/entries/entry.coffee +49 -0
- data/app/assets/javascripts/rubyception/views/entries/index.coffee +79 -0
- data/app/assets/javascripts/rubyception/views/lines/index.coffee +5 -0
- data/app/assets/javascripts/rubyception/views/lines/line.coffee +10 -0
- data/app/assets/javascripts/rubyception/views/logs/show.coffee +8 -0
- data/app/assets/stylesheets/rubyception/application.css +13 -0
- data/app/assets/stylesheets/rubyception/application.sass +12 -0
- data/app/assets/stylesheets/rubyception/backtrace_lines.sass +66 -0
- data/app/assets/stylesheets/rubyception/default.sass +35 -0
- data/app/assets/stylesheets/rubyception/entries.sass +57 -0
- data/app/assets/stylesheets/rubyception/lines.sass +41 -0
- data/app/assets/stylesheets/rubyception/shCore.css +226 -0
- data/app/assets/stylesheets/rubyception/shThemeDefault.css +117 -0
- data/app/controllers/rubyception/application_controller.rb +4 -0
- data/app/controllers/rubyception/templating_controller.rb +22 -0
- data/app/helpers/rubyception/application_helper.rb +9 -0
- data/app/models/rubyception/entry.rb +108 -0
- data/app/models/rubyception/line.rb +55 -0
- data/app/views/layouts/rubyception/application.haml +15 -0
- data/app/views/rubyception/application/index.haml +0 -0
- data/app/views/rubyception/backtrace_lines/_backtrace_line.haml +5 -0
- data/app/views/rubyception/backtrace_lines/_index.haml +7 -0
- data/app/views/rubyception/entries/_entry.haml +12 -0
- data/app/views/rubyception/entries/_index.haml +1 -0
- data/app/views/rubyception/lines/_index.haml +3 -0
- data/app/views/rubyception/lines/_line.haml +2 -0
- data/app/views/rubyception/lines/action_controller/_exist_fragment.haml +0 -0
- data/app/views/rubyception/lines/action_controller/_expire_fragment.haml +0 -0
- data/app/views/rubyception/lines/action_controller/_expire_page.haml +0 -0
- data/app/views/rubyception/lines/action_controller/_halted_callback.haml +0 -0
- data/app/views/rubyception/lines/action_controller/_process_action.haml +0 -0
- data/app/views/rubyception/lines/action_controller/_read_fragment.haml +0 -0
- data/app/views/rubyception/lines/action_controller/_redirect_to.haml +0 -0
- data/app/views/rubyception/lines/action_controller/_send_data.haml +0 -0
- data/app/views/rubyception/lines/action_controller/_send_file.haml +0 -0
- data/app/views/rubyception/lines/action_controller/_start_processing.haml +0 -0
- data/app/views/rubyception/lines/action_controller/_write_fragment.haml +0 -0
- data/app/views/rubyception/lines/action_controller/_write_page.haml +0 -0
- data/app/views/rubyception/lines/action_mailer/_deliver.haml +0 -0
- data/app/views/rubyception/lines/action_mailer/_receive.haml +0 -0
- data/app/views/rubyception/lines/action_view/_render_partial.haml +3 -0
- data/app/views/rubyception/lines/action_view/_render_template.haml +6 -0
- data/app/views/rubyception/lines/active_record/_identity.haml +3 -0
- data/app/views/rubyception/lines/active_record/_sql.haml +4 -0
- data/app/views/rubyception/lines/active_resource/_request.haml +0 -0
- data/app/views/rubyception/lines/active_support/_cache_delete.haml +0 -0
- data/app/views/rubyception/lines/active_support/_cache_exist.haml +0 -0
- data/app/views/rubyception/lines/active_support/_cache_fetch_hit.haml +0 -0
- data/app/views/rubyception/lines/active_support/_cache_generate.haml +0 -0
- data/app/views/rubyception/lines/active_support/_cache_read.haml +0 -0
- data/app/views/rubyception/lines/active_support/_cache_write.haml +0 -0
- data/config/initializers/sass.rb +4 -0
- data/config/initializers/websocket_server.rb +23 -0
- data/config/routes.rb +3 -0
- data/config/templating.yml +39 -0
- data/db/development.sqlite3 +0 -0
- data/lib/rubyception.rb +6 -0
- data/lib/rubyception/catcher.rb +12 -0
- data/lib/rubyception/engine.rb +5 -0
- data/lib/rubyception/subscriber.rb +30 -0
- data/lib/rubyception/templating.rb +48 -0
- data/lib/rubyception/version.rb +3 -0
- data/lib/rubyception/websocket_server.rb +30 -0
- data/lib/tasks/rubyception_tasks.rake +4 -0
- data/lib/tasks/templates.rake +7 -0
- data/test/dummy/README.rdoc +261 -0
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/assets/javascripts/application.js +15 -0
- data/test/dummy/app/assets/stylesheets/application.css +13 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/controllers/tasks_controller.rb +4 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/app/views/tasks/index.html.erb +1 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +59 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +37 -0
- data/test/dummy/config/environments/production.rb +67 -0
- data/test/dummy/config/environments/test.rb +37 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/inflections.rb +15 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +5 -0
- data/test/dummy/config/routes.rb +5 -0
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/log/development.log +183 -0
- data/test/dummy/public/404.html +26 -0
- data/test/dummy/public/422.html +26 -0
- data/test/dummy/public/500.html +25 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +6 -0
- data/test/dummy/tmp/cache/assets/C2A/A50/sprockets%2F502789294f7d708459013948aa30c91c +0 -0
- data/test/dummy/tmp/cache/assets/C76/720/sprockets%2F610e52016b025a1ce3828a39a7e93981 +0 -0
- data/test/dummy/tmp/cache/assets/C7E/740/sprockets%2F8703235e74ff13492a454a492b24b7c5 +0 -0
- data/test/dummy/tmp/cache/assets/C86/920/sprockets%2Fc4933e5c2861e44ab07485567259fa32 +0 -0
- data/test/dummy/tmp/cache/assets/C9C/F10/sprockets%2F33864d14794ad865eed8829535780ad9 +0 -0
- data/test/dummy/tmp/cache/assets/CA1/8B0/sprockets%2F2fb362180bfba307350968110ec6f454 +0 -0
- data/test/dummy/tmp/cache/assets/CAD/770/sprockets%2Fc5914c960063cf7cdcd50130a7637485 +0 -0
- data/test/dummy/tmp/cache/assets/CAD/DB0/sprockets%2Fe276db0373d02afa09f069436349328d +0 -0
- data/test/dummy/tmp/cache/assets/CAE/140/sprockets%2F6350953af3f774482a51481f8cd0a3c3 +0 -0
- data/test/dummy/tmp/cache/assets/CB0/010/sprockets%2F1c103104469484b76897daa3d04c6ee9 +0 -0
- data/test/dummy/tmp/cache/assets/CB2/E10/sprockets%2F7b063ac8c2e913114d098d89e60228e5 +0 -0
- data/test/dummy/tmp/cache/assets/CB5/EA0/sprockets%2Fe98d20291409af69a7316a86c45da651 +0 -0
- data/test/dummy/tmp/cache/assets/CB9/B80/sprockets%2F07c32ba22a6489f062e48df8830667d8 +0 -0
- data/test/dummy/tmp/cache/assets/CBE/630/sprockets%2F476aa283807fdd8203e98d3137686eb5 +0 -0
- data/test/dummy/tmp/cache/assets/CBE/A10/sprockets%2F7f66283cb01647a7c4cf954b62919c29 +0 -0
- data/test/dummy/tmp/cache/assets/CC8/DC0/sprockets%2F302790cf97013f80dc311cf2ad0a6342 +0 -0
- data/test/dummy/tmp/cache/assets/CD1/8E0/sprockets%2Fe898f78743c913b3855e1786cc58ec61 +0 -0
- data/test/dummy/tmp/cache/assets/CD2/510/sprockets%2F32995b414c804ddbb00f5504841f5e1b +0 -0
- data/test/dummy/tmp/cache/assets/CD6/EE0/sprockets%2F8666c05da70453c6e7cda433411192af +0 -0
- data/test/dummy/tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953 +0 -0
- data/test/dummy/tmp/cache/assets/CE4/F70/sprockets%2F538e295f0a0d9311c8259bf029ec680f +0 -0
- data/test/dummy/tmp/cache/assets/CE5/3E0/sprockets%2F7b916f5404e1ee4a943e921d6523a97b +0 -0
- data/test/dummy/tmp/cache/assets/CE9/D20/sprockets%2F9dd235d6e21764622b79bf65cf15349a +0 -0
- data/test/dummy/tmp/cache/assets/CF2/2F0/sprockets%2F314b4a0885d2efea526a19f539987e96 +0 -0
- data/test/dummy/tmp/cache/assets/CFB/750/sprockets%2F42c8014c71d022dd4c60ed1e963b076a +0 -0
- data/test/dummy/tmp/cache/assets/D03/BA0/sprockets%2F7c98f37658deed89f88b13d429262a75 +0 -0
- data/test/dummy/tmp/cache/assets/D07/3B0/sprockets%2F2ca3210b7cff57c3299aea8507803f32 +0 -0
- data/test/dummy/tmp/cache/assets/D08/7E0/sprockets%2F47ed6467d629e22254ca2b0d13c863bb +0 -0
- data/test/dummy/tmp/cache/assets/D0F/970/sprockets%2F0461a7c825c4bb945e2f5daf00974f64 +0 -0
- data/test/dummy/tmp/cache/assets/D10/E40/sprockets%2Fa39042b3a568331554c57725fedfcf3e +0 -0
- data/test/dummy/tmp/cache/assets/D13/740/sprockets%2F98a98bb8bc60c8b170c451195e44e42d +0 -0
- data/test/dummy/tmp/cache/assets/D14/BE0/sprockets%2Faa69f1166262379365d818afcf4fa3b3 +0 -0
- data/test/dummy/tmp/cache/assets/D15/C40/sprockets%2F8fe3d124a7582df0a47c44743f3e3d85 +0 -0
- data/test/dummy/tmp/cache/assets/D1B/210/sprockets%2F567244d0d8f2733c6d1826ee82c76dce +0 -0
- data/test/dummy/tmp/cache/assets/D2C/BD0/sprockets%2F17c8f4a03e52cd0d6b85605b0abd7413 +0 -0
- data/test/dummy/tmp/cache/assets/D2D/BE0/sprockets%2Fcdcde17900d6ad0c72c14390808a35b3 +0 -0
- data/test/dummy/tmp/cache/assets/D30/800/sprockets%2F6ad46c52755a4a6c0b81250fc72ae17c +0 -0
- data/test/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/test/dummy/tmp/cache/assets/D34/E20/sprockets%2Fc81175b2bb38464d022abb2d9b18bf87 +0 -0
- data/test/dummy/tmp/cache/assets/D38/420/sprockets%2Fc893136e3c5e0cb051358b8c01fc6b9c +0 -0
- data/test/dummy/tmp/cache/assets/D3C/C50/sprockets%2F52be58b70628a1836b3cea8bd096ee22 +0 -0
- data/test/dummy/tmp/cache/assets/D3E/980/sprockets%2F5e82819b1fe416d230b10d76abd948df +0 -0
- data/test/dummy/tmp/cache/assets/D3F/A80/sprockets%2F5e2ee04b0c2b6417f9ab728692a738cd +0 -0
- data/test/dummy/tmp/cache/assets/D41/340/sprockets%2Ffdc1e8bf346373a650e6d082f522a59e +0 -0
- data/test/dummy/tmp/cache/assets/D41/920/sprockets%2F64c94c28c60bbb70d9a3b9e972ae3057 +0 -0
- data/test/dummy/tmp/cache/assets/D47/BB0/sprockets%2F40929a27da40e05aa0b4aa0173f1ebb1 +0 -0
- data/test/dummy/tmp/cache/assets/D49/740/sprockets%2Fbcb0e6511f88b9af6d70380c86a57b79 +0 -0
- data/test/dummy/tmp/cache/assets/D4E/1B0/sprockets%2Ff7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/test/dummy/tmp/cache/assets/D50/940/sprockets%2Ff601e768c1f96abd3d019e7f7564e3c9 +0 -0
- data/test/dummy/tmp/cache/assets/D53/460/sprockets%2F64e051e79ebdaa56bd989d67831f941d +0 -0
- data/test/dummy/tmp/cache/assets/D58/150/sprockets%2F70d598d088bce2f8078c80866be9cff0 +0 -0
- data/test/dummy/tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/test/dummy/tmp/cache/assets/D66/E40/sprockets%2F0cd4ea4f30e313f641b96be80a13cf98 +0 -0
- data/test/dummy/tmp/cache/assets/D69/5A0/sprockets%2F8a630d58f110eeeffad123986912bae1 +0 -0
- data/test/dummy/tmp/cache/assets/D69/E10/sprockets%2F3d4d98cb1ad46a0b7635b75993c2ac0d +0 -0
- data/test/dummy/tmp/cache/assets/D6A/920/sprockets%2F9f1c0c3ad8aae418e1004d5cf54f5479 +0 -0
- data/test/dummy/tmp/cache/assets/D6B/A70/sprockets%2Fff1bd1557a03e82f5c2c45d58b661a4f +0 -0
- data/test/dummy/tmp/cache/assets/D6F/6B0/sprockets%2F1e2a322de4879106937ede70ffa2da6e +0 -0
- data/test/dummy/tmp/cache/assets/D70/780/sprockets%2F6c6a33bccf82b144dbd7982f0854f8b0 +0 -0
- data/test/dummy/tmp/cache/assets/D73/C90/sprockets%2F9752db727fd681d97becb91a17ad302d +0 -0
- data/test/dummy/tmp/cache/assets/D74/A50/sprockets%2Fe50162da67fdab880a08590f618dfc8e +0 -0
- data/test/dummy/tmp/cache/assets/D75/270/sprockets%2Fef0b31d47f8f9acc69f0234019b737ee +0 -0
- data/test/dummy/tmp/cache/assets/D77/320/sprockets%2F0c96ad8de5e6a049f5df53415baa4697 +0 -0
- data/test/dummy/tmp/cache/assets/D7A/CF0/sprockets%2Fb7e1aa09c7c42e2b98895e16dbc839b6 +0 -0
- data/test/dummy/tmp/cache/assets/D7B/110/sprockets%2F55184d1c2bc87fc49369d69e10be7adf +0 -0
- data/test/dummy/tmp/cache/assets/D81/A40/sprockets%2Ff886784e31a152dc32fdf5cf782d6bd9 +0 -0
- data/test/dummy/tmp/cache/assets/D91/AE0/sprockets%2Fab00df33bbe0ef2939b4d43e042e4d77 +0 -0
- data/test/dummy/tmp/cache/assets/D9E/1A0/sprockets%2F69bf83cb71b257071ba6db37bdea78f1 +0 -0
- data/test/dummy/tmp/cache/assets/D9E/840/sprockets%2Fc8da1010ea3b0a24bd101a2dd319dc4c +0 -0
- data/test/dummy/tmp/cache/assets/DA0/880/sprockets%2F89c46cad03e38a94663bfaac1b8d95d0 +0 -0
- data/test/dummy/tmp/cache/assets/DA1/950/sprockets%2F1ea6768fec37a8ee2ad758d4152ae1d2 +0 -0
- data/test/dummy/tmp/cache/assets/DA1/D40/sprockets%2Ffd605d648ad0a46b3e3ef9cf089a51b6 +0 -0
- data/test/dummy/tmp/cache/assets/DA1/FB0/sprockets%2Fe8cba462fd2940b4be7bf2d294fd7209 +0 -0
- data/test/dummy/tmp/cache/assets/DA9/140/sprockets%2Fa9dc7b7a71d4a92925c654f09d17fefa +0 -0
- data/test/dummy/tmp/cache/assets/DAA/960/sprockets%2F486294de7d016fa0ec65f0f9efa2e19f +0 -0
- data/test/dummy/tmp/cache/assets/DAB/9E0/sprockets%2Fa425c97bf53c87ea907267ce66ad5deb +0 -0
- data/test/dummy/tmp/cache/assets/DB3/1D0/sprockets%2F095c6e852a938bbfb9fc98a9ea105ee8 +0 -0
- data/test/dummy/tmp/cache/assets/DC3/C60/sprockets%2F0c49e61f99da10cf7acc0cac7736b23a +0 -0
- data/test/dummy/tmp/cache/assets/DC7/E70/sprockets%2Fdae539d9ce457212fabb2abf298e112d +0 -0
- data/test/dummy/tmp/cache/assets/DC8/C90/sprockets%2F880a4acdf2b3dec03f783e63ed10e6e3 +0 -0
- data/test/dummy/tmp/cache/assets/DD0/DE0/sprockets%2Fdd9bcfaa02c63a17f16d84fb523fd886 +0 -0
- data/test/dummy/tmp/cache/assets/DD0/E10/sprockets%2F7ff09d9b55239e81c67ac0bd1cd60cfb +0 -0
- data/test/dummy/tmp/cache/assets/DD3/140/sprockets%2Fdcdc4960e9f9381cbaec40b2f26c8f53 +0 -0
- data/test/dummy/tmp/cache/assets/DD4/340/sprockets%2Ff2cff1054cf9ff3d947f1372db9b6aa2 +0 -0
- data/test/dummy/tmp/cache/assets/DD7/F90/sprockets%2F3cbb2ecff5ff45927078c4490a93bfeb +0 -0
- data/test/dummy/tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/test/dummy/tmp/cache/assets/DE2/3D0/sprockets%2F503d37fdad31b11af5bd20b78ee3eaa0 +0 -0
- data/test/dummy/tmp/cache/assets/DF5/440/sprockets%2Fadaab579f5cf709a6c31b2fe40404ede +0 -0
- data/test/dummy/tmp/cache/assets/DFC/4A0/sprockets%2Fb2e7beb7a4bdf292c1b627bf0f84d9f0 +0 -0
- data/test/dummy/tmp/cache/assets/E02/C10/sprockets%2Fdd42eb4f61a99477f901cc31ddda7cfd +0 -0
- data/test/dummy/tmp/cache/assets/E04/610/sprockets%2Fd7d96ebe1affa231845c03c78ff6eaa7 +0 -0
- data/test/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/test/dummy/tmp/cache/assets/E14/060/sprockets%2F7d7d19b9786dbc0f535478bcdcdc8fce +0 -0
- data/test/dummy/tmp/cache/assets/E27/F00/sprockets%2F8abb689fab00eaa7301adf5d198f4dce +0 -0
- data/test/dummy/tmp/cache/assets/E2B/870/sprockets%2F22736cce6575f0dd0fcedb11ece9cc8a +0 -0
- data/test/dummy/tmp/cache/assets/E31/FB0/sprockets%2Fa8bb4c8b0dc7cc0affd698f7e2a27d72 +0 -0
- data/test/dummy/tmp/cache/assets/E3B/E00/sprockets%2F4e3fffccff7a681b16a92b6caf8ef761 +0 -0
- data/test/dummy/tmp/cache/assets/E57/9C0/sprockets%2Fb3ca68a8872ea6d2cc2bcbfe01a7fde6 +0 -0
- data/test/dummy/tmp/cache/assets/E69/200/sprockets%2Ff2e92a9a60ccdd889dd57cd5bdfed0f2 +0 -0
- data/test/dummy/tmp/cache/assets/E6B/860/sprockets%2Ffde862d9eef7ace776b5e3ebc470bcb4 +0 -0
- data/test/dummy/tmp/cache/assets/F4A/1F0/sprockets%2Ffceff42fa3bdfb2eafbcad5a77ad38ee +0 -0
- data/test/integration/navigation_test.rb +10 -0
- data/test/rubyception_test.rb +7 -0
- data/test/test_helper.rb +15 -0
- metadata +495 -0
@@ -0,0 +1,659 @@
|
|
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
|
+
}
|
659
|
+
|