inflection-js-rails 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +62 -0
- data/LICENSE +21 -0
- data/README.md +97 -0
- data/Rakefile +10 -0
- data/inflection-js-rails.gemspec +22 -0
- data/lib/generators/inflectionjs/install/install_generator.rb +36 -0
- data/lib/inflection-js-rails.rb +1 -0
- data/lib/inflectionjs/rails.rb +2 -0
- data/lib/inflectionjs/rails/engine.rb +6 -0
- data/lib/inflectionjs/rails/version.rb +6 -0
- data/vendor/assets/javascripts/inflection.js +656 -0
- metadata +19 -6
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
inflection-js-rails (0.1.0)
|
5
|
+
railties (>= 3.2.0, < 5.0)
|
6
|
+
thor (~> 0.14)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: http://rubygems.org/
|
10
|
+
specs:
|
11
|
+
actionpack (3.2.3)
|
12
|
+
activemodel (= 3.2.3)
|
13
|
+
activesupport (= 3.2.3)
|
14
|
+
builder (~> 3.0.0)
|
15
|
+
erubis (~> 2.7.0)
|
16
|
+
journey (~> 1.0.1)
|
17
|
+
rack (~> 1.4.0)
|
18
|
+
rack-cache (~> 1.2)
|
19
|
+
rack-test (~> 0.6.1)
|
20
|
+
sprockets (~> 2.1.2)
|
21
|
+
activemodel (3.2.3)
|
22
|
+
activesupport (= 3.2.3)
|
23
|
+
builder (~> 3.0.0)
|
24
|
+
activesupport (3.2.3)
|
25
|
+
i18n (~> 0.6)
|
26
|
+
multi_json (~> 1.0)
|
27
|
+
builder (3.0.0)
|
28
|
+
erubis (2.7.0)
|
29
|
+
hike (1.2.1)
|
30
|
+
i18n (0.6.0)
|
31
|
+
journey (1.0.3)
|
32
|
+
json (1.6.6)
|
33
|
+
multi_json (1.2.0)
|
34
|
+
rack (1.4.1)
|
35
|
+
rack-cache (1.2)
|
36
|
+
rack (>= 0.4)
|
37
|
+
rack-ssl (1.3.2)
|
38
|
+
rack
|
39
|
+
rack-test (0.6.1)
|
40
|
+
rack (>= 1.0)
|
41
|
+
railties (3.2.3)
|
42
|
+
actionpack (= 3.2.3)
|
43
|
+
activesupport (= 3.2.3)
|
44
|
+
rack-ssl (~> 1.3.2)
|
45
|
+
rake (>= 0.8.7)
|
46
|
+
rdoc (~> 3.4)
|
47
|
+
thor (~> 0.14.6)
|
48
|
+
rake (0.9.2.2)
|
49
|
+
rdoc (3.12)
|
50
|
+
json (~> 1.4)
|
51
|
+
sprockets (2.1.2)
|
52
|
+
hike (~> 1.2)
|
53
|
+
rack (~> 1.0)
|
54
|
+
tilt (~> 1.1, != 1.3.0)
|
55
|
+
thor (0.14.6)
|
56
|
+
tilt (1.3.3)
|
57
|
+
|
58
|
+
PLATFORMS
|
59
|
+
ruby
|
60
|
+
|
61
|
+
DEPENDENCIES
|
62
|
+
inflection-js-rails!
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2010 Andre Arko
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
# inflection-js-rails
|
2
|
+
|
3
|
+
ActiveSupport style inflections for client-side development for the Rails Asset Pipeline
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
In your Gemfile, add this line:
|
8
|
+
|
9
|
+
gem 'inflection-js-rails'
|
10
|
+
|
11
|
+
Now run `bundle install`
|
12
|
+
|
13
|
+
### Rails 3.0
|
14
|
+
|
15
|
+
This gem adds a single generator to Rails 3, `inflectionjs:install`.
|
16
|
+
|
17
|
+
Running the generator will copy over `inflection.js` to your assets to `public/javascript/`.
|
18
|
+
|
19
|
+
### Rails 3.1 or greater
|
20
|
+
|
21
|
+
For Rails 3.1 and greater, the files will be added to the asset pipeline and available for you to use.
|
22
|
+
|
23
|
+
Simply the following to `app/assets/javascripts/application.js`:
|
24
|
+
|
25
|
+
//= require inflection
|
26
|
+
|
27
|
+
## Javascript String Functions
|
28
|
+
|
29
|
+
The following functions will be available to each String instance:
|
30
|
+
|
31
|
+
String.pluralize(plural) == String
|
32
|
+
renders a singular English language noun into its plural form
|
33
|
+
normal results can be overridden by passing in an alternative
|
34
|
+
|
35
|
+
String.singularize(singular) == String
|
36
|
+
renders a plural English language noun into its singular form
|
37
|
+
normal results can be overridden by passing in an alterative
|
38
|
+
|
39
|
+
String.camelize(lowFirstLetter) == String
|
40
|
+
renders a lower case underscored word into camel case
|
41
|
+
the first letter of the result will be upper case unless you pass true
|
42
|
+
also translates "/" into "::" (underscore does the opposite)
|
43
|
+
|
44
|
+
String.underscore() == String
|
45
|
+
renders a camel cased word into words seperated by underscores
|
46
|
+
also translates "::" back into "/" (camelize does the opposite)
|
47
|
+
|
48
|
+
String.humanize(lowFirstLetter) == String
|
49
|
+
renders a lower case and underscored word into human readable form
|
50
|
+
defaults to making the first letter capitalized unless you pass true
|
51
|
+
|
52
|
+
String.capitalize() == String
|
53
|
+
renders all characters to lower case and then makes the first upper
|
54
|
+
|
55
|
+
String.dasherize() == String
|
56
|
+
renders all underbars and spaces as dashes
|
57
|
+
|
58
|
+
String.titleize() == String
|
59
|
+
renders words into title casing (as for book titles)
|
60
|
+
|
61
|
+
String.demodulize() == String
|
62
|
+
renders class names that are prepended by modules into just the class
|
63
|
+
|
64
|
+
String.tableize() == String
|
65
|
+
renders camel cased singular words into their underscored plural form
|
66
|
+
|
67
|
+
String.classify() == String
|
68
|
+
renders an underscored plural word into its camel cased singular form
|
69
|
+
|
70
|
+
String.foreign_key(dropIdUbar) == String
|
71
|
+
renders a class name (camel cased singular noun) into a foreign key
|
72
|
+
defaults to seperating the class from the id with an underbar unless
|
73
|
+
you pass true
|
74
|
+
|
75
|
+
String.ordinalize() == String
|
76
|
+
renders all numbers found in the string into their sequence like "22nd"
|
77
|
+
|
78
|
+
## Props
|
79
|
+
|
80
|
+
I didn't write any of the Javascript included within inflection-js.
|
81
|
+
All props goto Ryan Schuft.
|
82
|
+
|
83
|
+
[Original project URL](http://code.google.com/p/inflection-js/)
|
84
|
+
|
85
|
+
## Contributing
|
86
|
+
|
87
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
88
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
89
|
+
* Fork the project
|
90
|
+
* Start a feature/bugfix branch
|
91
|
+
* Commit and push until you are happy with your contribution
|
92
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
93
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
94
|
+
|
95
|
+
## Copyright
|
96
|
+
|
97
|
+
Copyright (c) 2010 Ryan Lewis. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/inflectionjs/rails/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "inflection-js-rails"
|
6
|
+
s.version = Inflectionjs::Rails::VERSION
|
7
|
+
s.platform = Gem::Platform::RUBY
|
8
|
+
s.authors = ["Ryan Scott Lewis"]
|
9
|
+
s.email = ["c00lryguy@gmail.com"]
|
10
|
+
s.homepage = "http://rubygems.org/gems/inflection-js-rails"
|
11
|
+
s.summary = "Use inflection-js with Rails 3"
|
12
|
+
s.description = "This gem provides inflection-js assets for your Rails 3 application."
|
13
|
+
|
14
|
+
s.required_rubygems_version = ">= 1.3.6"
|
15
|
+
|
16
|
+
s.add_dependency "railties", ">= 3.2.0", "< 5.0"
|
17
|
+
s.add_dependency "thor", "~> 0.14"
|
18
|
+
|
19
|
+
s.files = `git ls-files`.split("\n")
|
20
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
21
|
+
s.require_path = 'lib'
|
22
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'rails'
|
2
|
+
|
3
|
+
# Supply generator for Rails 3.0.x or if asset pipeline is not enabled
|
4
|
+
if ::Rails.version < "3.1" || !::Rails.application.config.assets.enabled
|
5
|
+
module Inflectionjs
|
6
|
+
module Generators
|
7
|
+
class InstallGenerator < ::Rails::Generators::Base
|
8
|
+
|
9
|
+
desc "This generator installs inflection-js #{Inflectionjs::Rails::INFLECTION_JS_VERSION}"
|
10
|
+
source_root File.expand_path('../../../../../vendor/assets/javascripts', __FILE__)
|
11
|
+
|
12
|
+
def copy_inflectionjs
|
13
|
+
say_status("copying", "inflection-js (#{Inflectionjs::Rails::INFLECTION_JS_VERSION})", :green)
|
14
|
+
copy_file "inflection.js", "public/javascripts/inflection.js"
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
else
|
21
|
+
module Inflectionjs
|
22
|
+
module Generators
|
23
|
+
class InstallGenerator < ::Rails::Generators::Base
|
24
|
+
desc "Just show instructions so people will know what to do when mistakenly using generator for Rails 3.1 apps"
|
25
|
+
|
26
|
+
def do_nothing
|
27
|
+
say_status("deprecated", "You are using Rails 3.1 or the asset pipeline enabled, so this generator is not needed.")
|
28
|
+
say_status("", "The necessary files are already in your asset pipeline.")
|
29
|
+
say_status("", "Just add `//= require inflection` to your app/assets/javascripts/application.js")
|
30
|
+
say_status("", "If you do not want the asset pipeline enabled, you may turn it off in application.rb and re-run this generator.")
|
31
|
+
# ok, nothing
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'inflectionjs/rails'
|
@@ -0,0 +1,656 @@
|
|
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('(pe)rson$', 'gi'), '$1ople'],
|
116
|
+
[new RegExp('(child)$', 'gi'), '$1ren'],
|
117
|
+
[new RegExp('^(ox)$', 'gi'), '$1en'],
|
118
|
+
[new RegExp('(ax|test)is$', 'gi'), '$1es'],
|
119
|
+
[new RegExp('(octop|vir)us$', 'gi'), '$1i'],
|
120
|
+
[new RegExp('(alias|status)$', 'gi'), '$1es'],
|
121
|
+
[new RegExp('(bu)s$', 'gi'), '$1ses'],
|
122
|
+
[new RegExp('(buffal|tomat|potat)o$', 'gi'), '$1oes'],
|
123
|
+
[new RegExp('([ti])um$', 'gi'), '$1a'],
|
124
|
+
[new RegExp('sis$', 'gi'), 'ses'],
|
125
|
+
[new RegExp('(?:([^f])fe|([lr])f)$', 'gi'), '$1$2ves'],
|
126
|
+
[new RegExp('(hive)$', 'gi'), '$1s'],
|
127
|
+
[new RegExp('([^aeiouy]|qu)y$', 'gi'), '$1ies'],
|
128
|
+
[new RegExp('(x|ch|ss|sh)$', 'gi'), '$1es'],
|
129
|
+
[new RegExp('(matr|vert|ind)ix|ex$', 'gi'), '$1ices'],
|
130
|
+
[new RegExp('([m|l])ouse$', 'gi'), '$1ice'],
|
131
|
+
[new RegExp('(quiz)$', 'gi'), '$1zes'],
|
132
|
+
[new RegExp('s$', 'gi'), 's'],
|
133
|
+
[new RegExp('$', 'gi'), 's']
|
134
|
+
],
|
135
|
+
|
136
|
+
/*
|
137
|
+
These rules translate from the plural form of a noun to its singular form.
|
138
|
+
*/
|
139
|
+
singular_rules: [
|
140
|
+
[new RegExp('(m)en$', 'gi'), '$1an'],
|
141
|
+
[new RegExp('(pe)ople$', 'gi'), '$1rson'],
|
142
|
+
[new RegExp('(child)ren$', 'gi'), '$1'],
|
143
|
+
[new RegExp('([ti])a$', 'gi'), '$1um'],
|
144
|
+
[new RegExp('((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$','gi'), '$1$2sis'],
|
145
|
+
[new RegExp('(hive)s$', 'gi'), '$1'],
|
146
|
+
[new RegExp('(tive)s$', 'gi'), '$1'],
|
147
|
+
[new RegExp('(curve)s$', 'gi'), '$1'],
|
148
|
+
[new RegExp('([lr])ves$', 'gi'), '$1f'],
|
149
|
+
[new RegExp('([^fo])ves$', 'gi'), '$1fe'],
|
150
|
+
[new RegExp('([^aeiouy]|qu)ies$', 'gi'), '$1y'],
|
151
|
+
[new RegExp('(s)eries$', 'gi'), '$1eries'],
|
152
|
+
[new RegExp('(m)ovies$', 'gi'), '$1ovie'],
|
153
|
+
[new RegExp('(x|ch|ss|sh)es$', 'gi'), '$1'],
|
154
|
+
[new RegExp('([m|l])ice$', 'gi'), '$1ouse'],
|
155
|
+
[new RegExp('(bus)es$', 'gi'), '$1'],
|
156
|
+
[new RegExp('(o)es$', 'gi'), '$1'],
|
157
|
+
[new RegExp('(shoe)s$', 'gi'), '$1'],
|
158
|
+
[new RegExp('(cris|ax|test)es$', 'gi'), '$1is'],
|
159
|
+
[new RegExp('(octop|vir)i$', 'gi'), '$1us'],
|
160
|
+
[new RegExp('(alias|status)es$', 'gi'), '$1'],
|
161
|
+
[new RegExp('^(ox)en', 'gi'), '$1'],
|
162
|
+
[new RegExp('(vert|ind)ices$', 'gi'), '$1ex'],
|
163
|
+
[new RegExp('(matr)ices$', 'gi'), '$1ix'],
|
164
|
+
[new RegExp('(quiz)zes$', 'gi'), '$1'],
|
165
|
+
[new RegExp('s$', 'gi'), '']
|
166
|
+
],
|
167
|
+
|
168
|
+
/*
|
169
|
+
This is a list of words that should not be capitalized for title case
|
170
|
+
*/
|
171
|
+
non_titlecased_words: [
|
172
|
+
'and', 'or', 'nor', 'a', 'an', 'the', 'so', 'but', 'to', 'of', 'at',
|
173
|
+
'by', 'from', 'into', 'on', 'onto', 'off', 'out', 'in', 'over',
|
174
|
+
'with', 'for'
|
175
|
+
],
|
176
|
+
|
177
|
+
/*
|
178
|
+
These are regular expressions used for converting between String formats
|
179
|
+
*/
|
180
|
+
id_suffix: new RegExp('(_ids|_id)$', 'g'),
|
181
|
+
underbar: new RegExp('_', 'g'),
|
182
|
+
space_or_underbar: new RegExp('[\ _]', 'g'),
|
183
|
+
uppercase: new RegExp('([A-Z])', 'g'),
|
184
|
+
underbar_prefix: new RegExp('^_'),
|
185
|
+
|
186
|
+
/*
|
187
|
+
This is a helper method that applies rules based replacement to a String
|
188
|
+
Signature:
|
189
|
+
InflectionJS.apply_rules(str, rules, skip, override) == String
|
190
|
+
Arguments:
|
191
|
+
str - String - String to modify and return based on the passed rules
|
192
|
+
rules - Array: [RegExp, String] - Regexp to match paired with String to use for replacement
|
193
|
+
skip - Array: [String] - Strings to skip if they match
|
194
|
+
override - String (optional) - String to return as though this method succeeded (used to conform to APIs)
|
195
|
+
Returns:
|
196
|
+
String - passed String modified by passed rules
|
197
|
+
Examples:
|
198
|
+
InflectionJS.apply_rules("cows", InflectionJs.singular_rules) === 'cow'
|
199
|
+
*/
|
200
|
+
apply_rules: function(str, rules, skip, override)
|
201
|
+
{
|
202
|
+
if (override)
|
203
|
+
{
|
204
|
+
str = override;
|
205
|
+
}
|
206
|
+
else
|
207
|
+
{
|
208
|
+
var ignore = (skip.indexOf(str.toLowerCase()) > -1);
|
209
|
+
if (!ignore)
|
210
|
+
{
|
211
|
+
for (var x = 0; x < rules.length; x++)
|
212
|
+
{
|
213
|
+
if (str.match(rules[x][0]))
|
214
|
+
{
|
215
|
+
str = str.replace(rules[x][0], rules[x][1]);
|
216
|
+
break;
|
217
|
+
}
|
218
|
+
}
|
219
|
+
}
|
220
|
+
}
|
221
|
+
return str;
|
222
|
+
}
|
223
|
+
};
|
224
|
+
|
225
|
+
/*
|
226
|
+
This lets us detect if an Array contains a given element
|
227
|
+
Signature:
|
228
|
+
Array.indexOf(item, fromIndex, compareFunc) == Integer
|
229
|
+
Arguments:
|
230
|
+
item - Object - object to locate in the Array
|
231
|
+
fromIndex - Integer (optional) - starts checking from this position in the Array
|
232
|
+
compareFunc - Function (optional) - function used to compare Array item vs passed item
|
233
|
+
Returns:
|
234
|
+
Integer - index position in the Array of the passed item
|
235
|
+
Examples:
|
236
|
+
['hi','there'].indexOf("guys") === -1
|
237
|
+
['hi','there'].indexOf("hi") === 0
|
238
|
+
*/
|
239
|
+
if (!Array.prototype.indexOf)
|
240
|
+
{
|
241
|
+
Array.prototype.indexOf = function(item, fromIndex, compareFunc)
|
242
|
+
{
|
243
|
+
if (!fromIndex)
|
244
|
+
{
|
245
|
+
fromIndex = -1;
|
246
|
+
}
|
247
|
+
var index = -1;
|
248
|
+
for (var i = fromIndex; i < this.length; i++)
|
249
|
+
{
|
250
|
+
if (this[i] === item || compareFunc && compareFunc(this[i], item))
|
251
|
+
{
|
252
|
+
index = i;
|
253
|
+
break;
|
254
|
+
}
|
255
|
+
}
|
256
|
+
return index;
|
257
|
+
};
|
258
|
+
}
|
259
|
+
|
260
|
+
/*
|
261
|
+
You can override this list for all Strings or just one depending on if you
|
262
|
+
set the new values on prototype or on a given String instance.
|
263
|
+
*/
|
264
|
+
if (!String.prototype._uncountable_words)
|
265
|
+
{
|
266
|
+
String.prototype._uncountable_words = InflectionJS.uncountable_words;
|
267
|
+
}
|
268
|
+
|
269
|
+
/*
|
270
|
+
You can override this list for all Strings or just one depending on if you
|
271
|
+
set the new values on prototype or on a given String instance.
|
272
|
+
*/
|
273
|
+
if (!String.prototype._plural_rules)
|
274
|
+
{
|
275
|
+
String.prototype._plural_rules = InflectionJS.plural_rules;
|
276
|
+
}
|
277
|
+
|
278
|
+
/*
|
279
|
+
You can override this list for all Strings or just one depending on if you
|
280
|
+
set the new values on prototype or on a given String instance.
|
281
|
+
*/
|
282
|
+
if (!String.prototype._singular_rules)
|
283
|
+
{
|
284
|
+
String.prototype._singular_rules = InflectionJS.singular_rules;
|
285
|
+
}
|
286
|
+
|
287
|
+
/*
|
288
|
+
You can override this list for all Strings or just one depending on if you
|
289
|
+
set the new values on prototype or on a given String instance.
|
290
|
+
*/
|
291
|
+
if (!String.prototype._non_titlecased_words)
|
292
|
+
{
|
293
|
+
String.prototype._non_titlecased_words = InflectionJS.non_titlecased_words;
|
294
|
+
}
|
295
|
+
|
296
|
+
/*
|
297
|
+
This function adds plurilization support to every String object
|
298
|
+
Signature:
|
299
|
+
String.pluralize(plural) == String
|
300
|
+
Arguments:
|
301
|
+
plural - String (optional) - overrides normal output with said String
|
302
|
+
Returns:
|
303
|
+
String - singular English language nouns are returned in plural form
|
304
|
+
Examples:
|
305
|
+
"person".pluralize() == "people"
|
306
|
+
"octopus".pluralize() == "octopi"
|
307
|
+
"Hat".pluralize() == "Hats"
|
308
|
+
"person".pluralize("guys") == "guys"
|
309
|
+
*/
|
310
|
+
if (!String.prototype.pluralize)
|
311
|
+
{
|
312
|
+
String.prototype.pluralize = function(plural)
|
313
|
+
{
|
314
|
+
return InflectionJS.apply_rules(
|
315
|
+
this,
|
316
|
+
this._plural_rules,
|
317
|
+
this._uncountable_words,
|
318
|
+
plural
|
319
|
+
);
|
320
|
+
};
|
321
|
+
}
|
322
|
+
|
323
|
+
/*
|
324
|
+
This function adds singularization support to every String object
|
325
|
+
Signature:
|
326
|
+
String.singularize(singular) == String
|
327
|
+
Arguments:
|
328
|
+
singular - String (optional) - overrides normal output with said String
|
329
|
+
Returns:
|
330
|
+
String - plural English language nouns are returned in singular form
|
331
|
+
Examples:
|
332
|
+
"people".singularize() == "person"
|
333
|
+
"octopi".singularize() == "octopus"
|
334
|
+
"Hats".singularize() == "Hat"
|
335
|
+
"guys".singularize("person") == "person"
|
336
|
+
*/
|
337
|
+
if (!String.prototype.singularize)
|
338
|
+
{
|
339
|
+
String.prototype.singularize = function(singular)
|
340
|
+
{
|
341
|
+
return InflectionJS.apply_rules(
|
342
|
+
this,
|
343
|
+
this._singular_rules,
|
344
|
+
this._uncountable_words,
|
345
|
+
singular
|
346
|
+
);
|
347
|
+
};
|
348
|
+
}
|
349
|
+
|
350
|
+
/*
|
351
|
+
This function adds camelization support to every String object
|
352
|
+
Signature:
|
353
|
+
String.camelize(lowFirstLetter) == String
|
354
|
+
Arguments:
|
355
|
+
lowFirstLetter - boolean (optional) - default is to capitalize the first
|
356
|
+
letter of the results... passing true will lowercase it
|
357
|
+
Returns:
|
358
|
+
String - lower case underscored words will be returned in camel case
|
359
|
+
additionally '/' is translated to '::'
|
360
|
+
Examples:
|
361
|
+
"message_properties".camelize() == "MessageProperties"
|
362
|
+
"message_properties".camelize(true) == "messageProperties"
|
363
|
+
*/
|
364
|
+
if (!String.prototype.camelize)
|
365
|
+
{
|
366
|
+
String.prototype.camelize = function(lowFirstLetter)
|
367
|
+
{
|
368
|
+
var str = this.toLowerCase();
|
369
|
+
var str_path = str.split('/');
|
370
|
+
for (var i = 0; i < str_path.length; i++)
|
371
|
+
{
|
372
|
+
var str_arr = str_path[i].split('_');
|
373
|
+
var initX = ((lowFirstLetter && i + 1 === str_path.length) ? (1) : (0));
|
374
|
+
for (var x = initX; x < str_arr.length; x++)
|
375
|
+
{
|
376
|
+
str_arr[x] = str_arr[x].charAt(0).toUpperCase() + str_arr[x].substring(1);
|
377
|
+
}
|
378
|
+
str_path[i] = str_arr.join('');
|
379
|
+
}
|
380
|
+
str = str_path.join('::');
|
381
|
+
return str;
|
382
|
+
};
|
383
|
+
}
|
384
|
+
|
385
|
+
/*
|
386
|
+
This function adds underscore support to every String object
|
387
|
+
Signature:
|
388
|
+
String.underscore() == String
|
389
|
+
Arguments:
|
390
|
+
N/A
|
391
|
+
Returns:
|
392
|
+
String - camel cased words are returned as lower cased and underscored
|
393
|
+
additionally '::' is translated to '/'
|
394
|
+
Examples:
|
395
|
+
"MessageProperties".camelize() == "message_properties"
|
396
|
+
"messageProperties".underscore() == "message_properties"
|
397
|
+
*/
|
398
|
+
if (!String.prototype.underscore)
|
399
|
+
{
|
400
|
+
String.prototype.underscore = function()
|
401
|
+
{
|
402
|
+
var str = this;
|
403
|
+
var str_path = str.split('::');
|
404
|
+
for (var i = 0; i < str_path.length; i++)
|
405
|
+
{
|
406
|
+
str_path[i] = str_path[i].replace(InflectionJS.uppercase, '_$1');
|
407
|
+
str_path[i] = str_path[i].replace(InflectionJS.underbar_prefix, '');
|
408
|
+
}
|
409
|
+
str = str_path.join('/').toLowerCase();
|
410
|
+
return str;
|
411
|
+
};
|
412
|
+
}
|
413
|
+
|
414
|
+
/*
|
415
|
+
This function adds humanize support to every String object
|
416
|
+
Signature:
|
417
|
+
String.humanize(lowFirstLetter) == String
|
418
|
+
Arguments:
|
419
|
+
lowFirstLetter - boolean (optional) - default is to capitalize the first
|
420
|
+
letter of the results... passing true will lowercase it
|
421
|
+
Returns:
|
422
|
+
String - lower case underscored words will be returned in humanized form
|
423
|
+
Examples:
|
424
|
+
"message_properties".humanize() == "Message properties"
|
425
|
+
"message_properties".humanize(true) == "message properties"
|
426
|
+
*/
|
427
|
+
if (!String.prototype.humanize)
|
428
|
+
{
|
429
|
+
String.prototype.humanize = function(lowFirstLetter)
|
430
|
+
{
|
431
|
+
var str = this.toLowerCase();
|
432
|
+
str = str.replace(InflectionJS.id_suffix, '');
|
433
|
+
str = str.replace(InflectionJS.underbar, ' ');
|
434
|
+
if (!lowFirstLetter)
|
435
|
+
{
|
436
|
+
str = str.capitalize();
|
437
|
+
}
|
438
|
+
return str;
|
439
|
+
};
|
440
|
+
}
|
441
|
+
|
442
|
+
/*
|
443
|
+
This function adds capitalization support to every String object
|
444
|
+
Signature:
|
445
|
+
String.capitalize() == String
|
446
|
+
Arguments:
|
447
|
+
N/A
|
448
|
+
Returns:
|
449
|
+
String - all characters will be lower case and the first will be upper
|
450
|
+
Examples:
|
451
|
+
"message_properties".capitalize() == "Message_properties"
|
452
|
+
"message properties".capitalize() == "Message properties"
|
453
|
+
*/
|
454
|
+
if (!String.prototype.capitalize)
|
455
|
+
{
|
456
|
+
String.prototype.capitalize = function()
|
457
|
+
{
|
458
|
+
var str = this.toLowerCase();
|
459
|
+
str = str.substring(0, 1).toUpperCase() + str.substring(1);
|
460
|
+
return str;
|
461
|
+
};
|
462
|
+
}
|
463
|
+
|
464
|
+
/*
|
465
|
+
This function adds dasherization support to every String object
|
466
|
+
Signature:
|
467
|
+
String.dasherize() == String
|
468
|
+
Arguments:
|
469
|
+
N/A
|
470
|
+
Returns:
|
471
|
+
String - replaces all spaces or underbars with dashes
|
472
|
+
Examples:
|
473
|
+
"message_properties".capitalize() == "message-properties"
|
474
|
+
"Message Properties".capitalize() == "Message-Properties"
|
475
|
+
*/
|
476
|
+
if (!String.prototype.dasherize)
|
477
|
+
{
|
478
|
+
String.prototype.dasherize = function()
|
479
|
+
{
|
480
|
+
var str = this;
|
481
|
+
str = str.replace(InflectionJS.space_or_underbar, '-');
|
482
|
+
return str;
|
483
|
+
};
|
484
|
+
}
|
485
|
+
|
486
|
+
/*
|
487
|
+
This function adds titleize support to every String object
|
488
|
+
Signature:
|
489
|
+
String.titleize() == String
|
490
|
+
Arguments:
|
491
|
+
N/A
|
492
|
+
Returns:
|
493
|
+
String - capitalizes words as you would for a book title
|
494
|
+
Examples:
|
495
|
+
"message_properties".titleize() == "Message Properties"
|
496
|
+
"message properties to keep".titleize() == "Message Properties to Keep"
|
497
|
+
*/
|
498
|
+
if (!String.prototype.titleize)
|
499
|
+
{
|
500
|
+
String.prototype.titleize = function()
|
501
|
+
{
|
502
|
+
var str = this.toLowerCase();
|
503
|
+
str = str.replace(InflectionJS.underbar, ' ');
|
504
|
+
var str_arr = str.split(' ');
|
505
|
+
for (var x = 0; x < str_arr.length; x++)
|
506
|
+
{
|
507
|
+
var d = str_arr[x].split('-');
|
508
|
+
for (var i = 0; i < d.length; i++)
|
509
|
+
{
|
510
|
+
if (this._non_titlecased_words.indexOf(d[i].toLowerCase()) < 0)
|
511
|
+
{
|
512
|
+
d[i] = d[i].capitalize();
|
513
|
+
}
|
514
|
+
}
|
515
|
+
str_arr[x] = d.join('-');
|
516
|
+
}
|
517
|
+
str = str_arr.join(' ');
|
518
|
+
str = str.substring(0, 1).toUpperCase() + str.substring(1);
|
519
|
+
return str;
|
520
|
+
};
|
521
|
+
}
|
522
|
+
|
523
|
+
/*
|
524
|
+
This function adds demodulize support to every String object
|
525
|
+
Signature:
|
526
|
+
String.demodulize() == String
|
527
|
+
Arguments:
|
528
|
+
N/A
|
529
|
+
Returns:
|
530
|
+
String - removes module names leaving only class names (Ruby style)
|
531
|
+
Examples:
|
532
|
+
"Message::Bus::Properties".demodulize() == "Properties"
|
533
|
+
*/
|
534
|
+
if (!String.prototype.demodulize)
|
535
|
+
{
|
536
|
+
String.prototype.demodulize = function()
|
537
|
+
{
|
538
|
+
var str = this;
|
539
|
+
var str_arr = str.split('::');
|
540
|
+
str = str_arr[str_arr.length - 1];
|
541
|
+
return str;
|
542
|
+
};
|
543
|
+
}
|
544
|
+
|
545
|
+
/*
|
546
|
+
This function adds tableize support to every String object
|
547
|
+
Signature:
|
548
|
+
String.tableize() == String
|
549
|
+
Arguments:
|
550
|
+
N/A
|
551
|
+
Returns:
|
552
|
+
String - renders camel cased words into their underscored plural form
|
553
|
+
Examples:
|
554
|
+
"MessageBusProperty".tableize() == "message_bus_properties"
|
555
|
+
*/
|
556
|
+
if (!String.prototype.tableize)
|
557
|
+
{
|
558
|
+
String.prototype.tableize = function()
|
559
|
+
{
|
560
|
+
var str = this;
|
561
|
+
str = str.underscore().pluralize();
|
562
|
+
return str;
|
563
|
+
};
|
564
|
+
}
|
565
|
+
|
566
|
+
/*
|
567
|
+
This function adds classification support to every String object
|
568
|
+
Signature:
|
569
|
+
String.classify() == String
|
570
|
+
Arguments:
|
571
|
+
N/A
|
572
|
+
Returns:
|
573
|
+
String - underscored plural nouns become the camel cased singular form
|
574
|
+
Examples:
|
575
|
+
"message_bus_properties".classify() == "MessageBusProperty"
|
576
|
+
*/
|
577
|
+
if (!String.prototype.classify)
|
578
|
+
{
|
579
|
+
String.prototype.classify = function()
|
580
|
+
{
|
581
|
+
var str = this;
|
582
|
+
str = str.camelize().singularize();
|
583
|
+
return str;
|
584
|
+
};
|
585
|
+
}
|
586
|
+
|
587
|
+
/*
|
588
|
+
This function adds foreign key support to every String object
|
589
|
+
Signature:
|
590
|
+
String.foreign_key(dropIdUbar) == String
|
591
|
+
Arguments:
|
592
|
+
dropIdUbar - boolean (optional) - default is to seperate id with an
|
593
|
+
underbar at the end of the class name, you can pass true to skip it
|
594
|
+
Returns:
|
595
|
+
String - camel cased singular class names become underscored with id
|
596
|
+
Examples:
|
597
|
+
"MessageBusProperty".foreign_key() == "message_bus_property_id"
|
598
|
+
"MessageBusProperty".foreign_key(true) == "message_bus_propertyid"
|
599
|
+
*/
|
600
|
+
if (!String.prototype.foreign_key)
|
601
|
+
{
|
602
|
+
String.prototype.foreign_key = function(dropIdUbar)
|
603
|
+
{
|
604
|
+
var str = this;
|
605
|
+
str = str.demodulize().underscore() + ((dropIdUbar) ? ('') : ('_')) + 'id';
|
606
|
+
return str;
|
607
|
+
};
|
608
|
+
}
|
609
|
+
|
610
|
+
/*
|
611
|
+
This function adds ordinalize support to every String object
|
612
|
+
Signature:
|
613
|
+
String.ordinalize() == String
|
614
|
+
Arguments:
|
615
|
+
N/A
|
616
|
+
Returns:
|
617
|
+
String - renders all found numbers their sequence like "22nd"
|
618
|
+
Examples:
|
619
|
+
"the 1 pitch".ordinalize() == "the 1st pitch"
|
620
|
+
*/
|
621
|
+
if (!String.prototype.ordinalize)
|
622
|
+
{
|
623
|
+
String.prototype.ordinalize = function()
|
624
|
+
{
|
625
|
+
var str = this;
|
626
|
+
var str_arr = str.split(' ');
|
627
|
+
for (var x = 0; x < str_arr.length; x++)
|
628
|
+
{
|
629
|
+
var i = parseInt(str_arr[x]);
|
630
|
+
if (i === NaN)
|
631
|
+
{
|
632
|
+
var ltd = str_arr[x].substring(str_arr[x].length - 2);
|
633
|
+
var ld = str_arr[x].substring(str_arr[x].length - 1);
|
634
|
+
var suf = "th";
|
635
|
+
if (ltd != "11" && ltd != "12" && ltd != "13")
|
636
|
+
{
|
637
|
+
if (ld === "1")
|
638
|
+
{
|
639
|
+
suf = "st";
|
640
|
+
}
|
641
|
+
else if (ld === "2")
|
642
|
+
{
|
643
|
+
suf = "nd";
|
644
|
+
}
|
645
|
+
else if (ld === "3")
|
646
|
+
{
|
647
|
+
suf = "rd";
|
648
|
+
}
|
649
|
+
}
|
650
|
+
str_arr[x] += suf;
|
651
|
+
}
|
652
|
+
}
|
653
|
+
str = str_arr.join(' ');
|
654
|
+
return str;
|
655
|
+
};
|
656
|
+
}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: inflection-js-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-04-13 00:00:00.000000000Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: railties
|
16
|
-
requirement: &
|
16
|
+
requirement: &70147323175740 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -24,10 +24,10 @@ dependencies:
|
|
24
24
|
version: '5.0'
|
25
25
|
type: :runtime
|
26
26
|
prerelease: false
|
27
|
-
version_requirements: *
|
27
|
+
version_requirements: *70147323175740
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: thor
|
30
|
-
requirement: &
|
30
|
+
requirement: &70147323159900 !ruby/object:Gem::Requirement
|
31
31
|
none: false
|
32
32
|
requirements:
|
33
33
|
- - ~>
|
@@ -35,14 +35,27 @@ dependencies:
|
|
35
35
|
version: '0.14'
|
36
36
|
type: :runtime
|
37
37
|
prerelease: false
|
38
|
-
version_requirements: *
|
38
|
+
version_requirements: *70147323159900
|
39
39
|
description: This gem provides inflection-js assets for your Rails 3 application.
|
40
40
|
email:
|
41
41
|
- c00lryguy@gmail.com
|
42
42
|
executables: []
|
43
43
|
extensions: []
|
44
44
|
extra_rdoc_files: []
|
45
|
-
files:
|
45
|
+
files:
|
46
|
+
- .gitignore
|
47
|
+
- Gemfile
|
48
|
+
- Gemfile.lock
|
49
|
+
- LICENSE
|
50
|
+
- README.md
|
51
|
+
- Rakefile
|
52
|
+
- inflection-js-rails.gemspec
|
53
|
+
- lib/generators/inflectionjs/install/install_generator.rb
|
54
|
+
- lib/inflection-js-rails.rb
|
55
|
+
- lib/inflectionjs/rails.rb
|
56
|
+
- lib/inflectionjs/rails/engine.rb
|
57
|
+
- lib/inflectionjs/rails/version.rb
|
58
|
+
- vendor/assets/javascripts/inflection.js
|
46
59
|
homepage: http://rubygems.org/gems/inflection-js-rails
|
47
60
|
licenses: []
|
48
61
|
post_install_message:
|