sugarcube 0.18.17 → 0.18.18

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -820,10 +820,10 @@ Chains can also be written like this:
820
820
 
821
821
  ```ruby
822
822
  chain = UIView.animation_chain
823
- chain << proc { view.slide(:left, 20, chain: true) }
824
- chain << proc { view.slide(:up, 20, chain: true) }
825
- chain << proc { view.slide(:right, 20, chain: true) }
826
- chain << proc { view.slide(:down, 20, chain: true) }
823
+ chain << proc { view.slide(:left, 20) }
824
+ chain << proc { view.slide(:up, 20) }
825
+ chain << proc { view.slide(:right, 20) }
826
+ chain << proc { view.slide(:down, 20) }
827
827
  chain << proc { view.fade_out }
828
828
  chain.start
829
829
  ```
@@ -1038,39 +1038,64 @@ text_view.off :change, :end, :begin
1038
1038
  ----------------------
1039
1039
 
1040
1040
  ```ruby
1041
+ # Get an instance containing the specified system item.
1041
1042
  UIBarButtonItem.done {
1042
1043
  self.dismissViewControllerAnimated true, completion:nil
1043
1044
  }
1044
1045
  # =>
1045
- UIBarButtonitem.alloc.initWithBarButtonSystemItem(:done.uibarbuttonitem, target:self, action:"action:")
1046
+ UIBarButtonItem.alloc.initWithBarButtonSystemItem(:done.uibarbuttonitem, target:self, action:"action:")
1047
+ # with 'action' defined as:
1048
+ def action(sender)
1049
+ self.dismissViewControllerAnimated true, completion:nil
1050
+ end
1051
+
1052
+ # the method names are 1::1 with the uibarbuttonitem constants in symbol.rb
1053
+ UIBarButtonItem.cancel(&action) => UIBarButtonItem.alloc.initWithBarButtonSystemItem(:cancel.uibarbuttonitem, target:self, action:"action:")
1054
+ UIBarButtonItem.edit(&action) => UIBarButtonItem.alloc.initWithBarButtonSystemItem(:edit.uibarbuttonitem, target:self, action:"action:")
1055
+ UIBarButtonItem.save(&action) => UIBarButtonItem.alloc.initWithBarButtonSystemItem(:save.uibarbuttonitem, target:self, action:"action:")
1056
+ .
1057
+ .
1058
+ .
1059
+ UIBarButtonItem.pagecurl(&action) => UIBarButtonItem.alloc.initWithBarButtonSystemItem(:pagecurl.uibarbuttonitem, target:self, action:"action:")
1060
+
1061
+ # Get an instance containing the specified title.
1062
+ UIBarButtonItem.titled('Close') {
1063
+ self.dismissViewControllerAnimated true, completion:nil
1064
+ }
1065
+ # =>
1066
+ UIBarButtonItem.alloc.initWithTitle('Close', style: :bordered.uibarbuttonstyle, target:self, action:"action:")
1067
+
1068
+ def action:sender
1069
+ self.dismissViewControllerAnimated true, completion:nil
1070
+ end
1071
+
1072
+ # You can also specify a style.
1073
+ UIBarButtonItem.titled('Close', :plain.uibarbuttonstyle) {
1074
+ self.dismissViewControllerAnimated true, completion:nil
1075
+ }
1076
+
1077
+
1078
+ # Get an instance containing the specified image.
1079
+ UIBarButtonItem.imaged('close'.uiimage) {
1080
+ self.dismissViewControllerAnimated true, completion:nil
1081
+ }
1082
+ # =>
1083
+ UIBarButtonItem.alloc.initWithImage('Close'.uiimage, style: :bordered.uibarbuttonstyle, target:self, action:"action:")
1046
1084
  def action:sender
1047
1085
  self.dismissViewControllerAnimated true, completion:nil
1048
1086
  end
1049
1087
 
1050
- UIBarButtonitem.done(&action) => UIBarButtonitem.alloc.initWithBarButtonSystemItem(:done.uibarbuttonitem, target:self, action:"action:")
1051
- UIBarButtonitem.cancel(&action) => UIBarButtonitem.alloc.initWithBarButtonSystemItem(:cancel.uibarbuttonitem, target:self, action:"action:")
1052
- UIBarButtonitem.edit(&action) => UIBarButtonitem.alloc.initWithBarButtonSystemItem(:edit.uibarbuttonitem, target:self, action:"action:")
1053
- UIBarButtonitem.save(&action) => UIBarButtonitem.alloc.initWithBarButtonSystemItem(:save.uibarbuttonitem, target:self, action:"action:")
1054
- UIBarButtonitem.add(&action) => UIBarButtonitem.alloc.initWithBarButtonSystemItem(:add.uibarbuttonitem, target:self, action:"action:")
1055
- UIBarButtonitem.flexiblespace(&action) => UIBarButtonitem.alloc.initWithBarButtonSystemItem(:flexiblespace.uibarbuttonitem, target:self, action:"action:")
1056
- UIBarButtonitem.fixedspace(&action) => UIBarButtonitem.alloc.initWithBarButtonSystemItem(:fixedspace.uibarbuttonitem, target:self, action:"action:")
1057
- UIBarButtonitem.compose(&action) => UIBarButtonitem.alloc.initWithBarButtonSystemItem(:compose.uibarbuttonitem, target:self, action:"action:")
1058
- UIBarButtonitem.reply(&action) => UIBarButtonitem.alloc.initWithBarButtonSystemItem(:reply.uibarbuttonitem, target:self, action:"action:")
1059
- UIBarButtonitem.action(&action) => UIBarButtonitem.alloc.initWithBarButtonSystemItem(:action.uibarbuttonitem, target:self, action:"action:")
1060
- UIBarButtonitem.organize(&action) => UIBarButtonitem.alloc.initWithBarButtonSystemItem(:organize.uibarbuttonitem, target:self, action:"action:")
1061
- UIBarButtonitem.bookmarks(&action) => UIBarButtonitem.alloc.initWithBarButtonSystemItem(:bookmarks.uibarbuttonitem, target:self, action:"action:")
1062
- UIBarButtonitem.search(&action) => UIBarButtonitem.alloc.initWithBarButtonSystemItem(:search.uibarbuttonitem, target:self, action:"action:")
1063
- UIBarButtonitem.refresh(&action) => UIBarButtonitem.alloc.initWithBarButtonSystemItem(:refresh.uibarbuttonitem, target:self, action:"action:")
1064
- UIBarButtonitem.stop(&action) => UIBarButtonitem.alloc.initWithBarButtonSystemItem(:stop.uibarbuttonitem, target:self, action:"action:")
1065
- UIBarButtonitem.camera(&action) => UIBarButtonitem.alloc.initWithBarButtonSystemItem(:camera.uibarbuttonitem, target:self, action:"action:")
1066
- UIBarButtonitem.trash(&action) => UIBarButtonitem.alloc.initWithBarButtonSystemItem(:trash.uibarbuttonitem, target:self, action:"action:")
1067
- UIBarButtonitem.play(&action) => UIBarButtonitem.alloc.initWithBarButtonSystemItem(:play.uibarbuttonitem, target:self, action:"action:")
1068
- UIBarButtonitem.pause(&action) => UIBarButtonitem.alloc.initWithBarButtonSystemItem(:pause.uibarbuttonitem, target:self, action:"action:")
1069
- UIBarButtonitem.rewind(&action) => UIBarButtonitem.alloc.initWithBarButtonSystemItem(:rewind.uibarbuttonitem, target:self, action:"action:")
1070
- UIBarButtonitem.fastforward(&action) => UIBarButtonitem.alloc.initWithBarButtonSystemItem(:fastforward.uibarbuttonitem, target:self, action:"action:")
1071
- UIBarButtonitem.undo(&action) => UIBarButtonitem.alloc.initWithBarButtonSystemItem(:undo.uibarbuttonitem, target:self, action:"action:")
1072
- UIBarButtonitem.redo(&action) => UIBarButtonitem.alloc.initWithBarButtonSystemItem(:redo.uibarbuttonitem, target:self, action:"action:")
1073
- UIBarButtonitem.pagecurl(&action) => UIBarButtonitem.alloc.initWithBarButtonSystemItem(:pagecurl.uibarbuttonitem, target:self, action:"action:")
1088
+ # You can also specify a style.
1089
+ UIBarButtonItem.imaged('close'.uiimage, :plain.uibarbuttonstyle) {
1090
+ self.dismissViewControllerAnimated true, completion:nil
1091
+ }
1092
+
1093
+ # Get an instance containing the specified array which contains a portrate image and a landscape iamge.
1094
+ UIBarButtonItem.imaged(['portrate'.uiimage, 'landscape'.uiimage) {
1095
+ self.dismissViewControllerAnimated true, completion:nil
1096
+ }
1097
+ # =>
1098
+ UIBarButtonItem.alloc.initWithImage('portrate'.uiimage, landscapeImagePhone:'landscape'.uiimage, style: :bordered.uibarbuttonstyle, target:self, action:"action:")
1074
1099
  ```
