Permalink
Browse files

cakefile

  • Loading branch information...
1 parent 563c01e commit b26bcbb735eb50329d587271eb58752a9d0cb27d @Radagaisus committed May 28, 2012
Showing with 831 additions and 1 deletion.
  1. +28 −0 Cakefile
  2. +44 −0 dist/commands.js
  3. +259 −0 dist/inflector.js
  4. +499 −0 dist/orpheus.js
  5. +1 −1 index.js
View
@@ -0,0 +1,28 @@
+{spawn, exec} = require 'child_process'
+log = console.log
+
+task 'build', "Compiles to JavaScript", ->
+ run 'coffee -o dist -c lib/*.coffee'
+ run 'cp lib/*.js dist/'
+
+task 'test', "Testing using Jasmine-Node", ->
+ run 'jasmine-node test/orpheus.spec.coffee --verbose --color --forceexit --coffee'
+
+task 'docs', "Create documenations using Docco", ->
+ run 'docco lib/*.coffee'
+
+run = (args...) ->
+ for a in args
+ switch typeof a
+ when 'string' then command = a
+ when 'object'
+ if a instanceof Array then params = a
+ else options = a
+ when 'function' then callback = a
+
+ command += ' ' + params.join ' ' if params?
+ cmd = spawn '/bin/sh', ['-c', command], options
+ cmd.stdout.on 'data', (data) -> process.stdout.write data
+ cmd.stderr.on 'data', (data) -> process.stderr.write data
+ process.on 'SIGHUP', -> cmd.kill()
+ cmd.on 'exit', (code) -> callback() if callback? and code is 0
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -0,0 +1,259 @@
+/*
+Copyright (c) 2010 Ryan Schuft (ryan.schuft@gmail.com)
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+
+/*
+ This code is based in part on the work done in Ruby to support
+ infection as part of Ruby on Rails in the ActiveSupport's Inflector
+ and Inflections classes. It was initally ported to Javascript by
+ Ryan Schuft (ryan.schuft@gmail.com) in 2007.
+
+ This code was modified and reduced by Almog Melamed. This version
+ does not infect the string prototype. The only functions available
+ are pluralize and singularize.
+
+ The code is available at http://code.google.com/p/inflection-js/
+
+ The basic usage is:
+ 1. inflector = require './inflector'
+ 2. inflector.pluralize(str) // etc
+
+ Currently implemented functions:
+
+ inflector.pluralize(str, plural) == String
+ renders a singular English language noun into its plural form
+ normal results can be overridden by passing in an alternative
+
+ inflector.singularize(str, singular) == String
+ renders a plural English language noun into its singular form
+ normal results can be overridden by passing in an alterative
+*/
+
+/*
+ This sets up some constants for later use
+*/
+InflectionJS =
+{
+ /*
+ This is a list of nouns that use the same form for both singular and plural.
+ This list should remain entirely in lower case to correctly match Strings.
+ */
+ uncountable_words: [
+ 'equipment', 'information', 'rice', 'money', 'species', 'series',
+ 'fish', 'sheep', 'moose', 'deer', 'news'
+ ],
+
+ /*
+ These rules translate from the singular form of a noun to its plural form.
+ */
+ plural_rules: [
+ [new RegExp('(m)an$', 'gi'), '$1en'],
+ [new RegExp('(pe)rson$', 'gi'), '$1ople'],
+ [new RegExp('(child)$', 'gi'), '$1ren'],
+ [new RegExp('^(ox)$', 'gi'), '$1en'],
+ [new RegExp('(ax|test)is$', 'gi'), '$1es'],
+ [new RegExp('(octop|vir)us$', 'gi'), '$1i'],
+ [new RegExp('(alias|status)$', 'gi'), '$1es'],
+ [new RegExp('(bu)s$', 'gi'), '$1ses'],
+ [new RegExp('(buffal|tomat|potat)o$', 'gi'), '$1oes'],
+ [new RegExp('([ti])um$', 'gi'), '$1a'],
+ [new RegExp('sis$', 'gi'), 'ses'],
+ [new RegExp('(?:([^f])fe|([lr])f)$', 'gi'), '$1$2ves'],
+ [new RegExp('(hive)$', 'gi'), '$1s'],
+ [new RegExp('([^aeiouy]|qu)y$', 'gi'), '$1ies'],
+ [new RegExp('(x|ch|ss|sh)$', 'gi'), '$1es'],
+ [new RegExp('(matr|vert|ind)ix|ex$', 'gi'), '$1ices'],
+ [new RegExp('([m|l])ouse$', 'gi'), '$1ice'],
+ [new RegExp('(quiz)$', 'gi'), '$1zes'],
+ [new RegExp('s$', 'gi'), 's'],
+ [new RegExp('$', 'gi'), 's']
+ ],
+
+ /*
+ These rules translate from the plural form of a noun to its singular form.
+ */
+ singular_rules: [
+ [new RegExp('(m)en$', 'gi'), '$1an'],
+ [new RegExp('(pe)ople$', 'gi'), '$1rson'],
+ [new RegExp('(child)ren$', 'gi'), '$1'],
+ [new RegExp('([ti])a$', 'gi'), '$1um'],
+ [new RegExp('((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$','gi'), '$1$2sis'],
+ [new RegExp('(hive)s$', 'gi'), '$1'],
+ [new RegExp('(tive)s$', 'gi'), '$1'],
+ [new RegExp('(curve)s$', 'gi'), '$1'],
+ [new RegExp('([lr])ves$', 'gi'), '$1f'],
+ [new RegExp('([^fo])ves$', 'gi'), '$1fe'],
+ [new RegExp('([^aeiouy]|qu)ies$', 'gi'), '$1y'],
+ [new RegExp('(s)eries$', 'gi'), '$1eries'],
+ [new RegExp('(m)ovies$', 'gi'), '$1ovie'],
+ [new RegExp('(x|ch|ss|sh)es$', 'gi'), '$1'],
+ [new RegExp('([m|l])ice$', 'gi'), '$1ouse'],
+ [new RegExp('(bus)es$', 'gi'), '$1'],
+ [new RegExp('(o)es$', 'gi'), '$1'],
+ [new RegExp('(shoe)s$', 'gi'), '$1'],
+ [new RegExp('(cris|ax|test)es$', 'gi'), '$1is'],
+ [new RegExp('(octop|vir)i$', 'gi'), '$1us'],
+ [new RegExp('(alias|status)es$', 'gi'), '$1'],
+ [new RegExp('^(ox)en', 'gi'), '$1'],
+ [new RegExp('(vert|ind)ices$', 'gi'), '$1ex'],
+ [new RegExp('(matr)ices$', 'gi'), '$1ix'],
+ [new RegExp('(quiz)zes$', 'gi'), '$1'],
+ [new RegExp('s$', 'gi'), '']
+ ],
+
+ /*
+ This is a list of words that should not be capitalized for title case
+ */
+ 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'
+ ],
+
+ /*
+ These are regular expressions used for converting between String formats
+ */
+ id_suffix: new RegExp('(_ids|_id)$', 'g'),
+ underbar: new RegExp('_', 'g'),
+ space_or_underbar: new RegExp('[\ _]', 'g'),
+ uppercase: new RegExp('([A-Z])', 'g'),
+ underbar_prefix: new RegExp('^_'),
+
+ /*
+ This is a helper method that applies rules based replacement to a String
+ Signature:
+ InflectionJS.apply_rules(str, rules, skip, override) == String
+ Arguments:
+ str - String - String to modify and return based on the passed rules
+ rules - Array: [RegExp, String] - Regexp to match paired with String to use for replacement
+ skip - Array: [String] - Strings to skip if they match
+ override - String (optional) - String to return as though this method succeeded (used to conform to APIs)
+ Returns:
+ String - passed String modified by passed rules
+ Examples:
+ InflectionJS.apply_rules("cows", InflectionJs.singular_rules) === 'cow'
+ */
+ apply_rules: function(str, rules, skip, override)
+ {
+ if (override)
+ {
+ str = override;
+ }
+ else
+ {
+ var ignore = (skip.indexOf(str.toLowerCase()) > -1);
+ if (!ignore)
+ {
+ for (var x = 0; x < rules.length; x++)
+ {
+ if (str.match(rules[x][0]))
+ {
+ str = str.replace(rules[x][0], rules[x][1]);
+ break;
+ }
+ }
+ }
+ }
+ return str;
+ }
+};
+
+/*
+ This lets us detect if an Array contains a given element
+ Signature:
+ Array.indexOf(item, fromIndex, compareFunc) == Integer
+ Arguments:
+ item - Object - object to locate in the Array
+ fromIndex - Integer (optional) - starts checking from this position in the Array
+ compareFunc - Function (optional) - function used to compare Array item vs passed item
+ Returns:
+ Integer - index position in the Array of the passed item
+ Examples:
+ ['hi','there'].indexOf("guys") === -1
+ ['hi','there'].indexOf("hi") === 0
+*/
+if (!Array.prototype.indexOf)
+{
+ Array.prototype.indexOf = function(item, fromIndex, compareFunc)
+ {
+ if (!fromIndex)
+ {
+ fromIndex = -1;
+ }
+ var index = -1;
+ for (var i = fromIndex; i < this.length; i++)
+ {
+ if (this[i] === item || compareFunc && compareFunc(this[i], item))
+ {
+ index = i;
+ break;
+ }
+ }
+ return index;
+ };
+}
+
+
+/*
+ This function adds plurilization support to every String object
+ Signature:
+ String.pluralize(plural) == String
+ Arguments:
+ plural - String (optional) - overrides normal output with said String
+ Returns:
+ String - singular English language nouns are returned in plural form
+ Examples:
+ "person".pluralize() == "people"
+ "octopus".pluralize() == "octopi"
+ "Hat".pluralize() == "Hats"
+ "person".pluralize("guys") == "guys"
+*/
+exports.pluralize = function(s, plural) {
+ return InflectionJS.apply_rules(
+ s,
+ InflectionJS.plural_rules,
+ InflectionJS.uncountable_words,
+ plural
+ );
+};
+
+/*
+ This function adds singularization support to every String object
+ Signature:
+ String.singularize(singular) == String
+ Arguments:
+ singular - String (optional) - overrides normal output with said String
+ Returns:
+ String - plural English language nouns are returned in singular form
+ Examples:
+ "people".singularize() == "person"
+ "octopi".singularize() == "octopus"
+ "Hats".singularize() == "Hat"
+ "guys".singularize("person") == "person"
+*/
+exports.singularize = function(s, singular) {
+ return InflectionJS.apply_rules(
+ s,
+ InflectionJS.plural_rules,
+ InflectionJS.uncountable_words,
+ singular
+ );
+};
Oops, something went wrong.

0 comments on commit b26bcbb

Please sign in to comment.