ultimate-helpers 0.1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +8 -0
- data/.rvmrc +1 -0
- data/.rvmrc.example +1 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +126 -0
- data/LICENSE +19 -0
- data/README.md +25 -0
- data/Rakefile +1 -0
- data/app/assets/javascripts/ultimate/base.js.coffee +11 -0
- data/app/assets/javascripts/ultimate/helpers/asset_tag.js.coffee +82 -0
- data/app/assets/javascripts/ultimate/helpers/base.js.coffee +3 -0
- data/app/assets/javascripts/ultimate/helpers/decor.js.coffee +19 -0
- data/app/assets/javascripts/ultimate/helpers/form_options.js.coffee +106 -0
- data/app/assets/javascripts/ultimate/helpers/form_tag.js.coffee +175 -0
- data/app/assets/javascripts/ultimate/helpers/javascript.js.coffee +31 -0
- data/app/assets/javascripts/ultimate/helpers/number.js.coffee +600 -0
- data/app/assets/javascripts/ultimate/helpers/record_tag.js.coffee +81 -0
- data/app/assets/javascripts/ultimate/helpers/tag.js.coffee +91 -0
- data/app/assets/javascripts/ultimate/helpers/url.js.coffee +152 -0
- data/app/assets/javascripts/ultimate/helpers.js.coffee +122 -0
- data/app/assets/javascripts/ultimate/jquery.base.js.coffee +85 -0
- data/app/assets/javascripts/ultimate/underscore/underscore.inflection.js +176 -0
- data/app/assets/javascripts/ultimate/underscore/underscore.js +1204 -0
- data/app/assets/javascripts/ultimate/underscore/underscore.outcasts.js.coffee +158 -0
- data/app/assets/javascripts/ultimate/underscore/underscore.string.js +600 -0
- data/config/routes.rb +2 -0
- data/lib/ultimate/helpers/engine.rb +7 -0
- data/lib/ultimate/helpers/version.rb +5 -0
- data/lib/ultimate/helpers.rb +8 -0
- data/scripts/rails +8 -0
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/_emfile +18 -0
- data/test/dummy/app/assets/images/.gitkeep +0 -0
- data/test/dummy/app/assets/javascripts/application.js +3 -0
- data/test/dummy/app/assets/stylesheets/application.css +13 -0
- data/test/dummy/app/assets/stylesheets/global/forms.css.scss +65 -0
- data/test/dummy/app/assets/stylesheets/global/layout/footer.scss +18 -0
- data/test/dummy/app/assets/stylesheets/global/layout/header.scss +13 -0
- data/test/dummy/app/assets/stylesheets/global/layout/main-menu.scss +68 -0
- data/test/dummy/app/assets/stylesheets/global/layout.css.scss +46 -0
- data/test/dummy/app/assets/stylesheets/global/reserved.css.scss +79 -0
- data/test/dummy/app/assets/stylesheets/global/reset.css.scss +85 -0
- data/test/dummy/app/assets/stylesheets/global/structures.css.scss +9 -0
- data/test/dummy/app/assets/stylesheets/import/base.scss +36 -0
- data/test/dummy/app/assets/stylesheets/plugins/qunit.css.scss +3 -0
- data/test/dummy/app/controllers/application_controller.rb +4 -0
- data/test/dummy/app/controllers/main_controller.rb +8 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/mailers/.gitkeep +0 -0
- data/test/dummy/app/models/.gitkeep +0 -0
- data/test/dummy/app/views/application/_footer.html.haml +3 -0
- data/test/dummy/app/views/application/_header.html.haml +4 -0
- data/test/dummy/app/views/application/_main_menu.html.haml +11 -0
- data/test/dummy/app/views/layouts/application.html.haml +24 -0
- data/test/dummy/app/views/main/index.html.haml +13 -0
- data/test/dummy/app/views/main/qunit.html.haml +7 -0
- data/test/dummy/config/application.rb +58 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +40 -0
- data/test/dummy/config/environments/production.rb +67 -0
- data/test/dummy/config/environments/test.rb +37 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/inflections.rb +15 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/qunit-rails.rb +1 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +5 -0
- data/test/dummy/config/routes.rb +63 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/log/.gitkeep +0 -0
- data/test/dummy/public/404.html +26 -0
- data/test/dummy/public/422.html +26 -0
- data/test/dummy/public/500.html +25 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +6 -0
- data/test/javascripts/all_tests.js.coffee +12 -0
- data/test/javascripts/test_helper.js.coffee +3 -0
- data/test/javascripts/tests/helpers/asset_tag_test.js.coffee +51 -0
- data/test/javascripts/tests/helpers/form_options_test.js.coffee +170 -0
- data/test/javascripts/tests/helpers/form_tag_test.js.coffee +226 -0
- data/test/javascripts/tests/helpers/javascript_test.js.coffee +25 -0
- data/test/javascripts/tests/helpers/number_test.js.coffee +250 -0
- data/test/javascripts/tests/helpers/record_tag_test.js.coffee +60 -0
- data/test/javascripts/tests/helpers/tag_test.js.coffee +58 -0
- data/test/javascripts/tests/helpers/url_test.js.coffee +76 -0
- data/test/javascripts/tests/underscore/underscore.outcasts.test.js.coffee +47 -0
- data/test/javascripts/vendors/backbone.js +1533 -0
- data/test/javascripts/vendors/i18n-lite.js.coffee +20 -0
- data/test/stylesheets/test_helper.css +4 -0
- data/test/stylesheets/vendors/ultimate/mixins/_routines.scss +120 -0
- data/test/stylesheets/vendors/ultimate/mixins/_vendors.scss +44 -0
- data/test/stylesheets/vendors/ultimate/mixins/css3/_text-shadow.scss +40 -0
- data/test/stylesheets/vendors/ultimate/mixins/css3.scss +350 -0
- data/test/stylesheets/vendors/ultimate/mixins/fonts.scss +100 -0
- data/test/stylesheets/vendors/ultimate/mixins/microstructures.scss +239 -0
- data/ultimate-helpers.gemspec +25 -0
- metadata +193 -0
@@ -0,0 +1,158 @@
|
|
1
|
+
###
|
2
|
+
Underscore.outcasts
|
3
|
+
(c) 2012 Dmitry Karpunin <koderfunk aet gmail dot com>
|
4
|
+
Underscore.outcasts is freely distributable under the terms of the MIT license.
|
5
|
+
Documentation: https://github.com/KODerFunk/underscore.outcasts
|
6
|
+
Some code is borrowed from outcasts pull requests to Underscore.
|
7
|
+
Version '0.1.4'
|
8
|
+
###
|
9
|
+
|
10
|
+
'use strict'
|
11
|
+
|
12
|
+
|
13
|
+
|
14
|
+
# Defining underscore.outcasts
|
15
|
+
|
16
|
+
UnderscoreOutcasts =
|
17
|
+
|
18
|
+
VERSION: '0.1.4'
|
19
|
+
|
20
|
+
delete: (object, key) ->
|
21
|
+
value = object[key]
|
22
|
+
delete object[key]
|
23
|
+
value
|
24
|
+
|
25
|
+
blockGiven: (args) ->
|
26
|
+
block = _.last(args)
|
27
|
+
if _.isFunction(block) then block else null
|
28
|
+
|
29
|
+
sortHash: (hash, byValue = false) ->
|
30
|
+
_.sortBy(_.map(hash, (value, key) -> [key, value]), (pair) -> pair[if byValue then 1 else 0])
|
31
|
+
|
32
|
+
regexpValidKey: /^[\w\-]+$/
|
33
|
+
|
34
|
+
invert: (object) ->
|
35
|
+
result = {}
|
36
|
+
for key, value of object
|
37
|
+
if _.isArray(value)
|
38
|
+
for newKey in value when UnderscoreOutcasts.regexpValidKey.test(newKey)
|
39
|
+
result[newKey] = key
|
40
|
+
else if UnderscoreOutcasts.regexpValidKey.test(value)
|
41
|
+
if _.has(result, value)
|
42
|
+
if _.isArray(result[value])
|
43
|
+
result[value].push key
|
44
|
+
else
|
45
|
+
result[value] = [result[value], key]
|
46
|
+
else
|
47
|
+
result[value] = key
|
48
|
+
result
|
49
|
+
|
50
|
+
scan: (str, pattern) ->
|
51
|
+
block = @blockGiven(arguments)
|
52
|
+
result = []
|
53
|
+
while str.length
|
54
|
+
matches = str.match(pattern)
|
55
|
+
if matches
|
56
|
+
cut = matches.shift()
|
57
|
+
str = str.slice(matches.index + cut.length)
|
58
|
+
result.push if block
|
59
|
+
if matches.length then block(matches...) else block(cut)
|
60
|
+
else
|
61
|
+
if matches.length then matches else cut
|
62
|
+
else
|
63
|
+
str = ''
|
64
|
+
result
|
65
|
+
|
66
|
+
arrayWrap: (object) ->
|
67
|
+
unless object?
|
68
|
+
[]
|
69
|
+
else if _.isArray(object)
|
70
|
+
object
|
71
|
+
else if _.isFunction(object.toArray)
|
72
|
+
object.toArray() or [object]
|
73
|
+
else
|
74
|
+
[object]
|
75
|
+
|
76
|
+
# http://coderwall.com/p/krcdig
|
77
|
+
deepBindAll: (obj) ->
|
78
|
+
target = _.last(arguments)
|
79
|
+
for key, value of obj
|
80
|
+
if _.isFunction(value)
|
81
|
+
obj[key] = _.bind(value, target)
|
82
|
+
else if _.isObject(value)
|
83
|
+
obj[key] = _.deepBindAll(value, target)
|
84
|
+
obj
|
85
|
+
|
86
|
+
###
|
87
|
+
Split array into slices of <number> elements.
|
88
|
+
Map result by iterator if last given.
|
89
|
+
|
90
|
+
>>> eachSlice [1..10], 3, (a) -> cout a
|
91
|
+
[1, 2, 3]
|
92
|
+
[4, 5, 6]
|
93
|
+
[7, 8, 9]
|
94
|
+
[10]
|
95
|
+
###
|
96
|
+
eachSlice: (array, number) ->
|
97
|
+
size = array.length
|
98
|
+
index = 0
|
99
|
+
slices = []
|
100
|
+
while index < size
|
101
|
+
nextIndex = index + number
|
102
|
+
slices.push array.slice(index, nextIndex)
|
103
|
+
index = nextIndex
|
104
|
+
if block = @blockGiven(arguments) then _.map(slices, block) else slices
|
105
|
+
|
106
|
+
###
|
107
|
+
Splits or iterates over the array in groups of size +number+,
|
108
|
+
padding any remaining slots with +fill_with+ unless it is +false+.
|
109
|
+
|
110
|
+
>>> inGroupsOf [1..7], 3, (group) -> cout group
|
111
|
+
[1, 2, 3]
|
112
|
+
[4, 5, 6]
|
113
|
+
[7, null, null]
|
114
|
+
|
115
|
+
>>> inGroupsOf [1..3], 2, ' ', (group) -> cout group
|
116
|
+
[1, 2]
|
117
|
+
[3, " "]
|
118
|
+
|
119
|
+
>>> inGroupsOf [1..3], 2, false, (group) -> cout group
|
120
|
+
[1, 2]
|
121
|
+
[3]
|
122
|
+
###
|
123
|
+
inGroupsOf: (array, number, fillWith = null) ->
|
124
|
+
return array if number < 1
|
125
|
+
unless fillWith is false
|
126
|
+
# size % number gives how many extra we have;
|
127
|
+
# subtracting from number gives how many to add;
|
128
|
+
# modulo number ensures we don't add group of just fill.
|
129
|
+
padding = (number - array.length % number) % number
|
130
|
+
if padding
|
131
|
+
fillWith = null if _.isFunction(fillWith)
|
132
|
+
array = array.slice()
|
133
|
+
array.push(fillWith) while padding-- > 0
|
134
|
+
@eachSlice array, number, @blockGiven(arguments)
|
135
|
+
|
136
|
+
exports: ->
|
137
|
+
result = {}
|
138
|
+
for prop of @
|
139
|
+
continue if not @hasOwnProperty(prop) or prop.match(/^(?:include|contains|reverse)$/)
|
140
|
+
result[prop] = @[prop]
|
141
|
+
result
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
# CommonJS module is defined
|
146
|
+
if exports?
|
147
|
+
if module?.exports
|
148
|
+
# Export module
|
149
|
+
module.exports = UnderscoreOutcasts
|
150
|
+
exports.UnderscoreOutcasts = UnderscoreOutcasts
|
151
|
+
else if define?.amd
|
152
|
+
# Register as a named module with AMD.
|
153
|
+
define 'underscore.outcasts', [], -> UnderscoreOutcasts
|
154
|
+
else
|
155
|
+
# Integrate with Underscore.js if defined
|
156
|
+
# or create our own underscore object.
|
157
|
+
@_ ||= {}
|
158
|
+
@_.outcasts = @_.out = UnderscoreOutcasts
|