1075
1100
 
1076
1101
  NSNotificationCenter
@@ -0,0 +1,67 @@
1
+ module SugarCube
2
+ module DateParser
3
+ # Parse a date string: E.g.:
4
+ #
5
+ # SugarCube::DateParser.parse_date "There is a date in here tomorrow at 9:00 AM"
6
+ #
7
+ # => 2013-02-20 09:00:00 -0800
8
+ def self.parse_date(date_string)
9
+ detect(date_string).first.date
10
+ end
11
+
12
+ # Parse time zone from date
13
+ #
14
+ # SugarCube::DateParser.parse_date "There is a date in here tomorrow at 9:00 AM EDT"
15
+ #
16
+ # Caveat: This is implemented per Apple documentation. I've never really
17
+ # seen it work.
18
+ def self.parse_time_zone(date_string)
19
+ detect(date_string).first.timeZone
20
+ end
21
+
22
+ # Parse a date string: E.g.:
23
+ #
24
+ # SugarCube::DateParser.parse_date "You have a meeting from 9:00 AM to 3:00 PM"
25
+ #
26
+ # => 21600.0
27
+ #
28
+ # Divide by 3600.0 to get number of hours duration.
29
+ def self.parse_duration(date_string)
30
+ detect(date_string).first.duration
31
+ end
32
+
33
+ # Parse a date into a raw match array for further processing
34
+ def self.match(date_string)
35
+ detect(date_string)
36
+ end
37
+
38
+ private
39
+ def self.detect(date_string)
40
+ error = Pointer.new(:object)
41
+ detector = NSDataDetector.dataDetectorWithTypes(NSTextCheckingTypeDate, error:error)
42
+ matches = detector.matchesInString(date_string, options:0, range:NSMakeRange(0, date_string.length))
43
+ end
44
+ end
45
+ end
46
+
47
+ class String
48
+ # Use NSDataDetector to parse a string containing a date
49
+ # or duration. These can be of the form:
50
+ #
51
+ # "tomorrow at 7:30 PM"
52
+ # "11.23.2013"
53
+ # "from 7:30 to 10:00 AM"
54
+ #
55
+ # etc.
56
+ def to_date
57
+ SugarCube::DateParser.parse_date(self)
58
+ end
59
+
60
+ def to_timezone
61
+ SugarCube::DateParser.parse_timezone(self)
62
+ end
63
+
64
+ def to_duration
65
+ SugarCube::DateParser.parse_duration(self)
66
+ end
67
+ end
@@ -97,6 +97,14 @@ class UIBarButtonItem
97
97
  def pagecurl(&action)
