Skip to content

Commit

Permalink
Added tableize support
Browse files Browse the repository at this point in the history
git-svn-id: http://inflection-js.googlecode.com/svn/trunk@32 d2fe450a-162e-0410-afd2-a5a3f3c8e437
  • Loading branch information
ryan.schuft committed Apr 15, 2007
1 parent 33942f8 commit 54e8c82
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
45 changes: 44 additions & 1 deletion inflection.js
Expand Up @@ -63,8 +63,11 @@ THE SOFTWARE.
String.titleize() == String
renders words into title casing (as for book titles)
String.demodulize() == String
renders class names that are prepended by modules into just the class
To be implemented:
demodulize, tableize, classify, foreign_key, constantize, and ordinalize
tableize, classify, foreign_key, and ordinalize
*/

/*
Expand Down Expand Up @@ -376,3 +379,43 @@ if(!String.prototype._non_titlecased_words)
'and','or','nor','a','an','the','so','but','to','of','at','by','from',
'into','on','onto','off','out','in','over','with','for'
];

/*
This function adds demodulize support to every String object
Signature:
String.demodulize() == String
Arguments:
N/A
Returns:
String - removes module names leaving only class names (Ruby style)
Examples:
"Message::Bus::Properties".demodulize() == "Properties"
*/
if(!String.prototype.demodulize)
String.prototype.demodulize=function()
{
var str=this;
var str_arr=str.split('::');
str=str_arr[str_arr.length-1];
return str;
};

/*
This function adds tableize support to every String object
Signature:
String.tableize() == String
Arguments:
N/A
Returns:
String - renders camel cased words into their underscored plural form
Examples:
"MessageBusProperty".tableize() == "message_bus_properties"
*/
if(!String.prototype.tableize)
String.prototype.tableize=function()
{
var str=this;
str=str.underscore().pluralize();
return str;
};

5 changes: 5 additions & 0 deletions test/inflection_test.html
Expand Up @@ -90,6 +90,11 @@
var t1="the man under the foot-bridge tells us how-to dance";
document.writeln("Titleize Test: "+t1.titleize());
document.writeln("<br>");
var d1="ActiveRecord::CoreExtensions::String::Inflections";
document.writeln("Demodulize Test: "+d1.demodulize());
document.writeln("<br>");
document.writeln("Tableize Test: "+"MessageBusProperty".tableize());
document.writeln("<br>");
</script>
</body>
</html>
Expand Down

0 comments on commit 54e8c82

Please sign in to comment.