motion-support 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +3 -0
- data/Gemfile +1 -1
- data/README.md +231 -2
- data/Rakefile +3 -3
- data/app/app_delegate.rb +0 -2
- data/examples/Inflector/.gitignore +16 -0
- data/examples/Inflector/Gemfile +5 -0
- data/examples/Inflector/Rakefile +13 -0
- data/examples/Inflector/app/app_delegate.rb +8 -0
- data/examples/Inflector/app/inflections.rb +5 -0
- data/examples/Inflector/app/inflector_view_controller.rb +120 -0
- data/examples/Inflector/app/words_view_controller.rb +101 -0
- data/examples/Inflector/resources/Default-568h@2x.png +0 -0
- data/examples/Inflector/spec/main_spec.rb +9 -0
- data/lib/motion-support/core_ext/array.rb +13 -0
- data/lib/motion-support/core_ext/class.rb +8 -0
- data/lib/motion-support/core_ext/hash.rb +16 -0
- data/lib/motion-support/core_ext/integer.rb +9 -0
- data/lib/motion-support/core_ext/module.rb +14 -0
- data/lib/motion-support/core_ext/numeric.rb +8 -0
- data/lib/motion-support/core_ext/object.rb +14 -0
- data/lib/motion-support/core_ext/range.rb +8 -0
- data/lib/motion-support/core_ext/string.rb +14 -0
- data/lib/motion-support/core_ext/time.rb +19 -0
- data/lib/motion-support/core_ext.rb +3 -0
- data/lib/motion-support/inflector.rb +12 -156
- data/lib/motion-support.rb +5 -5
- data/motion/_stdlib/cgi.rb +22 -0
- data/motion/_stdlib/date.rb +77 -0
- data/motion/_stdlib/time.rb +19 -0
- data/motion/core_ext/array/access.rb +28 -0
- data/motion/core_ext/array/conversions.rb +86 -0
- data/motion/core_ext/array/extract_options.rb +11 -0
- data/motion/core_ext/array/grouping.rb +99 -0
- data/motion/core_ext/array/prepend_and_append.rb +7 -0
- data/motion/core_ext/array/wrap.rb +45 -0
- data/{lib/motion-support → motion/core_ext}/array.rb +0 -4
- data/motion/core_ext/class/attribute.rb +119 -0
- data/motion/core_ext/class/attribute_accessors.rb +168 -0
- data/motion/core_ext/date/acts_like.rb +8 -0
- data/motion/core_ext/date/calculations.rb +117 -0
- data/motion/core_ext/date/conversions.rb +56 -0
- data/motion/core_ext/date_and_time/calculations.rb +232 -0
- data/motion/core_ext/enumerable.rb +90 -0
- data/motion/core_ext/hash/deep_merge.rb +27 -0
- data/motion/core_ext/hash/except.rb +15 -0
- data/motion/core_ext/hash/indifferent_access.rb +19 -0
- data/motion/core_ext/hash/keys.rb +138 -0
- data/motion/core_ext/hash/reverse_merge.rb +22 -0
- data/motion/core_ext/hash/slice.rb +40 -0
- data/motion/core_ext/integer/inflections.rb +27 -0
- data/motion/core_ext/integer/multiple.rb +10 -0
- data/motion/core_ext/integer/time.rb +41 -0
- data/{lib/motion-support → motion/core_ext}/metaclass.rb +0 -0
- data/motion/core_ext/module/aliasing.rb +69 -0
- data/motion/core_ext/module/anonymous.rb +19 -0
- data/motion/core_ext/module/attr_internal.rb +38 -0
- data/motion/core_ext/module/attribute_accessors.rb +64 -0
- data/motion/core_ext/module/delegation.rb +175 -0
- data/motion/core_ext/module/introspection.rb +60 -0
- data/motion/core_ext/module/reachable.rb +5 -0
- data/motion/core_ext/module/remove_method.rb +12 -0
- data/motion/core_ext/ns_dictionary.rb +11 -0
- data/motion/core_ext/numeric/bytes.rb +44 -0
- data/motion/core_ext/numeric/conversions.rb +7 -0
- data/motion/core_ext/numeric/time.rb +75 -0
- data/motion/core_ext/object/acts_like.rb +10 -0
- data/motion/core_ext/object/blank.rb +105 -0
- data/motion/core_ext/object/deep_dup.rb +44 -0
- data/motion/core_ext/object/duplicable.rb +83 -0
- data/motion/core_ext/object/instance_variables.rb +28 -0
- data/motion/core_ext/object/to_param.rb +58 -0
- data/motion/core_ext/object/to_query.rb +26 -0
- data/motion/core_ext/object/try.rb +78 -0
- data/motion/core_ext/range/include_range.rb +23 -0
- data/motion/core_ext/range/overlaps.rb +8 -0
- data/motion/core_ext/regexp.rb +5 -0
- data/motion/core_ext/string/access.rb +104 -0
- data/motion/core_ext/string/behavior.rb +6 -0
- data/motion/core_ext/string/exclude.rb +11 -0
- data/motion/core_ext/string/filters.rb +55 -0
- data/motion/core_ext/string/indent.rb +43 -0
- data/motion/core_ext/string/inflections.rb +195 -0
- data/motion/core_ext/string/starts_ends_with.rb +4 -0
- data/motion/core_ext/string/strip.rb +24 -0
- data/motion/core_ext/time/acts_like.rb +8 -0
- data/motion/core_ext/time/calculations.rb +215 -0
- data/motion/core_ext/time/conversions.rb +52 -0
- data/motion/duration.rb +104 -0
- data/motion/hash_with_indifferent_access.rb +251 -0
- data/motion/inflections.rb +67 -0
- data/motion/inflector/inflections.rb +203 -0
- data/motion/inflector/methods.rb +321 -0
- data/{lib/motion-support → motion}/logger.rb +0 -0
- data/{lib/motion-support → motion}/version.rb +1 -1
- data/motion-support.gemspec +2 -2
- data/spec/motion-support/_helpers/constantize_test_cases.rb +75 -0
- data/spec/motion-support/_helpers/inflector_test_cases.rb +313 -0
- data/spec/motion-support/core_ext/array/access_spec.rb +29 -0
- data/spec/motion-support/core_ext/array/conversion_spec.rb +60 -0
- data/spec/motion-support/core_ext/array/extract_options_spec.rb +15 -0
- data/spec/motion-support/core_ext/array/grouping_spec.rb +85 -0
- data/spec/motion-support/core_ext/array/prepend_and_append_spec.rb +25 -0
- data/spec/motion-support/core_ext/array/wrap_spec.rb +19 -0
- data/spec/motion-support/{array_spec.rb → core_ext/array_spec.rb} +0 -5
- data/spec/motion-support/core_ext/class/attribute_accessor_spec.rb +127 -0
- data/spec/motion-support/core_ext/class/attribute_spec.rb +92 -0
- data/spec/motion-support/core_ext/date/acts_like_spec.rb +11 -0
- data/spec/motion-support/core_ext/date/calculation_spec.rb +186 -0
- data/spec/motion-support/core_ext/date/conversion_spec.rb +18 -0
- data/spec/motion-support/core_ext/date_and_time/calculation_spec.rb +336 -0
- data/spec/motion-support/core_ext/enumerable_spec.rb +130 -0
- data/spec/motion-support/core_ext/hash/deep_merge_spec.rb +32 -0
- data/spec/motion-support/core_ext/hash/except_spec.rb +43 -0
- data/spec/motion-support/core_ext/hash/key_spec.rb +230 -0
- data/spec/motion-support/core_ext/hash/reverse_merge_spec.rb +26 -0
- data/spec/motion-support/core_ext/hash/slice_spec.rb +61 -0
- data/spec/motion-support/core_ext/integer/inflection_spec.rb +23 -0
- data/spec/motion-support/core_ext/integer/multiple_spec.rb +19 -0
- data/spec/motion-support/{metaclass_spec.rb → core_ext/metaclass_spec.rb} +0 -0
- data/spec/motion-support/core_ext/module/aliasing_spec.rb +143 -0
- data/spec/motion-support/core_ext/module/anonymous_spec.rb +29 -0
- data/spec/motion-support/core_ext/module/attr_internal_spec.rb +104 -0
- data/spec/motion-support/core_ext/module/attribute_accessor_spec.rb +86 -0
- data/spec/motion-support/core_ext/module/delegation_spec.rb +136 -0
- data/spec/motion-support/core_ext/module/introspection_spec.rb +70 -0
- data/spec/motion-support/core_ext/module/reachable_spec.rb +61 -0
- data/spec/motion-support/core_ext/module/remove_method_spec.rb +25 -0
- data/spec/motion-support/core_ext/numeric/bytes_spec.rb +43 -0
- data/spec/motion-support/core_ext/object/acts_like_spec.rb +21 -0
- data/spec/motion-support/core_ext/object/blank_spec.rb +54 -0
- data/spec/motion-support/core_ext/object/deep_dup_spec.rb +54 -0
- data/spec/motion-support/core_ext/object/duplicable_spec.rb +31 -0
- data/spec/motion-support/core_ext/object/instance_variable_spec.rb +19 -0
- data/spec/motion-support/core_ext/object/to_param_spec.rb +75 -0
- data/spec/motion-support/core_ext/object/to_query_spec.rb +37 -0
- data/spec/motion-support/core_ext/object/try_spec.rb +92 -0
- data/spec/motion-support/core_ext/range/include_range_spec.rb +31 -0
- data/spec/motion-support/core_ext/range/overlap_spec.rb +43 -0
- data/spec/motion-support/core_ext/regexp_spec.rb +7 -0
- data/spec/motion-support/core_ext/string/access_spec.rb +53 -0
- data/spec/motion-support/core_ext/string/behavior_spec.rb +7 -0
- data/spec/motion-support/core_ext/string/exclude_spec.rb +8 -0
- data/spec/motion-support/core_ext/string/filter_spec.rb +48 -0
- data/spec/motion-support/core_ext/string/indent_spec.rb +56 -0
- data/spec/motion-support/core_ext/string/inflection_spec.rb +142 -0
- data/spec/motion-support/core_ext/string/starts_end_with_spec.rb +14 -0
- data/spec/motion-support/core_ext/string/strip_spec.rb +34 -0
- data/spec/motion-support/core_ext/string_spec.rb +88 -0
- data/spec/motion-support/core_ext/time/acts_like_spec.rb +11 -0
- data/spec/motion-support/core_ext/time/calculation_spec.rb +201 -0
- data/spec/motion-support/core_ext/time/conversion_spec.rb +54 -0
- data/spec/motion-support/duration_spec.rb +107 -0
- data/spec/motion-support/hash_with_indifferent_access_spec.rb +605 -0
- data/spec/motion-support/inflector_spec.rb +474 -35
- data/spec/motion-support/ns_dictionary_spec.rb +29 -0
- metadata +212 -35
- data/lib/motion-support/cattr_accessor.rb +0 -19
- data/lib/motion-support/class_inheritable_accessor.rb +0 -23
- data/lib/motion-support/class_inheritable_array.rb +0 -29
- data/lib/motion-support/hash.rb +0 -31
- data/lib/motion-support/nilclass.rb +0 -5
- data/lib/motion-support/object.rb +0 -17
- data/lib/motion-support/string.rb +0 -71
- data/spec/motion-support/cattr_accessor_spec.rb +0 -49
- data/spec/motion-support/class_inheritable_accessor_spec.rb +0 -49
- data/spec/motion-support/class_inheritable_array_spec.rb +0 -61
- data/spec/motion-support/hash_spec.rb +0 -31
- data/spec/motion-support/nilclass_spec.rb +0 -5
- data/spec/motion-support/object_spec.rb +0 -43
- data/spec/motion-support/string_spec.rb +0 -145
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
|
@@ -1,8 +1,237 @@
|
|
|
1
1
|
# MotionSupport
|
|
2
2
|
|
|
3
|
-
This is a
|
|
3
|
+
This is a port of the parts of ActiveSupport that make sense for RubyMotion.
|
|
4
4
|
|
|
5
|
-
To see what's there, look into the lib folder.
|
|
5
|
+
To see what's there, generate the documentation with the `rdoc` command from the repository root, or look into the lib folder. Almost everything is tested.
|
|
6
|
+
|
|
7
|
+
# Usage
|
|
8
|
+
|
|
9
|
+
Install with
|
|
10
|
+
|
|
11
|
+
gem install motion-support
|
|
12
|
+
|
|
13
|
+
or add to your `Gemfile`
|
|
14
|
+
|
|
15
|
+
gem 'motion-support'
|
|
16
|
+
|
|
17
|
+
# Partial loading
|
|
18
|
+
|
|
19
|
+
It is also possible to only use parts of this library. To do so, change your `Gemfile` so that it reads:
|
|
20
|
+
|
|
21
|
+
gem 'motion-support', :require => false
|
|
22
|
+
|
|
23
|
+
Then add a require statement as shown below to your `Rakefile`.
|
|
24
|
+
|
|
25
|
+
## all
|
|
26
|
+
|
|
27
|
+
require 'motion-support'
|
|
28
|
+
|
|
29
|
+
Loads everything.
|
|
30
|
+
|
|
31
|
+
## inflector
|
|
32
|
+
|
|
33
|
+
require 'motion-support/inflector'
|
|
34
|
+
|
|
35
|
+
Loads the `Inflector` module and extensions to the `String` class. See the "Inflector" app in the `examples/` folder for what the inflector can do.
|
|
36
|
+
|
|
37
|
+
Example usage include:
|
|
38
|
+
|
|
39
|
+
"app_delegate".camelize # => "AppDelegate"
|
|
40
|
+
"HomeController".constantize # => HomeController
|
|
41
|
+
"thing".pluralize # => "things"
|
|
42
|
+
"mice".singularize # => "mouse"
|
|
43
|
+
|
|
44
|
+
## core_ext
|
|
45
|
+
|
|
46
|
+
require 'motion-support/core_ext'
|
|
47
|
+
|
|
48
|
+
Loads all the extensions to core classes.
|
|
49
|
+
|
|
50
|
+
## core_ext/array
|
|
51
|
+
|
|
52
|
+
require 'motion-support/core_ext/array'
|
|
53
|
+
|
|
54
|
+
Loads extensions to class `Array`. Example usage include
|
|
55
|
+
|
|
56
|
+
%w( a b c d ).from(2) # => ["c", "d"]
|
|
57
|
+
['one', 'two', 'three'].to_sentence # => "one, two, and three"
|
|
58
|
+
args.extract_options! # extracts options hash from variant args array
|
|
59
|
+
[1, 2, 3, 4].in_groups_of(2) # => [[1, 2], [3, 4]]
|
|
60
|
+
|
|
61
|
+
## core_ext/class
|
|
62
|
+
|
|
63
|
+
require 'motion-support/core_ext/class'
|
|
64
|
+
|
|
65
|
+
Loads extensions to class `Class`.
|
|
66
|
+
|
|
67
|
+
class Foo
|
|
68
|
+
cattr_accessor :bar
|
|
69
|
+
class_attribute :foo
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
## core_ext/hash
|
|
73
|
+
|
|
74
|
+
require 'motion-support/core_ext/hash'
|
|
75
|
+
|
|
76
|
+
Loads extensions to class `Hash`, including class `HashWithIndifferentAccess`.
|
|
77
|
+
|
|
78
|
+
{ 'foo' => 'bar', 'baz' => 'bam' }.symbolize_keys # => { :foo => 'bar', :baz => 'bam' }
|
|
79
|
+
{ 'foo' => 'bar', 'baz' => 'bam' }.except('foo') # => { 'baz' => 'bam' }
|
|
80
|
+
{ 'foo' => 'bar', 'baz' => 'bam' }.with_indifferent_access
|
|
81
|
+
# => #<HashWithIndifferentAccess>
|
|
82
|
+
|
|
83
|
+
## core_ext/integer
|
|
84
|
+
|
|
85
|
+
require 'motion-support/core_ext/integer'
|
|
86
|
+
|
|
87
|
+
Loads extensions to class `Integer`.
|
|
88
|
+
|
|
89
|
+
1.ordinalize # => "1st"
|
|
90
|
+
3.ordinalize # => "3rd"
|
|
91
|
+
|
|
92
|
+
## core_ext/module
|
|
93
|
+
|
|
94
|
+
require 'motion-support/core_ext/module'
|
|
95
|
+
|
|
96
|
+
Loads extensions to class `Module`.
|
|
97
|
+
|
|
98
|
+
module Mod
|
|
99
|
+
mattr_accessor :foo, :bar
|
|
100
|
+
attr_internal :baz
|
|
101
|
+
delegate :boo, :to => :foo
|
|
102
|
+
|
|
103
|
+
remove_method :baz
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
## core_ext/numeric
|
|
107
|
+
|
|
108
|
+
require 'motion-support/core_ext/numeric'
|
|
109
|
+
|
|
110
|
+
Loads extensions to class `Numeric`.
|
|
111
|
+
|
|
112
|
+
10.kilobytes # => 10240
|
|
113
|
+
2.megabytes # => 2097152
|
|
114
|
+
3.days
|
|
115
|
+
|
|
116
|
+
## core_ext/object
|
|
117
|
+
|
|
118
|
+
require 'motion-support/core_ext/object'
|
|
119
|
+
|
|
120
|
+
Loads extensions to class `Object`.
|
|
121
|
+
|
|
122
|
+
nil.blank? # => true
|
|
123
|
+
Object.new.blank? # => false
|
|
124
|
+
{ "hello" => "world", "foo" => "bar" }.to_query # => "hello=world&foo=bar"
|
|
125
|
+
1.duplicable? # => false
|
|
126
|
+
1.try(:to_s) # => "1"
|
|
127
|
+
nil.try(:to_s) # => nil
|
|
128
|
+
|
|
129
|
+
## core_ext/range
|
|
130
|
+
|
|
131
|
+
require 'motion-support/core_ext/range'
|
|
132
|
+
|
|
133
|
+
Loads extensions to class `Range`.
|
|
134
|
+
|
|
135
|
+
(1..5).overlaps(3..9) # => true
|
|
136
|
+
(1..5).include?(2..3) # => true
|
|
137
|
+
|
|
138
|
+
## core_ext/string
|
|
139
|
+
|
|
140
|
+
require 'motion-support/core_ext/string'
|
|
141
|
+
|
|
142
|
+
Loads extensions to class `String`.
|
|
143
|
+
|
|
144
|
+
"ruby_motion".camelize # => "RubyMotion"
|
|
145
|
+
"User".pluralize # => "Users"
|
|
146
|
+
"mice".singularize # => "mouse"
|
|
147
|
+
"Foo::Bar".underscore # => "foo/bar"
|
|
148
|
+
"AppDelegate".underscore # => "app_delegate"
|
|
149
|
+
"UIView".constantize # => UIView
|
|
150
|
+
|
|
151
|
+
## core_ext/time
|
|
152
|
+
|
|
153
|
+
require 'motion-support/core_ext/time'
|
|
154
|
+
|
|
155
|
+
Loads extensions to class `Time`.
|
|
156
|
+
|
|
157
|
+
1.week.ago
|
|
158
|
+
17.days.from_now
|
|
159
|
+
Date.yesterday
|
|
160
|
+
Time.beginning_of_week
|
|
161
|
+
|
|
162
|
+
# Differences to ActiveSupport
|
|
163
|
+
|
|
164
|
+
In general:
|
|
165
|
+
|
|
166
|
+
* All `I18n` stuff was removed. Maybe it will be readded later.
|
|
167
|
+
* No support for the `TimeWithZone` class (iOS apps don't need advanced time zone support)
|
|
168
|
+
* No support for the `DateTime` class
|
|
169
|
+
* All deprecated methods have been removed
|
|
170
|
+
* All `YAML` extensions were removed, since RubyMotion doesn't come with YAML support
|
|
171
|
+
* `Kernel#silence_warnings` and stream manipulation methods were removed
|
|
172
|
+
* Multibyte string handling methods have been removed
|
|
173
|
+
* All Rails-specific stuff was removed
|
|
174
|
+
* The dependency resolution code was removed. So was the dynamic code reloading code
|
|
175
|
+
* All marshalling code was removed
|
|
176
|
+
* All logging code was removed
|
|
177
|
+
* All extensions to `Test::Unit` were removed
|
|
178
|
+
|
|
179
|
+
Specifically:
|
|
180
|
+
|
|
181
|
+
* `Array#third` .. `Array#fourty_two` were removed
|
|
182
|
+
* `Array#to_xml` is missing
|
|
183
|
+
* `Array#to_sentence` does not accept a `:locale` parameter
|
|
184
|
+
* `Class#subclasses` is missing. It depends on `ObjectSpace.each_object` which is missing in RubyMotion
|
|
185
|
+
* `Hash#extractable_options?` is missing
|
|
186
|
+
* `BigDecimal` conversions were removed
|
|
187
|
+
* `Time.current` an alias for `Time.now`
|
|
188
|
+
* `Date.current` an alias for `Date.today`
|
|
189
|
+
* `Date#to_time` does not accept a timezone form (`:local`, `:utc`)
|
|
190
|
+
* `Date#xmlschema` is missing
|
|
191
|
+
* `Object#in?` is missing. It is incompatible with Bacon, it will break specs.
|
|
192
|
+
* `String#parameterize` is missing because it needs to transliterate the string, which is dependent on the locale
|
|
193
|
+
* `String#constantize` is very slow. Cache the result if you use it.
|
|
194
|
+
* `String#to_time`, `#to_date`, `#to_datetime` are missing because they depend on `Date#_parse`
|
|
195
|
+
* String inquiry methods are missing
|
|
196
|
+
* String multibyte methods are missing
|
|
197
|
+
* `String#html_safe` and `ERB` extensions are not needed in RubyMotion
|
|
198
|
+
* `Object#to_json` and subclasses are missing
|
|
199
|
+
* `Range#to_s(:db)` was removed
|
|
200
|
+
* The `rfc822` time format was removed, since it relies on time zone support.
|
|
201
|
+
* Extensions to `LoadError` and `NameError` were removed
|
|
202
|
+
* The `ThreadSafe` versions of `Hash` and `Array` are just aliases to the standard classes
|
|
203
|
+
|
|
204
|
+
Things to do / to decide:
|
|
205
|
+
|
|
206
|
+
* RubyMotion lacks a `Date` class. in `_stdlib` there is a stub of a Date class that makes the `Date` extensions work. This stub needs to be completed.
|
|
207
|
+
* Implement `Object#to_json`, probably best if implemented on top of Cocoa APIs
|
|
208
|
+
* Implement `Object#to_xml`
|
|
209
|
+
* Implement `Hash#from_xml`
|
|
210
|
+
* Do we need `Hash#extractable_options?`?
|
|
211
|
+
* Do we need `Class#superclass_delegating_accessor`?
|
|
212
|
+
* Implement all `InfiniteComparable` extensions
|
|
213
|
+
* Do we need `File#atomic_write` for thread-safe file writing?
|
|
214
|
+
* Do we need `Kernel#class_eval` (it delegates to `class_eval` on this' singleton class)?
|
|
215
|
+
* Do we need `Module#qualified_const_defined?`? What is that even for?
|
|
216
|
+
* Do we need `Module#synchronize`?
|
|
217
|
+
* Implement `Numeric` conversions, especially `NumberHelper`
|
|
218
|
+
* Do we need `Object#with_options`?
|
|
219
|
+
* Implement `String#to_time`, `String#to_date`. In the original ActiveSupport, they make use of the `Date#_parse` method (which seems like it's supposed to be private). Here, they should be implemented on top of Cocoa APIs
|
|
220
|
+
* Do we need `String#parameterize`? If so, we need to find a way to transliterate UTF-8 characters.
|
|
221
|
+
* Do we need the `StringInquirer`? It allows things like `Rails.env.development?` instead of `Rails.env == 'development'`
|
|
222
|
+
* Do we need multibyte string handling extensions? AFAIK, all strings in RubyMotion are UTF-8. Is that true?
|
|
223
|
+
* Do we need `Struct#to_h`?
|
|
224
|
+
* Implement extensions to class `Thread` if they make sense.
|
|
225
|
+
* Port callbacks.rb
|
|
226
|
+
* Port concern.rb
|
|
227
|
+
* Do we need the `Configurable` module?
|
|
228
|
+
* Do we need the `DescendantsTracker` module?
|
|
229
|
+
* Do we need the `OrderedOptions` class?
|
|
230
|
+
* Go through documentation and remove or rewrite things not relevant to RubyMotion, especially examples mentioning Rails components
|
|
231
|
+
|
|
232
|
+
# Acknowledgements
|
|
233
|
+
|
|
234
|
+
ActiveSupport was originally written as part of Ruby on Rails by David Heinemeier Hansson. Over the years, countless contributors made many additions. They made this library possible.
|
|
6
235
|
|
|
7
236
|
# Forking
|
|
8
237
|
|
data/Rakefile
CHANGED
|
@@ -5,10 +5,10 @@ require "bundler/gem_tasks"
|
|
|
5
5
|
Bundler.setup
|
|
6
6
|
Bundler.require
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
require './lib/motion-support'
|
|
8
|
+
require 'motion-support'
|
|
10
9
|
|
|
11
10
|
Motion::Project::App.setup do |app|
|
|
12
11
|
# Use `rake config' to see complete project settings.
|
|
13
12
|
app.name = 'MotionSupport'
|
|
14
|
-
|
|
13
|
+
app.detect_dependencies = false
|
|
14
|
+
end
|
data/app/app_delegate.rb
CHANGED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
$:.unshift("/Library/RubyMotion/lib")
|
|
3
|
+
require 'motion/project'
|
|
4
|
+
require 'bundler'
|
|
5
|
+
Bundler.require
|
|
6
|
+
|
|
7
|
+
require '../../lib/motion-support/inflector'
|
|
8
|
+
|
|
9
|
+
Motion::Project::App.setup do |app|
|
|
10
|
+
# Use `rake config' to see complete project settings.
|
|
11
|
+
app.name = 'Inflector'
|
|
12
|
+
app.detect_dependencies = false
|
|
13
|
+
end
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
class AppDelegate
|
|
2
|
+
def application(application, didFinishLaunchingWithOptions:launchOptions)
|
|
3
|
+
@window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
|
|
4
|
+
@window.rootViewController = UINavigationController.alloc.initWithRootViewController(InflectorViewController.alloc.init)
|
|
5
|
+
@window.makeKeyAndVisible
|
|
6
|
+
true
|
|
7
|
+
end
|
|
8
|
+
end
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
class Formotion::Form
|
|
2
|
+
def row(key)
|
|
3
|
+
sections.each do |section|
|
|
4
|
+
section.rows.each do |row|
|
|
5
|
+
return row if row.key == key
|
|
6
|
+
end
|
|
7
|
+
end
|
|
8
|
+
nil
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
class InflectorViewController < Formotion::FormController
|
|
13
|
+
def init
|
|
14
|
+
initWithForm(build_form)
|
|
15
|
+
self.title = "Inflector"
|
|
16
|
+
@form.on_submit do |form|
|
|
17
|
+
submit(form)
|
|
18
|
+
end
|
|
19
|
+
self
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def submit(form)
|
|
23
|
+
data = form.render
|
|
24
|
+
original = String.new(data[:word])
|
|
25
|
+
|
|
26
|
+
update_fields(original)
|
|
27
|
+
|
|
28
|
+
form.row(:word).text_field.resignFirstResponder
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def set_word(word)
|
|
32
|
+
@form.values = { :word => word }
|
|
33
|
+
update_fields(word)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def update_fields(original)
|
|
37
|
+
@form.values = {
|
|
38
|
+
:singular => original.singularize,
|
|
39
|
+
:plural => original.pluralize,
|
|
40
|
+
:camelized => original.camelize,
|
|
41
|
+
:lower_camelized => original.camelize(:lower),
|
|
42
|
+
:underscored => original.underscore,
|
|
43
|
+
:classified => original.classify,
|
|
44
|
+
:dasherized => original.dasherize,
|
|
45
|
+
:titleized => original.titleize,
|
|
46
|
+
:humanized => original.humanize
|
|
47
|
+
}
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
private
|
|
51
|
+
def build_form
|
|
52
|
+
@form ||= Formotion::Form.persist({
|
|
53
|
+
sections: [{
|
|
54
|
+
rows: [{
|
|
55
|
+
title: "Word",
|
|
56
|
+
key: :word,
|
|
57
|
+
type: :string,
|
|
58
|
+
placeholder: "Enter a word",
|
|
59
|
+
auto_correction: :no,
|
|
60
|
+
auto_capitalization: :none
|
|
61
|
+
}, {
|
|
62
|
+
title: "Select",
|
|
63
|
+
type: :button,
|
|
64
|
+
key: :select
|
|
65
|
+
}]
|
|
66
|
+
}, {
|
|
67
|
+
rows: [{
|
|
68
|
+
title: "Inflect",
|
|
69
|
+
type: :submit
|
|
70
|
+
}]
|
|
71
|
+
}, {
|
|
72
|
+
title: "Inflections",
|
|
73
|
+
rows: [{
|
|
74
|
+
title: "Singular",
|
|
75
|
+
key: :singular,
|
|
76
|
+
type: :static
|
|
77
|
+
}, {
|
|
78
|
+
title: "Plural",
|
|
79
|
+
key: :plural,
|
|
80
|
+
type: :static
|
|
81
|
+
}]
|
|
82
|
+
}, {
|
|
83
|
+
title: "Transformations",
|
|
84
|
+
rows: [{
|
|
85
|
+
title: "Camelized",
|
|
86
|
+
key: :camelized,
|
|
87
|
+
type: :static
|
|
88
|
+
}, {
|
|
89
|
+
title: "Lower-Camelized",
|
|
90
|
+
key: :lower_camelized,
|
|
91
|
+
type: :static
|
|
92
|
+
}, {
|
|
93
|
+
title: "Underscored",
|
|
94
|
+
key: :underscored,
|
|
95
|
+
type: :static
|
|
96
|
+
}, {
|
|
97
|
+
title: "Classified",
|
|
98
|
+
key: :classified,
|
|
99
|
+
type: :static
|
|
100
|
+
}, {
|
|
101
|
+
title: "Dasherized",
|
|
102
|
+
key: :dasherized,
|
|
103
|
+
type: :static
|
|
104
|
+
}, {
|
|
105
|
+
title: "Titleized",
|
|
106
|
+
key: :titleized,
|
|
107
|
+
type: :static
|
|
108
|
+
}, {
|
|
109
|
+
title: "Humanized",
|
|
110
|
+
key: :humanized,
|
|
111
|
+
type: :static
|
|
112
|
+
}]
|
|
113
|
+
}]
|
|
114
|
+
})
|
|
115
|
+
@form.row(:select).on_tap do
|
|
116
|
+
self.navigationController.pushViewController(WordsViewController.alloc.initWithParent(self), animated:true)
|
|
117
|
+
end
|
|
118
|
+
@form
|
|
119
|
+
end
|
|
120
|
+
end
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
class WordsViewController < UITableViewController
|
|
2
|
+
WORDS = [
|
|
3
|
+
[
|
|
4
|
+
"Single words",
|
|
5
|
+
%w{
|
|
6
|
+
alias
|
|
7
|
+
axis
|
|
8
|
+
buffalo
|
|
9
|
+
bus
|
|
10
|
+
cat
|
|
11
|
+
child
|
|
12
|
+
cow
|
|
13
|
+
crisis
|
|
14
|
+
dog
|
|
15
|
+
house
|
|
16
|
+
man
|
|
17
|
+
matrix
|
|
18
|
+
mouse
|
|
19
|
+
move
|
|
20
|
+
octopus
|
|
21
|
+
ox
|
|
22
|
+
parenthesis
|
|
23
|
+
person
|
|
24
|
+
quiz
|
|
25
|
+
series
|
|
26
|
+
sex
|
|
27
|
+
vertex
|
|
28
|
+
zombie
|
|
29
|
+
}
|
|
30
|
+
], [
|
|
31
|
+
"Uncountable words",
|
|
32
|
+
%w{
|
|
33
|
+
equipment
|
|
34
|
+
fish
|
|
35
|
+
information
|
|
36
|
+
jeans
|
|
37
|
+
money
|
|
38
|
+
police
|
|
39
|
+
rice
|
|
40
|
+
series
|
|
41
|
+
sheep
|
|
42
|
+
species
|
|
43
|
+
}
|
|
44
|
+
], [
|
|
45
|
+
"Programming",
|
|
46
|
+
%w{
|
|
47
|
+
app_delegate
|
|
48
|
+
motion_support
|
|
49
|
+
motion_support/inflector
|
|
50
|
+
ruby_motion
|
|
51
|
+
}
|
|
52
|
+
], [
|
|
53
|
+
"Acronyms",
|
|
54
|
+
%w{
|
|
55
|
+
free_bsd
|
|
56
|
+
html_api
|
|
57
|
+
html_tidy
|
|
58
|
+
ui_image
|
|
59
|
+
ui_table_view_controller
|
|
60
|
+
xml_http_request
|
|
61
|
+
}
|
|
62
|
+
]
|
|
63
|
+
]
|
|
64
|
+
|
|
65
|
+
def initWithParent(parent)
|
|
66
|
+
@parent = parent
|
|
67
|
+
|
|
68
|
+
self.title = "Select word"
|
|
69
|
+
|
|
70
|
+
self
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def numberOfSectionsInTableView(tableView)
|
|
74
|
+
WORDS.size
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def tableView(tableView, titleForHeaderInSection:section)
|
|
78
|
+
WORDS[section].first
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def tableView(tableView, numberOfRowsInSection:section)
|
|
82
|
+
WORDS[section].last.size
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def tableView(tableView, cellForRowAtIndexPath:indexPath)
|
|
86
|
+
fresh_cell.tap do |cell|
|
|
87
|
+
cell.textLabel.text = WORDS[indexPath.section].last[indexPath.row]
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def tableView(tableView, didSelectRowAtIndexPath:indexPath)
|
|
92
|
+
@parent.set_word(WORDS[indexPath.section].last[indexPath.row])
|
|
93
|
+
navigationController.popViewControllerAnimated(true)
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
private
|
|
97
|
+
def fresh_cell
|
|
98
|
+
tableView.dequeueReusableCellWithIdentifier('Cell') ||
|
|
99
|
+
UITableViewCell.alloc.initWithStyle(UITableViewCellStyleSubtitle, reuseIdentifier:'Cell')
|
|
100
|
+
end
|
|
101
|
+
end
|
|
Binary file
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
require 'motion-require'
|
|
2
|
+
|
|
3
|
+
files = [
|
|
4
|
+
'core_ext/array',
|
|
5
|
+
'core_ext/array/wrap',
|
|
6
|
+
'core_ext/array/access',
|
|
7
|
+
'core_ext/array/conversions',
|
|
8
|
+
'core_ext/array/extract_options',
|
|
9
|
+
'core_ext/array/grouping',
|
|
10
|
+
'core_ext/array/prepend_and_append'
|
|
11
|
+
].map { |file| File.expand_path(File.join(File.dirname(__FILE__), "/../../../motion", "#{file}.rb")) }
|
|
12
|
+
|
|
13
|
+
Motion::Require.all(files)
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
require 'motion-require'
|
|
2
|
+
|
|
3
|
+
files = [
|
|
4
|
+
'core_ext/ns_dictionary',
|
|
5
|
+
'core_ext/hash/deep_merge',
|
|
6
|
+
'core_ext/hash/except',
|
|
7
|
+
'core_ext/hash/indifferent_access',
|
|
8
|
+
'core_ext/hash/keys',
|
|
9
|
+
'core_ext/hash/reverse_merge',
|
|
10
|
+
'core_ext/hash/slice',
|
|
11
|
+
'hash_with_indifferent_access',
|
|
12
|
+
|
|
13
|
+
'core_ext/module/delegation'
|
|
14
|
+
].map { |file| File.expand_path(File.join(File.dirname(__FILE__), "/../../../motion", "#{file}.rb")) }
|
|
15
|
+
|
|
16
|
+
Motion::Require.all(files)
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
require 'motion-require'
|
|
2
|
+
|
|
3
|
+
files = [
|
|
4
|
+
'core_ext/integer/multiple',
|
|
5
|
+
'core_ext/integer/inflections',
|
|
6
|
+
'core_ext/integer/time'
|
|
7
|
+
].map { |file| File.expand_path(File.join(File.dirname(__FILE__), "/../../../motion", "#{file}.rb")) }
|
|
8
|
+
|
|
9
|
+
Motion::Require.all(files)
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
require 'motion-require'
|
|
2
|
+
|
|
3
|
+
files = [
|
|
4
|
+
'core_ext/module/aliasing',
|
|
5
|
+
'core_ext/module/introspection',
|
|
6
|
+
'core_ext/module/anonymous',
|
|
7
|
+
'core_ext/module/reachable',
|
|
8
|
+
'core_ext/module/attribute_accessors',
|
|
9
|
+
'core_ext/module/attr_internal',
|
|
10
|
+
'core_ext/module/delegation',
|
|
11
|
+
'core_ext/module/remove_method'
|
|
12
|
+
].map { |file| File.expand_path(File.join(File.dirname(__FILE__), "/../../../motion", "#{file}.rb")) }
|
|
13
|
+
|
|
14
|
+
Motion::Require.all(files)
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
require 'motion-require'
|
|
2
|
+
|
|
3
|
+
files = [
|
|
4
|
+
'core_ext/object/acts_like',
|
|
5
|
+
'core_ext/object/blank',
|
|
6
|
+
'core_ext/object/deep_dup',
|
|
7
|
+
'core_ext/object/duplicable',
|
|
8
|
+
'core_ext/object/try',
|
|
9
|
+
'core_ext/object/instance_variables',
|
|
10
|
+
'core_ext/object/to_param',
|
|
11
|
+
'core_ext/object/to_query',
|
|
12
|
+
].map { |file| File.expand_path(File.join(File.dirname(__FILE__), "/../../../motion", "#{file}.rb")) }
|
|
13
|
+
|
|
14
|
+
Motion::Require.all(files)
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
require 'motion-require'
|
|
2
|
+
|
|
3
|
+
files = [
|
|
4
|
+
'core_ext/string/access',
|
|
5
|
+
'core_ext/string/behavior',
|
|
6
|
+
'core_ext/string/exclude',
|
|
7
|
+
'core_ext/string/filters',
|
|
8
|
+
'core_ext/string/indent',
|
|
9
|
+
'core_ext/string/starts_ends_with',
|
|
10
|
+
'core_ext/string/inflections',
|
|
11
|
+
'core_ext/string/strip'
|
|
12
|
+
].map { |file| File.expand_path(File.join(File.dirname(__FILE__), "/../../../motion", "#{file}.rb")) }
|
|
13
|
+
|
|
14
|
+
Motion::Require.all(files)
|