98
98
  sugarcube_barbuttonitem :pagecurl.uibarbuttonitem, action
99
99
  end
100
+
101
+ def titled(title, style = :bordered.uibarbuttonstyle, &action)
102
+ sugarcube_barbuttonitem_with_title(title, style, action)
103
+ end
104
+
105
+ def imaged(image, style = :bordered.uibarbuttonstyle, &action)
106
+ sugarcube_barbuttonitem_with_image(image, style, action)
107
+ end
100
108
 
101
109
  end
102
110
 
@@ -116,6 +124,23 @@ private
116
124
  b
117
125
  end
118
126
 
127
+ def self.sugarcube_barbuttonitem_with_title(title, style, action)
128
+ b = UIBarButtonItem.alloc.initWithTitle title, style:style, target:nil, action:nil
129
+ b.set_target_and_action b, action
130
+ b
131
+ end
132
+
133
+ def self.sugarcube_barbuttonitem_with_image(image, style, action)
134
+ case image
135
+ when Array
136
+ b = UIBarButtonItem.alloc.initWithImage image.first, landscapeImagePhone:image.last, style:style, target:nil, action:nil
137
+ else
138
+ b = UIBarButtonItem.alloc.initWithImage image, style:style, target:nil, action:nil
139
+ end
140
+ b.set_target_and_action b, action
141
+ b
142
+ end
143
+
119
144
  def sugarcube_handle_action(sender)
120
145
  handler = @sugarcube_action
121
146
  if handler.arity == 0
@@ -157,7 +157,7 @@ class UIView
157
157
  options[:after] = after
158
158
 
159
159
  animate(options) {
160
- self.layer.opacity = options[:opacity]
160
+ self.alpha = options[:opacity]
161
161
  }
162
162
  end
163
163
 
@@ -192,11 +192,11 @@ class UIView
192
192
  options = { duration: options }
193
193
  end
194
194
 
195
- original_opacity = self.layer.opacity
195
+ original_opacity = self.alpha
196
196
 
197
197
  after_remove = proc {
198
198
  removeFromSuperview
199
- self.layer.opacity = original_opacity
199
+ self.alpha = original_opacity
200
200
  after.call if after
201
201
  }
202
202
 
@@ -1,3 +1,3 @@
1
1
  module SugarCube
2
- Version = '0.18.17'
2
+ Version = '0.18.18'
3
3
  end
