alt159-rails 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/alt159-rails/version.rb +1 -1
- data/vendor/assets/javascripts/alt159/Cakefile +18 -0
- data/vendor/assets/javascripts/alt159/README.md +1 -0
- data/vendor/assets/javascripts/alt159/SpecRunner.html +56 -0
- data/vendor/assets/javascripts/alt159/index.html +196 -0
- data/vendor/assets/javascripts/alt159/lib/jasmine-1.1.0/MIT.LICENSE +20 -0
- data/vendor/assets/javascripts/alt159/lib/jasmine-1.1.0/jasmine-html.js +190 -0
- data/vendor/assets/javascripts/alt159/lib/jasmine-1.1.0/jasmine.css +166 -0
- data/vendor/assets/javascripts/alt159/lib/jasmine-1.1.0/jasmine.js +2476 -0
- data/vendor/assets/javascripts/alt159/lib/jasmine-1.1.0/jasmine_favicon.png +0 -0
- data/vendor/assets/javascripts/alt159/spec/DateSpec.js +11 -0
- data/vendor/assets/javascripts/alt159/spec/LagniappeSpec.js +49 -0
- data/vendor/assets/javascripts/alt159/spec/NumberSpec.js +79 -0
- data/vendor/assets/javascripts/alt159/spec/SpecHelper.js +2 -0
- data/vendor/assets/javascripts/alt159/spec/StringySpec.js +181 -0
- data/vendor/assets/javascripts/alt159/src/ALT159.coffee +39 -0
- data/vendor/assets/javascripts/alt159/src/ALT159.js +360 -0
- data/vendor/assets/javascripts/alt159/src/types/datey.coffee +1 -0
- data/vendor/assets/javascripts/alt159/src/types/langniappe.coffee +29 -0
- data/vendor/assets/javascripts/alt159/src/types/numbery.coffee +11 -0
- data/vendor/assets/javascripts/alt159/src/types/stringy.coffee +181 -0
- metadata +23 -3
@@ -0,0 +1 @@
|
|
1
|
+
Datey = ->
|
@@ -0,0 +1,29 @@
|
|
1
|
+
Lagniappe = ->
|
2
|
+
|
3
|
+
Lagniappe:: =
|
4
|
+
|
5
|
+
extendPrototypes: ->
|
6
|
+
addFunction = (obj, func, key) ->
|
7
|
+
obj::[key] = ->
|
8
|
+
func.apply
|
9
|
+
value: this
|
10
|
+
, arguments
|
11
|
+
unnicer = (obj, to_add) ->
|
12
|
+
for key of to_add::
|
13
|
+
addFunction obj, to_add::[key], key unless obj::[key]
|
14
|
+
unnicer String, Stringy
|
15
|
+
unnicer Number, Numbery
|
16
|
+
|
17
|
+
#Adds ALT159 functions to this Instance of an object
|
18
|
+
chain: (value, type) ->
|
19
|
+
f().extendPrototypes()
|
20
|
+
value
|
21
|
+
|
22
|
+
reloadStylesheets: ->
|
23
|
+
queryString = "?reload=" + new Date().getTime()
|
24
|
+
links = document.getElementsByTagName("link")
|
25
|
+
i = 0
|
26
|
+
while i < links.length
|
27
|
+
links[i].href = links[i].href.replace(/\?.*|$/, queryString) if links[i] and links[i].ref is "stylesheet"
|
28
|
+
i++
|
29
|
+
true
|
@@ -0,0 +1,181 @@
|
|
1
|
+
rules = {
|
2
|
+
plural : []
|
3
|
+
singular : []
|
4
|
+
irregular : []
|
5
|
+
uncountable : []
|
6
|
+
}
|
7
|
+
|
8
|
+
inflect = {
|
9
|
+
plural : (matcher, suffix )-> rules.plural.push( [matcher, suffix] )
|
10
|
+
singular : (matcher, suffix )-> rules.singular.push( [matcher, suffix] )
|
11
|
+
irregular : (matcher, suffix )-> rules.irregular.push( [matcher, suffix] )
|
12
|
+
uncountable : (words) -> rules.uncountable = words
|
13
|
+
}
|
14
|
+
|
15
|
+
# stollen shamelessly from rails source
|
16
|
+
inflect.plural(/$/, 's')
|
17
|
+
inflect.plural(/s$/i, 's')
|
18
|
+
inflect.plural(/^(ax|test)is$/i, '$1es')
|
19
|
+
inflect.plural(/(octop|vir)us$/i, '$1i')
|
20
|
+
inflect.plural(/(octop|vir)i$/i, '$1i')
|
21
|
+
inflect.plural(/(alias|status)$/i, '$1es')
|
22
|
+
inflect.plural(/(bu)s$/i, '$1ses')
|
23
|
+
inflect.plural(/(buffal|tomat)o$/i, '$1oes')
|
24
|
+
inflect.plural(/([ti])um$/i, '$1a')
|
25
|
+
inflect.plural(/([ti])a$/i, '$1a')
|
26
|
+
inflect.plural(/sis$/i, 'ses')
|
27
|
+
inflect.plural(/(?:([^f])fe|([lr])f)$/i, '$1$2ves')
|
28
|
+
inflect.plural(/(hive)$/i, '$1s')
|
29
|
+
inflect.plural(/([^aeiouy]|qu)y$/i, '$1ies')
|
30
|
+
inflect.plural(/(x|ch|ss|sh)$/i, '$1es')
|
31
|
+
inflect.plural(/(matr|vert|ind)(?:ix|ex)$/i, '$1ices')
|
32
|
+
inflect.plural(/(m|l)ouse$/i, '$1ice')
|
33
|
+
inflect.plural(/(m|l)ice$/i, '$1ice')
|
34
|
+
inflect.plural(/^(ox)$/i, '$1en')
|
35
|
+
inflect.plural(/^(oxen)$/i, '$1')
|
36
|
+
inflect.plural(/(quiz)$/i, '$1zes')
|
37
|
+
inflect.singular(/s$/i, '')
|
38
|
+
inflect.singular(/(ss)$/i, '$1')
|
39
|
+
inflect.singular(/(n)ews$/i, '$1ews')
|
40
|
+
inflect.singular(/([ti])a$/i, '$1um')
|
41
|
+
inflect.singular(/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)(sis|ses)$/i, '$1$2sis')
|
42
|
+
inflect.singular(/(^analy)(sis|ses)$/i, '$1sis')
|
43
|
+
inflect.singular(/([^f])ves$/i, '$1fe')
|
44
|
+
inflect.singular(/(hive)s$/i, '$1')
|
45
|
+
inflect.singular(/(tive)s$/i, '$1')
|
46
|
+
inflect.singular(/([lr])ves$/i, '$1f')
|
47
|
+
inflect.singular(/([^aeiouy]|qu)ies$/i, '$1y')
|
48
|
+
inflect.singular(/(s)eries$/i, '$1eries')
|
49
|
+
inflect.singular(/(m)ovies$/i, '$1ovie')
|
50
|
+
inflect.singular(/(x|ch|ss|sh)es$/i, '$1')
|
51
|
+
inflect.singular(/(m|l)ice$/i, '$1ouse')
|
52
|
+
inflect.singular(/(bus)(es)?$/i, '$1')
|
53
|
+
inflect.singular(/(o)es$/i, '$1')
|
54
|
+
inflect.singular(/(shoe)s$/i, '$1')
|
55
|
+
inflect.singular(/(cris|test)(is|es)$/i, '$1is')
|
56
|
+
inflect.singular(/^(a)x[ie]s$/i, '$1xis')
|
57
|
+
inflect.singular(/(octop|vir)(us|i)$/i, '$1us')
|
58
|
+
inflect.singular(/(alias|status)(es)?$/i, '$1')
|
59
|
+
inflect.singular(/^(ox)en/i, '$1')
|
60
|
+
inflect.singular(/(vert|ind)ices$/i, '$1ex')
|
61
|
+
inflect.singular(/(matr)ices$/i, '$1ix')
|
62
|
+
inflect.singular(/(quiz)zes$/i, '$1')
|
63
|
+
inflect.singular(/(database)s$/i, '$1')
|
64
|
+
inflect.irregular('person', 'people')
|
65
|
+
inflect.irregular('man', 'men')
|
66
|
+
inflect.irregular('woman', 'women')
|
67
|
+
inflect.irregular('child', 'children')
|
68
|
+
inflect.irregular('sex', 'sexes')
|
69
|
+
inflect.irregular('move', 'moves')
|
70
|
+
inflect.irregular('cow', 'kine')
|
71
|
+
inflect.irregular('zombie', 'zombies')
|
72
|
+
inflect.uncountable(['equipment','information','rice','money','species','series','fish','sheep','jeans','bacon'])
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
Stringy = (obj) ->
|
78
|
+
@value = obj
|
79
|
+
|
80
|
+
Stringy:: =
|
81
|
+
capitalize: ->
|
82
|
+
return @value if(@value is '')
|
83
|
+
lowerCased = @value.toLowerCase()
|
84
|
+
word = lowerCased[0].toUpperCase() + lowerCased.substring(1)
|
85
|
+
return word
|
86
|
+
|
87
|
+
# Returns only the numbers out of a string
|
88
|
+
numbers: ->
|
89
|
+
parseFloat(@value.replace(/[^0-9.-]+/g, ""))
|
90
|
+
#return isNaN(n) ? null : n
|
91
|
+
|
92
|
+
underscore: ->
|
93
|
+
underscored = []
|
94
|
+
for ch of @value.split("")
|
95
|
+
underscored.push "_" if ch isnt 0 and @value[ch].match(/[A-Z|\s]/)
|
96
|
+
underscored.push @value[ch].toLowerCase() unless @value[ch].match(/\s/)
|
97
|
+
underscored = underscored.join ""
|
98
|
+
underscored.replace(/^_?/,"")
|
99
|
+
|
100
|
+
camel: ->
|
101
|
+
f(f(@value).underscore()).titleize().replace(RegExp(" ","g"), "")
|
102
|
+
|
103
|
+
humanize: ->
|
104
|
+
humanized = []
|
105
|
+
for ch of @value.split("")
|
106
|
+
humanized.push "_" if ch isnt 0 and @value[ch].match(/[A-Z]/)
|
107
|
+
humanized.push @value[ch] unless @value[ch].match(/\-/)
|
108
|
+
humanized = humanized.join("").split("_")
|
109
|
+
humanized[0] = f(humanized[0]).capitalize()
|
110
|
+
humanized.join(" ").trim()
|
111
|
+
|
112
|
+
pluralize: ->
|
113
|
+
return @value if rules.uncountable.indexOf(@value) > 0
|
114
|
+
i = rules.irregular.length
|
115
|
+
while i > 0
|
116
|
+
r = rules.irregular[i - 1]
|
117
|
+
return r[1] if @value is r[0]
|
118
|
+
i--
|
119
|
+
i = rules.plural.length
|
120
|
+
while i > 0
|
121
|
+
r = rules.plural[i - 1]
|
122
|
+
return @value.replace(r[0], r[1]) if @value.match(r[0])
|
123
|
+
i--
|
124
|
+
|
125
|
+
singularize: ->
|
126
|
+
return @value if rules.uncountable.indexOf(@value) > 0
|
127
|
+
i = rules.irregular.length
|
128
|
+
while i > 0
|
129
|
+
r = rules.irregular[i - 1]
|
130
|
+
return r[0] if @value is r[1]
|
131
|
+
i--
|
132
|
+
i = rules.singular.length
|
133
|
+
while i > 0
|
134
|
+
r = rules.singular[i - 1]
|
135
|
+
return @value.replace(r[0], r[1]) if @value.match(r[0])
|
136
|
+
i--
|
137
|
+
|
138
|
+
money: (options) ->
|
139
|
+
options or (options = {})
|
140
|
+
defaults =
|
141
|
+
precision: 2
|
142
|
+
symbol: "$"
|
143
|
+
dot: "."
|
144
|
+
seperator: ","
|
145
|
+
default: "-"
|
146
|
+
for prop of defaults
|
147
|
+
(options[prop] isnt undefined) or (options[prop] = defaults[prop])
|
148
|
+
unless @value
|
149
|
+
options.defaults
|
150
|
+
else
|
151
|
+
val = parseFloat(@value)
|
152
|
+
sign = (if val < 0 then "-" else "")
|
153
|
+
i = parseInt(val = Math.abs(+val or 0).toFixed(options.precision)) + ""
|
154
|
+
j = (if (j = i.length) > 3 then j % 3 else 0)
|
155
|
+
first = (sign + options.symbol + (if j then i.substr(0, j) + options.seperator else ""))
|
156
|
+
middle = i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + options.seperator)
|
157
|
+
last = (if options.precision then options.dot + Math.abs(val - i).toFixed(options.precision).slice(2) else "")
|
158
|
+
first + middle + last
|
159
|
+
|
160
|
+
number: (opts) ->
|
161
|
+
opts = opts or {}
|
162
|
+
opts.symbol = ""
|
163
|
+
f(@value).money opts
|
164
|
+
|
165
|
+
titleize: ->
|
166
|
+
parts = @value.split RegExp('[ _]')
|
167
|
+
parts = (f(word).capitalize() for word in parts)
|
168
|
+
parts.join " "
|
169
|
+
|
170
|
+
isBlank: ->
|
171
|
+
clean = @value || ""
|
172
|
+
clean = clean.replace RegExp(' ','g'), ""
|
173
|
+
clean is ""
|
174
|
+
|
175
|
+
truncate: (amount, tail="...")->
|
176
|
+
parts = []
|
177
|
+
parts = (str for str in @value when _i < amount)
|
178
|
+
parts.join("") + tail
|
179
|
+
|
180
|
+
|
181
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: alt159-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-03-10 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
16
|
-
requirement: &
|
16
|
+
requirement: &70366693168660 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: '3.2'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70366693168660
|
25
25
|
description: Easily Add ALT159 to a rails app
|
26
26
|
email:
|
27
27
|
- micahwoods@gmail.com
|
@@ -29,6 +29,26 @@ executables: []
|
|
29
29
|
extensions: []
|
30
30
|
extra_rdoc_files: []
|
31
31
|
files:
|
32
|
+
- vendor/assets/javascripts/alt159/Cakefile
|
33
|
+
- vendor/assets/javascripts/alt159/index.html
|
34
|
+
- vendor/assets/javascripts/alt159/lib/jasmine-1.1.0/jasmine-html.js
|
35
|
+
- vendor/assets/javascripts/alt159/lib/jasmine-1.1.0/jasmine.css
|
36
|
+
- vendor/assets/javascripts/alt159/lib/jasmine-1.1.0/jasmine.js
|
37
|
+
- vendor/assets/javascripts/alt159/lib/jasmine-1.1.0/jasmine_favicon.png
|
38
|
+
- vendor/assets/javascripts/alt159/lib/jasmine-1.1.0/MIT.LICENSE
|
39
|
+
- vendor/assets/javascripts/alt159/README.md
|
40
|
+
- vendor/assets/javascripts/alt159/spec/DateSpec.js
|
41
|
+
- vendor/assets/javascripts/alt159/spec/LagniappeSpec.js
|
42
|
+
- vendor/assets/javascripts/alt159/spec/NumberSpec.js
|
43
|
+
- vendor/assets/javascripts/alt159/spec/SpecHelper.js
|
44
|
+
- vendor/assets/javascripts/alt159/spec/StringySpec.js
|
45
|
+
- vendor/assets/javascripts/alt159/SpecRunner.html
|
46
|
+
- vendor/assets/javascripts/alt159/src/ALT159.coffee
|
47
|
+
- vendor/assets/javascripts/alt159/src/ALT159.js
|
48
|
+
- vendor/assets/javascripts/alt159/src/types/datey.coffee
|
49
|
+
- vendor/assets/javascripts/alt159/src/types/langniappe.coffee
|
50
|
+
- vendor/assets/javascripts/alt159/src/types/numbery.coffee
|
51
|
+
- vendor/assets/javascripts/alt159/src/types/stringy.coffee
|
32
52
|
- vendor/assets/javascripts/ALT159.js.coffee
|
33
53
|
- lib/alt159-rails/version.rb
|
34
54
|
- lib/alt159-rails.rb
|