rogue-girl-rails 0.0.1 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +21 -3
- data/lib/rogue/girl/rails/version.rb +1 -1
- data/vendor/assets/javascripts/rogue_girl.js +767 -62
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 44fc1aefb28157b905a1b76f6649155782e78a13
|
4
|
+
data.tar.gz: 4dec682c93b52a706f54f46016067d3f533b8e0f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5144618118181bbcebcdaa488f3f711b067542000d1f15b8727f280afb28dc042506960ed944ec483c6601f65fcb4e327384a72061dd4900bb012f569825dfc1
|
7
|
+
data.tar.gz: ede9a2f3144ea0c9b1c74d39100d89bb874f5fca5a310c1787d78dae7f71d41f2aa20b1e0fe3cf962c45171e2a12cb1f91e0be9541424eb452080899ff706583
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
#
|
1
|
+
# RogueGirl with Rails
|
2
2
|
|
3
|
-
|
3
|
+
[RogueGirl](https://github.com/smolnar/rogue-girl) is a factory for objects in JavaScript.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -18,7 +18,13 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
|
21
|
+
Just require library.
|
22
|
+
|
23
|
+
```coffeescript
|
24
|
+
#= require rogue_girl
|
25
|
+
```
|
26
|
+
|
27
|
+
For API, [see more](https://github.com/smolnar/rogue-girl).
|
22
28
|
|
23
29
|
## Contributing
|
24
30
|
|
@@ -27,3 +33,15 @@ TODO: Write usage instructions here
|
|
27
33
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
34
|
4. Push to the branch (`git push origin my-new-feature`)
|
29
35
|
5. Create a new Pull Request
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
The MIT License (MIT)
|
40
|
+
|
41
|
+
Copyright (c) 2013 Samuel Molnár
|
42
|
+
|
43
|
+
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:
|
44
|
+
|
45
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
46
|
+
|
47
|
+
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.
|
@@ -1,3 +1,661 @@
|
|
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
|
+
|
91
|
+
if (window && !window.InflectionJS)
|
92
|
+
{
|
93
|
+
window.InflectionJS = null;
|
94
|
+
}
|
95
|
+
|
96
|
+
/*
|
97
|
+
This sets up some constants for later use
|
98
|
+
This should use the window namespace variable if available
|
99
|
+
*/
|
100
|
+
InflectionJS =
|
101
|
+
{
|
102
|
+
/*
|
103
|
+
This is a list of nouns that use the same form for both singular and plural.
|
104
|
+
This list should remain entirely in lower case to correctly match Strings.
|
105
|
+
*/
|
106
|
+
uncountable_words: [
|
107
|
+
'equipment', 'information', 'rice', 'money', 'species', 'series',
|
108
|
+
'fish', 'sheep', 'moose', 'deer', 'news'
|
109
|
+
],
|
110
|
+
|
111
|
+
/*
|
112
|
+
These rules translate from the singular form of a noun to its plural form.
|
113
|
+
*/
|
114
|
+
plural_rules: [
|
115
|
+
[new RegExp('(m)an$', 'gi'), '$1en'],
|
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('(pe)ople$', 'gi'), '$1rson'],
|
143
|
+
[new RegExp('(child)ren$', 'gi'), '$1'],
|
144
|
+
[new RegExp('([ti])a$', 'gi'), '$1um'],
|
145
|
+
[new RegExp('((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$','gi'), '$1$2sis'],
|
146
|
+
[new RegExp('(hive)s$', 'gi'), '$1'],
|
147
|
+
[new RegExp('(tive)s$', 'gi'), '$1'],
|
148
|
+
[new RegExp('(curve)s$', 'gi'), '$1'],
|
149
|
+
[new RegExp('([lr])ves$', 'gi'), '$1f'],
|
150
|
+
[new RegExp('([^fo])ves$', 'gi'), '$1fe'],
|
151
|
+
[new RegExp('([^aeiouy]|qu)ies$', 'gi'), '$1y'],
|
152
|
+
[new RegExp('(s)eries$', 'gi'), '$1eries'],
|
153
|
+
[new RegExp('(m)ovies$', 'gi'), '$1ovie'],
|
154
|
+
[new RegExp('(x|ch|ss|sh)es$', 'gi'), '$1'],
|
155
|
+
[new RegExp('([m|l])ice$', 'gi'), '$1ouse'],
|
156
|
+
[new RegExp('(bus)es$', 'gi'), '$1'],
|
157
|
+
[new RegExp('(o)es$', 'gi'), '$1'],
|
158
|
+
[new RegExp('(shoe)s$', 'gi'), '$1'],
|
159
|
+
[new RegExp('(cris|ax|test)es$', 'gi'), '$1is'],
|
160
|
+
[new RegExp('(octop|vir)i$', 'gi'), '$1us'],
|
161
|
+
[new RegExp('(alias|status)es$', 'gi'), '$1'],
|
162
|
+
[new RegExp('^(ox)en', 'gi'), '$1'],
|
163
|
+
[new RegExp('(vert|ind)ices$', 'gi'), '$1ex'],
|
164
|
+
[new RegExp('(matr)ices$', 'gi'), '$1ix'],
|
165
|
+
[new RegExp('(quiz)zes$', 'gi'), '$1'],
|
166
|
+
[new RegExp('s$', 'gi'), '']
|
167
|
+
],
|
168
|
+
|
169
|
+
/*
|
170
|
+
This is a list of words that should not be capitalized for title case
|
171
|
+
*/
|
172
|
+
non_titlecased_words: [
|
173
|
+
'and', 'or', 'nor', 'a', 'an', 'the', 'so', 'but', 'to', 'of', 'at',
|
174
|
+
'by', 'from', 'into', 'on', 'onto', 'off', 'out', 'in', 'over',
|
175
|
+
'with', 'for'
|
176
|
+
],
|
177
|
+
|
178
|
+
/*
|
179
|
+
These are regular expressions used for converting between String formats
|
180
|
+
*/
|
181
|
+
id_suffix: new RegExp('(_ids|_id)$', 'g'),
|
182
|
+
underbar: new RegExp('_', 'g'),
|
183
|
+
space_or_underbar: new RegExp('[\ _]', 'g'),
|
184
|
+
uppercase: new RegExp('([A-Z])', 'g'),
|
185
|
+
underbar_prefix: new RegExp('^_'),
|
186
|
+
|
187
|
+
/*
|
188
|
+
This is a helper method that applies rules based replacement to a String
|
189
|
+
Signature:
|
190
|
+
InflectionJS.apply_rules(str, rules, skip, override) == String
|
191
|
+
Arguments:
|
192
|
+
str - String - String to modify and return based on the passed rules
|
193
|
+
rules - Array: [RegExp, String] - Regexp to match paired with String to use for replacement
|
194
|
+
skip - Array: [String] - Strings to skip if they match
|
195
|
+
override - String (optional) - String to return as though this method succeeded (used to conform to APIs)
|
196
|
+
Returns:
|
197
|
+
String - passed String modified by passed rules
|
198
|
+
Examples:
|
199
|
+
InflectionJS.apply_rules("cows", InflectionJs.singular_rules) === 'cow'
|
200
|
+
*/
|
201
|
+
apply_rules: function(str, rules, skip, override)
|
202
|
+
{
|
203
|
+
if (override)
|
204
|
+
{
|
205
|
+
str = override;
|
206
|
+
}
|
207
|
+
else
|
208
|
+
{
|
209
|
+
var ignore = (skip.indexOf(str.toLowerCase()) > -1);
|
210
|
+
if (!ignore)
|
211
|
+
{
|
212
|
+
for (var x = 0; x < rules.length; x++)
|
213
|
+
{
|
214
|
+
if (str.match(rules[x][0]))
|
215
|
+
{
|
216
|
+
str = str.replace(rules[x][0], rules[x][1]);
|
217
|
+
break;
|
218
|
+
}
|
219
|
+
}
|
220
|
+
}
|
221
|
+
}
|
222
|
+
return str;
|
223
|
+
}
|
224
|
+
};
|
225
|
+
|
226
|
+
/*
|
227
|
+
This lets us detect if an Array contains a given element
|
228
|
+
Signature:
|
229
|
+
Array.indexOf(item, fromIndex, compareFunc) == Integer
|
230
|
+
Arguments:
|
231
|
+
item - Object - object to locate in the Array
|
232
|
+
fromIndex - Integer (optional) - starts checking from this position in the Array
|
233
|
+
compareFunc - Function (optional) - function used to compare Array item vs passed item
|
234
|
+
Returns:
|
235
|
+
Integer - index position in the Array of the passed item
|
236
|
+
Examples:
|
237
|
+
['hi','there'].indexOf("guys") === -1
|
238
|
+
['hi','there'].indexOf("hi") === 0
|
239
|
+
*/
|
240
|
+
if (!Array.prototype.indexOf)
|
241
|
+
{
|
242
|
+
Array.prototype.indexOf = function(item, fromIndex, compareFunc)
|
243
|
+
{
|
244
|
+
if (!fromIndex)
|
245
|
+
{
|
246
|
+
fromIndex = -1;
|
247
|
+
}
|
248
|
+
var index = -1;
|
249
|
+
for (var i = fromIndex; i < this.length; i++)
|
250
|
+
{
|
251
|
+
if (this[i] === item || compareFunc && compareFunc(this[i], item))
|
252
|
+
{
|
253
|
+
index = i;
|
254
|
+
break;
|
255
|
+
}
|
256
|
+
}
|
257
|
+
return index;
|
258
|
+
};
|
259
|
+
}
|
260
|
+
|
261
|
+
/*
|
262
|
+
You can override this list for all Strings or just one depending on if you
|
263
|
+
set the new values on prototype or on a given String instance.
|
264
|
+
*/
|
265
|
+
if (!String.prototype._uncountable_words)
|
266
|
+
{
|
267
|
+
String.prototype._uncountable_words = InflectionJS.uncountable_words;
|
268
|
+
}
|
269
|
+
|
270
|
+
/*
|
271
|
+
You can override this list for all Strings or just one depending on if you
|
272
|
+
set the new values on prototype or on a given String instance.
|
273
|
+
*/
|
274
|
+
if (!String.prototype._plural_rules)
|
275
|
+
{
|
276
|
+
String.prototype._plural_rules = InflectionJS.plural_rules;
|
277
|
+
}
|
278
|
+
|
279
|
+
/*
|
280
|
+
You can override this list for all Strings or just one depending on if you
|
281
|
+
set the new values on prototype or on a given String instance.
|
282
|
+
*/
|
283
|
+
if (!String.prototype._singular_rules)
|
284
|
+
{
|
285
|
+
String.prototype._singular_rules = InflectionJS.singular_rules;
|
286
|
+
}
|
287
|
+
|
288
|
+
/*
|
289
|
+
You can override this list for all Strings or just one depending on if you
|
290
|
+
set the new values on prototype or on a given String instance.
|
291
|
+
*/
|
292
|
+
if (!String.prototype._non_titlecased_words)
|
293
|
+
{
|
294
|
+
String.prototype._non_titlecased_words = InflectionJS.non_titlecased_words;
|
295
|
+
}
|
296
|
+
|
297
|
+
/*
|
298
|
+
This function adds plurilization support to every String object
|
299
|
+
Signature:
|
300
|
+
String.pluralize(plural) == String
|
301
|
+
Arguments:
|
302
|
+
plural - String (optional) - overrides normal output with said String
|
303
|
+
Returns:
|
304
|
+
String - singular English language nouns are returned in plural form
|
305
|
+
Examples:
|
306
|
+
"person".pluralize() == "people"
|
307
|
+
"octopus".pluralize() == "octopi"
|
308
|
+
"Hat".pluralize() == "Hats"
|
309
|
+
"person".pluralize("guys") == "guys"
|
310
|
+
*/
|
311
|
+
if (!String.prototype.pluralize)
|
312
|
+
{
|
313
|
+
String.prototype.pluralize = function(plural)
|
314
|
+
{
|
315
|
+
return InflectionJS.apply_rules(
|
316
|
+
this,
|
317
|
+
this._plural_rules,
|
318
|
+
this._uncountable_words,
|
319
|
+
plural
|
320
|
+
);
|
321
|
+
};
|
322
|
+
}
|
323
|
+
|
324
|
+
/*
|
325
|
+
This function adds singularization support to every String object
|
326
|
+
Signature:
|
327
|
+
String.singularize(singular) == String
|
328
|
+
Arguments:
|
329
|
+
singular - String (optional) - overrides normal output with said String
|
330
|
+
Returns:
|
331
|
+
String - plural English language nouns are returned in singular form
|
332
|
+
Examples:
|
333
|
+
"people".singularize() == "person"
|
334
|
+
"octopi".singularize() == "octopus"
|
335
|
+
"Hats".singularize() == "Hat"
|
336
|
+
"guys".singularize("person") == "person"
|
337
|
+
*/
|
338
|
+
if (!String.prototype.singularize)
|
339
|
+
{
|
340
|
+
String.prototype.singularize = function(singular)
|
341
|
+
{
|
342
|
+
return InflectionJS.apply_rules(
|
343
|
+
this,
|
344
|
+
this._singular_rules,
|
345
|
+
this._uncountable_words,
|
346
|
+
singular
|
347
|
+
);
|
348
|
+
};
|
349
|
+
}
|
350
|
+
|
351
|
+
/*
|
352
|
+
This function adds camelization support to every String object
|
353
|
+
Signature:
|
354
|
+
String.camelize(lowFirstLetter) == String
|
355
|
+
Arguments:
|
356
|
+
lowFirstLetter - boolean (optional) - default is to capitalize the first
|
357
|
+
letter of the results... passing true will lowercase it
|
358
|
+
Returns:
|
359
|
+
String - lower case underscored words will be returned in camel case
|
360
|
+
additionally '/' is translated to '::'
|
361
|
+
Examples:
|
362
|
+
"message_properties".camelize() == "MessageProperties"
|
363
|
+
"message_properties".camelize(true) == "messageProperties"
|
364
|
+
*/
|
365
|
+
if (!String.prototype.camelize)
|
366
|
+
{
|
367
|
+
String.prototype.camelize = function(lowFirstLetter)
|
368
|
+
{
|
369
|
+
var str = this.toLowerCase();
|
370
|
+
var str_path = str.split('/');
|
371
|
+
for (var i = 0; i < str_path.length; i++)
|
372
|
+
{
|
373
|
+
var str_arr = str_path[i].split('_');
|
374
|
+
var initX = ((lowFirstLetter && i + 1 === str_path.length) ? (1) : (0));
|
375
|
+
for (var x = initX; x < str_arr.length; x++)
|
376
|
+
{
|
377
|
+
str_arr[x] = str_arr[x].charAt(0).toUpperCase() + str_arr[x].substring(1);
|
378
|
+
}
|
379
|
+
str_path[i] = str_arr.join('');
|
380
|
+
}
|
381
|
+
str = str_path.join('::');
|
382
|
+
return str;
|
383
|
+
};
|
384
|
+
}
|
385
|
+
|
386
|
+
/*
|
387
|
+
This function adds underscore support to every String object
|
388
|
+
Signature:
|
389
|
+
String.underscore() == String
|
390
|
+
Arguments:
|
391
|
+
N/A
|
392
|
+
Returns:
|
393
|
+
String - camel cased words are returned as lower cased and underscored
|
394
|
+
additionally '::' is translated to '/'
|
395
|
+
Examples:
|
396
|
+
"MessageProperties".camelize() == "message_properties"
|
397
|
+
"messageProperties".underscore() == "message_properties"
|
398
|
+
*/
|
399
|
+
if (!String.prototype.underscore)
|
400
|
+
{
|
401
|
+
String.prototype.underscore = function()
|
402
|
+
{
|
403
|
+
var str = this;
|
404
|
+
var str_path = str.split('::');
|
405
|
+
for (var i = 0; i < str_path.length; i++)
|
406
|
+
{
|
407
|
+
str_path[i] = str_path[i].replace(InflectionJS.uppercase, '_$1');
|
408
|
+
str_path[i] = str_path[i].replace(InflectionJS.underbar_prefix, '');
|
409
|
+
}
|
410
|
+
str = str_path.join('/').toLowerCase();
|
411
|
+
return str;
|
412
|
+
};
|
413
|
+
}
|
414
|
+
|
415
|
+
/*
|
416
|
+
This function adds humanize support to every String object
|
417
|
+
Signature:
|
418
|
+
String.humanize(lowFirstLetter) == String
|
419
|
+
Arguments:
|
420
|
+
lowFirstLetter - boolean (optional) - default is to capitalize the first
|
421
|
+
letter of the results... passing true will lowercase it
|
422
|
+
Returns:
|
423
|
+
String - lower case underscored words will be returned in humanized form
|
424
|
+
Examples:
|
425
|
+
"message_properties".humanize() == "Message properties"
|
426
|
+
"message_properties".humanize(true) == "message properties"
|
427
|
+
*/
|
428
|
+
if (!String.prototype.humanize)
|
429
|
+
{
|
430
|
+
String.prototype.humanize = function(lowFirstLetter)
|
431
|
+
{
|
432
|
+
var str = this.toLowerCase();
|
433
|
+
str = str.replace(InflectionJS.id_suffix, '');
|
434
|
+
str = str.replace(InflectionJS.underbar, ' ');
|
435
|
+
if (!lowFirstLetter)
|
436
|
+
{
|
437
|
+
str = str.capitalize();
|
438
|
+
}
|
439
|
+
return str;
|
440
|
+
};
|
441
|
+
}
|
442
|
+
|
443
|
+
/*
|
444
|
+
This function adds capitalization support to every String object
|
445
|
+
Signature:
|
446
|
+
String.capitalize() == String
|
447
|
+
Arguments:
|
448
|
+
N/A
|
449
|
+
Returns:
|
450
|
+
String - all characters will be lower case and the first will be upper
|
451
|
+
Examples:
|
452
|
+
"message_properties".capitalize() == "Message_properties"
|
453
|
+
"message properties".capitalize() == "Message properties"
|
454
|
+
*/
|
455
|
+
if (!String.prototype.capitalize)
|
456
|
+
{
|
457
|
+
String.prototype.capitalize = function()
|
458
|
+
{
|
459
|
+
var str = this.toLowerCase();
|
460
|
+
str = str.substring(0, 1).toUpperCase() + str.substring(1);
|
461
|
+
return str;
|
462
|
+
};
|
463
|
+
}
|
464
|
+
|
465
|
+
/*
|
466
|
+
This function adds dasherization support to every String object
|
467
|
+
Signature:
|
468
|
+
String.dasherize() == String
|
469
|
+
Arguments:
|
470
|
+
N/A
|
471
|
+
Returns:
|
472
|
+
String - replaces all spaces or underbars with dashes
|
473
|
+
Examples:
|
474
|
+
"message_properties".capitalize() == "message-properties"
|
475
|
+
"Message Properties".capitalize() == "Message-Properties"
|
476
|
+
*/
|
477
|
+
if (!String.prototype.dasherize)
|
478
|
+
{
|
479
|
+
String.prototype.dasherize = function()
|
480
|
+
{
|
481
|
+
var str = this;
|
482
|
+
str = str.replace(InflectionJS.space_or_underbar, '-');
|
483
|
+
return str;
|
484
|
+
};
|
485
|
+
}
|
486
|
+
|
487
|
+
/*
|
488
|
+
This function adds titleize support to every String object
|
489
|
+
Signature:
|
490
|
+
String.titleize() == String
|
491
|
+
Arguments:
|
492
|
+
N/A
|
493
|
+
Returns:
|
494
|
+
String - capitalizes words as you would for a book title
|
495
|
+
Examples:
|
496
|
+
"message_properties".titleize() == "Message Properties"
|
497
|
+
"message properties to keep".titleize() == "Message Properties to Keep"
|
498
|
+
*/
|
499
|
+
if (!String.prototype.titleize)
|
500
|
+
{
|
501
|
+
String.prototype.titleize = function()
|
502
|
+
{
|
503
|
+
var str = this.toLowerCase();
|
504
|
+
str = str.replace(InflectionJS.underbar, ' ');
|
505
|
+
var str_arr = str.split(' ');
|
506
|
+
for (var x = 0; x < str_arr.length; x++)
|
507
|
+
{
|
508
|
+
var d = str_arr[x].split('-');
|
509
|
+
for (var i = 0; i < d.length; i++)
|
510
|
+
{
|
511
|
+
if (this._non_titlecased_words.indexOf(d[i].toLowerCase()) < 0)
|
512
|
+
{
|
513
|
+
d[i] = d[i].capitalize();
|
514
|
+
}
|
515
|
+
}
|
516
|
+
str_arr[x] = d.join('-');
|
517
|
+
}
|
518
|
+
str = str_arr.join(' ');
|
519
|
+
str = str.substring(0, 1).toUpperCase() + str.substring(1);
|
520
|
+
return str;
|
521
|
+
};
|
522
|
+
}
|
523
|
+
|
524
|
+
/*
|
525
|
+
This function adds demodulize support to every String object
|
526
|
+
Signature:
|
527
|
+
String.demodulize() == String
|
528
|
+
Arguments:
|
529
|
+
N/A
|
530
|
+
Returns:
|
531
|
+
String - removes module names leaving only class names (Ruby style)
|
532
|
+
Examples:
|
533
|
+
"Message::Bus::Properties".demodulize() == "Properties"
|
534
|
+
*/
|
535
|
+
if (!String.prototype.demodulize)
|
536
|
+
{
|
537
|
+
String.prototype.demodulize = function()
|
538
|
+
{
|
539
|
+
var str = this;
|
540
|
+
var str_arr = str.split('::');
|
541
|
+
str = str_arr[str_arr.length - 1];
|
542
|
+
return str;
|
543
|
+
};
|
544
|
+
}
|
545
|
+
|
546
|
+
/*
|
547
|
+
This function adds tableize support to every String object
|
548
|
+
Signature:
|
549
|
+
String.tableize() == String
|
550
|
+
Arguments:
|
551
|
+
N/A
|
552
|
+
Returns:
|
553
|
+
String - renders camel cased words into their underscored plural form
|
554
|
+
Examples:
|
555
|
+
"MessageBusProperty".tableize() == "message_bus_properties"
|
556
|
+
*/
|
557
|
+
if (!String.prototype.tableize)
|
558
|
+
{
|
559
|
+
String.prototype.tableize = function()
|
560
|
+
{
|
561
|
+
var str = this;
|
562
|
+
str = str.underscore().pluralize();
|
563
|
+
return str;
|
564
|
+
};
|
565
|
+
}
|
566
|
+
|
567
|
+
/*
|
568
|
+
This function adds classification support to every String object
|
569
|
+
Signature:
|
570
|
+
String.classify() == String
|
571
|
+
Arguments:
|
572
|
+
N/A
|
573
|
+
Returns:
|
574
|
+
String - underscored plural nouns become the camel cased singular form
|
575
|
+
Examples:
|
576
|
+
"message_bus_properties".classify() == "MessageBusProperty"
|
577
|
+
*/
|
578
|
+
if (!String.prototype.classify)
|
579
|
+
{
|
580
|
+
String.prototype.classify = function()
|
581
|
+
{
|
582
|
+
var str = this;
|
583
|
+
str = str.camelize().singularize();
|
584
|
+
return str;
|
585
|
+
};
|
586
|
+
}
|
587
|
+
|
588
|
+
/*
|
589
|
+
This function adds foreign key support to every String object
|
590
|
+
Signature:
|
591
|
+
String.foreign_key(dropIdUbar) == String
|
592
|
+
Arguments:
|
593
|
+
dropIdUbar - boolean (optional) - default is to seperate id with an
|
594
|
+
underbar at the end of the class name, you can pass true to skip it
|
595
|
+
Returns:
|
596
|
+
String - camel cased singular class names become underscored with id
|
597
|
+
Examples:
|
598
|
+
"MessageBusProperty".foreign_key() == "message_bus_property_id"
|
599
|
+
"MessageBusProperty".foreign_key(true) == "message_bus_propertyid"
|
600
|
+
*/
|
601
|
+
if (!String.prototype.foreign_key)
|
602
|
+
{
|
603
|
+
String.prototype.foreign_key = function(dropIdUbar)
|
604
|
+
{
|
605
|
+
var str = this;
|
606
|
+
str = str.demodulize().underscore() + ((dropIdUbar) ? ('') : ('_')) + 'id';
|
607
|
+
return str;
|
608
|
+
};
|
609
|
+
}
|
610
|
+
|
611
|
+
/*
|
612
|
+
This function adds ordinalize support to every String object
|
613
|
+
Signature:
|
614
|
+
String.ordinalize() == String
|
615
|
+
Arguments:
|
616
|
+
N/A
|
617
|
+
Returns:
|
618
|
+
String - renders all found numbers their sequence like "22nd"
|
619
|
+
Examples:
|
620
|
+
"the 1 pitch".ordinalize() == "the 1st pitch"
|
621
|
+
*/
|
622
|
+
if (!String.prototype.ordinalize)
|
623
|
+
{
|
624
|
+
String.prototype.ordinalize = function()
|
625
|
+
{
|
626
|
+
var str = this;
|
627
|
+
var str_arr = str.split(' ');
|
628
|
+
for (var x = 0; x < str_arr.length; x++)
|
629
|
+
{
|
630
|
+
var i = parseInt(str_arr[x]);
|
631
|
+
if (i === NaN)
|
632
|
+
{
|
633
|
+
var ltd = str_arr[x].substring(str_arr[x].length - 2);
|
634
|
+
var ld = str_arr[x].substring(str_arr[x].length - 1);
|
635
|
+
var suf = "th";
|
636
|
+
if (ltd != "11" && ltd != "12" && ltd != "13")
|
637
|
+
{
|
638
|
+
if (ld === "1")
|
639
|
+
{
|
640
|
+
suf = "st";
|
641
|
+
}
|
642
|
+
else if (ld === "2")
|
643
|
+
{
|
644
|
+
suf = "nd";
|
645
|
+
}
|
646
|
+
else if (ld === "3")
|
647
|
+
{
|
648
|
+
suf = "rd";
|
649
|
+
}
|
650
|
+
}
|
651
|
+
str_arr[x] += suf;
|
652
|
+
}
|
653
|
+
}
|
654
|
+
str = str_arr.join(' ');
|
655
|
+
return str;
|
656
|
+
};
|
657
|
+
}
|
658
|
+
;
|
1
659
|
// TODO (smolnar) examine other global exports
|
2
660
|
exports = typeof(global) !== 'undefined' ? global : this
|
3
661
|
;
|
@@ -38,14 +696,12 @@ exports = typeof(global) !== 'undefined' ? global : this
|
|
38
696
|
|
39
697
|
VERSION.MAJOR = 0;
|
40
698
|
|
41
|
-
VERSION.MINOR =
|
699
|
+
VERSION.MINOR = 1;
|
42
700
|
|
43
701
|
VERSION.PATCH = 1;
|
44
702
|
|
45
|
-
VERSION.PRE = 'beta';
|
46
|
-
|
47
703
|
VERSION.STRING = function() {
|
48
|
-
return "" + RogueGirl.VERSION.MAJOR + "." + RogueGirl.VERSION.MINOR + "." + RogueGirl.VERSION.PATCH
|
704
|
+
return "" + RogueGirl.VERSION.MAJOR + "." + RogueGirl.VERSION.MINOR + "." + RogueGirl.VERSION.PATCH;
|
49
705
|
};
|
50
706
|
|
51
707
|
return VERSION;
|
@@ -68,10 +724,6 @@ exports = typeof(global) !== 'undefined' ? global : this
|
|
68
724
|
return record;
|
69
725
|
};
|
70
726
|
|
71
|
-
Factory.createAssociation = function() {
|
72
|
-
return RogueGirl.driver.associationFor.apply(null, arguments);
|
73
|
-
};
|
74
|
-
|
75
727
|
return Factory;
|
76
728
|
|
77
729
|
})();
|
@@ -82,19 +734,14 @@ exports = typeof(global) !== 'undefined' ? global : this
|
|
82
734
|
function Builder() {}
|
83
735
|
|
84
736
|
Builder.build = function() {
|
85
|
-
var attributes,
|
737
|
+
var attributes, name, params, traits, type;
|
86
738
|
params = RogueGirl.Parser.parse(arguments);
|
87
739
|
name = params.name;
|
88
740
|
type = params.type;
|
89
741
|
traits = params.traits;
|
90
742
|
attributes = params.attributes;
|
91
|
-
|
92
|
-
|
93
|
-
for (_i = 0, _len = callbacks.length; _i < _len; _i++) {
|
94
|
-
callback = callbacks[_i];
|
95
|
-
callback(record);
|
96
|
-
}
|
97
|
-
return record;
|
743
|
+
RogueGirl.Builder.populate(name, attributes, traits);
|
744
|
+
return RogueGirl.driver.build(type, attributes);
|
98
745
|
};
|
99
746
|
|
100
747
|
Builder.populate = function(name, attributes, traits) {
|
@@ -244,7 +891,7 @@ exports = typeof(global) !== 'undefined' ? global : this
|
|
244
891
|
if (!definition) {
|
245
892
|
throw new Error("There is no definition for '" + name + "'");
|
246
893
|
}
|
247
|
-
return this.attributes[name] = new RogueGirl.Association(definition.type, this.base.type, arguments);
|
894
|
+
return this.attributes[name] = new RogueGirl.Association(definition.name, definition.type, this.base.type, arguments);
|
248
895
|
};
|
249
896
|
|
250
897
|
return Proxy;
|
@@ -304,31 +951,33 @@ exports = typeof(global) !== 'undefined' ? global : this
|
|
304
951
|
}).call(this);
|
305
952
|
(function() {
|
306
953
|
RogueGirl.Association = (function() {
|
307
|
-
function Association(
|
308
|
-
this.
|
309
|
-
this.
|
954
|
+
function Association(name, parent, child, params) {
|
955
|
+
this.name = name;
|
956
|
+
this.parent = parent;
|
957
|
+
this.child = child;
|
310
958
|
this.params = params;
|
311
959
|
}
|
312
960
|
|
313
961
|
Association.prototype.build = function(attributes) {
|
314
|
-
var
|
315
|
-
|
316
|
-
if (attributes[this.
|
317
|
-
|
318
|
-
delete attributes[this.
|
962
|
+
var parent_id, record;
|
963
|
+
record = null;
|
964
|
+
if (attributes[this.name]) {
|
965
|
+
record = attributes[this.name];
|
966
|
+
delete attributes[this.name];
|
319
967
|
} else {
|
320
|
-
|
968
|
+
record = RogueGirl.Factory.create.apply(null, this.params);
|
321
969
|
}
|
322
|
-
parent_id =
|
970
|
+
parent_id = record.id != null ? record.id : typeof record.get === "function" ? record.get('id') : void 0;
|
323
971
|
if (parent_id == null) {
|
324
|
-
throw new Error("Could not resolve 'parent_id' for #" +
|
972
|
+
throw new Error("Could not resolve 'parent_id' for #" + record);
|
325
973
|
}
|
326
|
-
attributes[
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
974
|
+
return attributes[this.parent] = {
|
975
|
+
__association__: {
|
976
|
+
parent: this.parent,
|
977
|
+
child: this.child,
|
978
|
+
record: record
|
979
|
+
}
|
980
|
+
};
|
332
981
|
};
|
333
982
|
|
334
983
|
return Association;
|
@@ -337,7 +986,78 @@ exports = typeof(global) !== 'undefined' ? global : this
|
|
337
986
|
|
338
987
|
}).call(this);
|
339
988
|
(function() {
|
340
|
-
RogueGirl.
|
989
|
+
RogueGirl.AbstractDriver = (function() {
|
990
|
+
function AbstractDriver() {}
|
991
|
+
|
992
|
+
AbstractDriver.prototype.build = function() {
|
993
|
+
throw new Error();
|
994
|
+
};
|
995
|
+
|
996
|
+
AbstractDriver.prototype.save = function() {
|
997
|
+
throw new Error();
|
998
|
+
};
|
999
|
+
|
1000
|
+
AbstractDriver.prototype.extractAssociations = function(attributes) {
|
1001
|
+
var associations, name, value;
|
1002
|
+
associations = [];
|
1003
|
+
for (name in attributes) {
|
1004
|
+
value = attributes[name];
|
1005
|
+
if (value.__association__ != null) {
|
1006
|
+
associations.push(value.__association__);
|
1007
|
+
delete attributes[name];
|
1008
|
+
}
|
1009
|
+
}
|
1010
|
+
return associations;
|
1011
|
+
};
|
1012
|
+
|
1013
|
+
return AbstractDriver;
|
1014
|
+
|
1015
|
+
})();
|
1016
|
+
|
1017
|
+
}).call(this);
|
1018
|
+
(function() {
|
1019
|
+
var __hasProp = {}.hasOwnProperty,
|
1020
|
+
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
1021
|
+
|
1022
|
+
RogueGirl.DefaultDriver = (function(_super) {
|
1023
|
+
__extends(DefaultDriver, _super);
|
1024
|
+
|
1025
|
+
function DefaultDriver() {
|
1026
|
+
return DefaultDriver.__super__.constructor.apply(this, arguments);
|
1027
|
+
}
|
1028
|
+
|
1029
|
+
DefaultDriver.prototype.build = function(type, attributes) {
|
1030
|
+
var association, associations, record, relation, _base, _i, _len;
|
1031
|
+
associations = this.extractAssociations(attributes);
|
1032
|
+
record = attributes;
|
1033
|
+
for (_i = 0, _len = associations.length; _i < _len; _i++) {
|
1034
|
+
association = associations[_i];
|
1035
|
+
record[association.parent] = association.record;
|
1036
|
+
relation = association.child.pluralize();
|
1037
|
+
if ((_base = association.record)[relation] == null) {
|
1038
|
+
_base[relation] = [];
|
1039
|
+
}
|
1040
|
+
association.record[relation].push(record);
|
1041
|
+
}
|
1042
|
+
return record;
|
1043
|
+
};
|
1044
|
+
|
1045
|
+
DefaultDriver.prototype.save = function(record) {
|
1046
|
+
return record;
|
1047
|
+
};
|
1048
|
+
|
1049
|
+
return DefaultDriver;
|
1050
|
+
|
1051
|
+
})(RogueGirl.AbstractDriver);
|
1052
|
+
|
1053
|
+
}).call(this);
|
1054
|
+
(function() {
|
1055
|
+
var __hasProp = {}.hasOwnProperty,
|
1056
|
+
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
1057
|
+
|
1058
|
+
RogueGirl.EmberStoreDriver = (function(_super) {
|
1059
|
+
__extends(EmberStoreDriver, _super);
|
1060
|
+
|
341
1061
|
EmberStoreDriver.prototype.app = null;
|
342
1062
|
|
343
1063
|
EmberStoreDriver.prototype.store = null;
|
@@ -354,17 +1074,19 @@ exports = typeof(global) !== 'undefined' ? global : this
|
|
354
1074
|
}
|
355
1075
|
|
356
1076
|
EmberStoreDriver.prototype.build = function(type, attributes) {
|
1077
|
+
var associations;
|
1078
|
+
associations = this.extractAssociations(attributes);
|
357
1079
|
return Ember.run((function(_this) {
|
358
1080
|
return function() {
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
return
|
1081
|
+
var association, record, relation, _i, _len;
|
1082
|
+
record = _this.store.createRecord(type, attributes);
|
1083
|
+
for (_i = 0, _len = associations.length; _i < _len; _i++) {
|
1084
|
+
association = associations[_i];
|
1085
|
+
record.set(association.parent, association.record);
|
1086
|
+
relation = association.child.pluralize();
|
1087
|
+
association.record.get(relation).pushObject(record);
|
1088
|
+
}
|
1089
|
+
return record;
|
368
1090
|
};
|
369
1091
|
})(this));
|
370
1092
|
};
|
@@ -378,26 +1100,9 @@ exports = typeof(global) !== 'undefined' ? global : this
|
|
378
1100
|
return record;
|
379
1101
|
};
|
380
1102
|
|
381
|
-
EmberStoreDriver.prototype.translateAssociation = function(relation) {
|
382
|
-
return "" + relation + "Id";
|
383
|
-
};
|
384
|
-
|
385
|
-
EmberStoreDriver.prototype.createAssociation = function(parent, child, target) {
|
386
|
-
return Ember.run((function(_this) {
|
387
|
-
return function() {
|
388
|
-
var relation;
|
389
|
-
relation = Ember.Inflector.inflector.pluralize(target);
|
390
|
-
if (!parent.get(relation)) {
|
391
|
-
throw new Error("Did you specify relation hasMany " + relation + " in " + (parent.constructor.toString()) + "?");
|
392
|
-
}
|
393
|
-
return parent.get(relation).pushObject(child);
|
394
|
-
};
|
395
|
-
})(this));
|
396
|
-
};
|
397
|
-
|
398
1103
|
return EmberStoreDriver;
|
399
1104
|
|
400
|
-
})();
|
1105
|
+
})(RogueGirl.AbstractDriver);
|
401
1106
|
|
402
1107
|
}).call(this);
|
403
1108
|
(function() {
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rogue-girl-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Molnar
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|