@@ -0,0 +1,26 @@
1
+ describe "Base Methods" do
2
+ it "parses a relative natural language string, returning a date" do
3
+ today = Time.now
4
+ t = SugarCube::DateParser.parse_date("tomorrow at 7:30 PM")
5
+ t.should.is_a Time
6
+ t.hour.should == 19
7
+ t.min.should == 30
8
+ t.sec.should == 0
9
+ (t.day - today.day).should == 1
10
+ end
11
+
12
+ it "parses a specific natural language string, returning a date" do
13
+ t = SugarCube::DateParser.parse_date("6/18/13 at 7:30 AM")
14
+ t.month.should == 6
15
+ t.day.should == 18
16
+ t.year.should == 2013
17
+ t.hour.should == 7
18
+ t.min.should == 30
19
+ end
20
+ end
21
+
22
+ describe "String Extensions" do
23
+ it "parses a date the same as the base method" do
24
+ "tomorrow at 7:30 PM".to_date.should == SugarCube::DateParser.parse_date("tomorrow at 7:30 PM")
25
+ end
26
+ end
@@ -1,5 +1,6 @@
1
1
  describe UIBarButtonItem do
2
2
 
3
+ # with system item
3
4
  it 'should be :done' do
4
5
  b = UIBarButtonItem.done {
5
6
  @result = :done
@@ -192,4 +193,47 @@ describe UIBarButtonItem do
192
193
  @result.should == :pagecurl
193
194
  end
194
195
 
196
+ # with title
197
+ it 'should be :titled' do
198
+ b = UIBarButtonItem.titled('title') {
199
+ @result = :titled
200
+ }
201
+ b.target.send b.action, b
202
+ @result.should == :titled
203
+ end
204
+
205
+ it 'should be :titled_with_style' do
206
+ b = UIBarButtonItem.titled('title', :plain.uibarbuttonstyle) {
207
+ @result = :titled_with_style
208
+ }
209
+ b.target.send b.action, b
210
+ @result.should == :titled_with_style
211
+ end
212
+
213
+ it 'should be :imaged' do
214
+ b = UIBarButtonItem.imaged('little_square'.uiimage) {
215
+ @result = :imaged
216
+ }
217
+ b.target.send b.action, b
218
+ @result.should == :imaged
219
+ end
220
+
221
+ it 'should be :imaged_with_style' do
222
+ b = UIBarButtonItem.imaged('little_square'.uiimage, :plain.uibarbuttonstyle) {
223
+ @result = :imaged_with_style
224
+ }
225
+ b.target.send b.action, b
226
+ @result.should == :imaged_with_style
227
+ end
228
+
229
+ it 'should be :imaged_with_images' do
230
+ b = UIBarButtonItem.imaged(['little_square'.uiimage, 'little_square'.uiimage]) {
231
+ @result = :imaged_with_images
232
+ }
233
+ b.target.send b.action, b
234
+ @result.should == :imaged_with_images
235
+ end
236
+
237
+
238
+
195
239
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sugarcube
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.18.17
4
+ version: 0.18.18
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2013-02-27 00:00:00.000000000 Z
16
+ date: 2013-03-07 00:00:00.000000000 Z
17
17
  dependencies: []
18
18
  description: ! '== Description
19
19
 
@@ -64,6 +64,7 @@ files:
64
64
  - lib/sugarcube/calayer.rb
65
65
  - lib/sugarcube/core_graphics.rb
66
66
  - lib/sugarcube/core_location.rb
67
+ - lib/sugarcube/date_parser.rb
67
68
  - lib/sugarcube/exceptions.rb
68
69
  - lib/sugarcube/fixnum.rb
69
70
  - lib/sugarcube/modal.rb
@@ -127,6 +128,7 @@ files:
127
128
  - spec/calayer_spec.rb
128
129
  - spec/core_graphics_spec.rb
129
130
  - spec/core_location_spec.rb
131
+ - spec/date_parser_spec.rb
130
132
  - spec/fixnum_spec.rb
131
133
  - spec/notification_spec.rb
132
134
  - spec/nsarray_spec.rb
@@ -173,7 +175,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
173
175
  version: '0'
174
176
  requirements: []
175
177
  rubyforge_project:
176
- rubygems_version: 1.8.24
178
+ rubygems_version: 1.8.25
177
179
  signing_key:
178
180
  specification_version: 3
179
181
  summary: Extensions for Ruby to make Rubymotion development more enjoyable, and hopefully
@@ -185,6 +187,7 @@ test_files:
185
187
  - spec/calayer_spec.rb
186
188
  - spec/core_graphics_spec.rb
187
189
  - spec/core_location_spec.rb
190
+ - spec/date_parser_spec.rb
188
191
  - spec/fixnum_spec.rb
189
192
  - spec/notification_spec.rb
190
193
  - spec/nsarray_spec.rb
@@ -210,4 +213,3 @@ test_files:
210
213
  - spec/uiview_attr_updates_spec.rb
211
214
  - spec/uiview_spec.rb
212
215
  - spec/unholy_spec.rb
213
- has_rdoc: