sugarcube 0.18.1 → 0.18.2

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/README.md CHANGED
@@ -160,7 +160,7 @@ And you can easily turn this into a label!
160
160
  ```ruby
161
161
  view << (("We just met\n".attrd +
162
162
  "and this is " + "CRAZY".italic + "\n"
163
- "But here's my " + "id_rsa.pub".code + " file,\n" +
163
+ "But here's my " + "id_rsa.pub".monospace + " file,\n" +
164
164
  "so give me SSH access.").uilabel
165
165
  ```
166
166
 
@@ -176,7 +176,7 @@ self.value = decoder['key']
176
176
 
177
177
  # but if you want to store booleans and such (in their C form,
178
178
  # which will take up less space I suppose):
179
- coder.set('sugarcube_is_neat', toBool:self.is_sugarcube_neat?)
179
+ coder.set('sugarcube_is_neat', toBool:self.sugarcube_is_neat?)
180
180
  self.sugarcube_is_neat = decoder.bool('sugarcube_is_neat')
181
181
 
182
182
  coder.set('number_of_things', toInt:self.number_of_things)
@@ -218,29 +218,30 @@ image_data.nsimage # => whatever 'an image' was
218
218
  --------
219
219
 
220
220
  `NSDate` objects are converted to `Time` objects automatically by rubymotion.
221
- That's the good news. The bad news? That still doesn't help a lot with some of
222
- the everyday date&time crap we have to deal with. (I hate dates, especially
221
+ That's the good news.
222
+ The bad news? That still doesn't help a lot with some of
223
+ the everyday date & time crap we have to deal with. (I hate dates, especially
223
224
  recurring events)
225
+ ##### NSDate
224
226
 
225
227
  1. Adds the following methods to get date and time components: `date_array, time_array, datetime_array`.
226
-
227
228
  These methods return arrays. Comparing dates, times, or both become
228
229
  simple `date1.date_array == date2.date_array`.
229
230
  2. While I would love to support `date + 1.month` and have that support "smart"
230
231
  calendar math (e.g. "2/13/2013" + 1.month => "3/13/2013"), I can't fudge with
231
232
  the return value of `1.month` (=> `Fixnum`), and I won't make the terrible
232
233
  assumption that "30 days of seconds is *about* one month". So instead, a new
233
- method that accepts date components as options is introduced. `date.delta(month:1)`
234
- 3. Something that is often done is checking whether two dates are the same,
235
- ignoring the time components. `start_of_day` and `end_of_day` methods help
236
- you here. They are akin to `floor` and `ceil`, if you consider the time to
234
+ method that accepts date components as options is introduced: `date.delta(months:1)`
235
+ 3. Checking whether two dates are the same, ignoring the time components, is often required
236
+ `start_of_day` and `end_of_day` methods help
237
+ you here. They are akin to `floor` and `ceil`; if you consider the time to
237
238
  be the "floating" component, and the date to be the nearest "integer".
238
239
  4. Formatting is made easier with `NSDate#string_with_style(NSDateStyleConstant or Symbol)`
239
240
  and `NSDate#string_with_format(format_string)`. See
240
241
  <http://www.unicode.org/reports/tr35/tr35-25.html#Date_Format_Patterns> for
241
242
  the formatters, they take getting used to, coming from `strftime`, but they
242
243
  are much more powerful and locale-aware.
243
- 5. Misc other helpers. I'll go over these first.
244
+ 5. Miscellaneous other helpers. I'll go over these first.
244
245
 
245
246
  ###### Helpers
246
247
 
@@ -262,8 +263,8 @@ recurring events)
262
263
  (main)> feb_1_2013.era
263
264
  => 1 # no, I don't know what this is :-/
264
265
  (main)> feb_1_2013.today?
265
- => false # actually, at the time i'm WRITING this, it IS true, but by the time
266
- # you read it, not so much ;-)
266
+ => false # actually, at the time I am WRITING this, it IS true, but by the time
267
+ # you read it, not so much ;-)
267
268
  (main)> NSDate.new.today?
268
269
  => true
269
270
  (main)> feb_1_2013.same_day?(NSDate.new)
@@ -307,7 +308,7 @@ recurring events)
307
308
  ```
308
309
 
309
310
  It is easy to add seconds to the date using the time-related methods added to
310
- `Numeric`, thought the `NSDate#delta` method is MUCH more capable.
311
+ `Numeric`, though the `NSDate#delta` method is MUCH more capable.
311
312
 
312
313
  ```ruby
313
314
  (main)> now + 5
@@ -388,7 +389,7 @@ on.
388
389
  (main)> feb_28_2012.delta(days:2, years:1)
389
390
  => 2013-03-01 17:00:00 -0700
390
391
 
391
- # Crazier: add a day (fab 29th), then a month (march 29th), THEN a year.
392
+ # Crazier: add a day (Feb 29th), then a month (March 29th), THEN a year.
392
393
  (main)> feb_28_2012.delta(days:1, years:1, months:1)
393
394
  => 2013-03-29 17:00:00 -0600
394
395
 
@@ -400,7 +401,7 @@ on.
400
401
  (main)> jan_29_2013.delta(months:2)
401
402
  => 2013-03-29 17:00:00 -0600
402
403
 
403
- # Yeah, smart guy? Well then what is 1/29/2013 plus ONE month. It's feb 28th.
404
+ # Yeah, smart guy? Well then what is 1/29/2013 plus ONE month. It's Feb 28th.
404
405
  # When someone says "see you in a month!" they mean "next month", not "in the
405
406
  # early part of two months in the future", which is where the math will take you
406
407
  # if you don't add a "day of month" correction.
@@ -623,11 +624,11 @@ form, you can pass just a title and block.
623
624
  UIAlertView.alert "This is happening, OK?" { self.happened! }
624
625
  # a little more complex
625
626
  UIAlertView.alert("This is happening, OK?", buttons: ["Nevermind", "OK"],
626
- message: "don't worry, it'll be fine.") {
627
+ message: "Don't worry, it'll be fine.") {
627
628
  self.happened!
628
629
  }
629
630
 
630
- # Full on whiz bangery. Note the success block takes the pressed button, but as
631
+ # Full on whiz-bangery. Note the success block takes the pressed button, but as
631
632
  # a string instead of an index. The cancel button should be the first entry in
632
633
  # `buttons:`
633
634
  UIAlertView.alert "I mean, is this cool?", buttons: %w[No! Sure! Hmmmm],
@@ -787,7 +788,6 @@ UIView.animation_chain {
787
788
 
788
789
  Chains can also be written like this:
789
790
 
790
-
791
791
  ```ruby
792
792
  chain = UIView.animation_chain
793
793
  chain << proc { view.slide(:left, 20) }
@@ -822,7 +822,7 @@ UIButton.contact_add => UIButton.buttonWithType(:contact_add.uibuttontype)
822
822
  ###### UITableView
823
823
 
824
824
  Default frame is `[[0, 0], [0, 0]]`, but most containers will resize it to be
825
- the correct size. But heads up, it *used* to be `[[0, 0], [320, 480]]` (until
825
+ the correct size. But heads up, it *was* `[[0, 0], [320, 480]]` (until
826
826
  the iphone 5 / 4-inch retina came out).
827
827
 
828
828
  ```ruby
@@ -840,7 +840,7 @@ UITableView.plain([[0, 0], [320, 568]])
840
840
  UITableView.grouped([[0, 0], [320, 400]])
841
841
  ```
842
842
 
843
- ###### UISegmentedControle
843
+ ###### UISegmentedControl
844
844
 
845
845
  ```ruby
846
846
  control = UISegmentedControl.alloc.initItems(["one", "ah-two-whoo", "thr-r-r-ree"])
@@ -909,8 +909,8 @@ dismiss_modal
909
909
  These accept completion blocks:
910
910
 
911
911
  ```ruby
912
- present_modal(view_ctlr) { puts "here!" }
913
- dismiss_modal { puts "gone!" }
912
+ present_modal(view_ctlr) { puts "Now You See Me!" }
913
+ dismiss_modal { puts "Now You Don't!" }
914
914
  ```
915
915
 
916
916
  If you like these methods, but you want to specify the reciever, they are
@@ -923,7 +923,7 @@ controller.present_modal(other_controller) { puts "presented" }
923
923
  UINavigationController
924
924
  ------------------------
925
925
 
926
- `push`/`<<` and `pop` instead of `pushViewController` and `popViewController`.
926
+ `push`, `<<` and `pop` instead of `pushViewController` and `popViewController`.
927
927
  `!` and `!(view)` instead of `popToRootViewController` and `popToViewController`
928
928
 
929
929
  animated is `true` for all these.
@@ -940,7 +940,7 @@ nav_ctlr.!(another_view_ctlr)
940
940
  ------------------------
941
941
 
942
942
  I have mixed feelings about adding this extension, but **I** needed it, so maybe
943
- you will, too... Usually `UITabBarController`s have a static number of tabs,
943
+ you will, too... Usually a `UITabBarController` has a static number of tabs,
944
944
  but in my case, I needed to be able to add one later, when a certain condition
945
945
  was met.
946
946
 
@@ -1059,11 +1059,11 @@ This file does *one* thing very **DANGEROUS**... to "help" with defaults.
1059
1059
  When storing `nil` into `NSUserDefaults`, it is converted into `false`, because
1060
1060
  Cocoa complains if you give it `nil`, and the RubyMotion runtime refuses to
1061
1061
  allow the `NSNull.null` object. Without relying on an external project (like
1062
- [nsnulldammit]<https://github.com/colinta/nsnulldammit>) I don't know of a
1062
+ [nsnulldammit](https://github.com/colinta/nsnulldammit) I don't know of a
1063
1063
  sensible workaround...
1064
1064
 
1065
1065
  If you want to "tap into" the defaults system that SugarCube uses, add a
1066
- `to_nsuserdefaults` method an that will get called if you hand your object to
1066
+ `to_nsuserdefaults` method and that will get called if you hand your object to
1067
1067
  `NSUserDefaults[]=`. However, there's no way to get it *back* later, so the
1068
1068
  usefulness of this is very limited.
1069
1069
 
@@ -1071,7 +1071,7 @@ usefulness of this is very limited.
1071
1071
  'key'.set_default(['any', 'objects']) # => NSUserDefaults.standardUserDefaults.setObject(['any', 'objects'], forKey: :key)
1072
1072
  'key'.get_default # => NSUserDefaults.standardUserDefaults.objectForKey(:key)
1073
1073
 
1074
- # symbols are converted to strings, so theses are equivalent
1074
+ # symbols are converted to strings, so these are equivalent
1075
1075
  :key.set_default(['any', 'objects']) # => NSUserDefaults.standardUserDefaults.setObject(['any', 'objects'], forKey: :key)
1076
1076
  :key.get_default # => NSUserDefaults.standardUserDefaults.objectForKey(:key)
1077
1077
  ```
@@ -1231,6 +1231,7 @@ The most useful feature of the REPL adjustment is the ability to quickly
1231
1231
  position and size your UI elements __visually__ and then paste the final values
1232
1232
  into your code. In order to better accomodate that, `adjust` has an option to
1233
1233
  modify the output format.
1234
+ These were inspired by [Thom Parkin](https://github.com/ParkinT)
1234
1235
 
1235
1236
  This better facilitates copy/paste of the values. Currently supported is:
1236
1237
  * Default (RubyMotion) (`nil`, `:default`)
@@ -1481,7 +1482,7 @@ use these everywhere. :poop:
1481
1482
 
1482
1483
  ### `ivar`
1483
1484
 
1484
- ###### Rackfile
1485
+ ###### Rakefile
1485
1486
 
1486
1487
  ```ruby
1487
1488
  require 'sugarcube-unholy'
@@ -207,7 +207,7 @@ class Symbol
207
207
  system: :"systemFontOfSize:",
208
208
  bold: :"boldSystemFontOfSize:",
209
209
  italic: :"italicSystemFontOfSize:",
210
- monospace: 'Monaco',
210
+ monospace: 'Courier New',
211
211
  }
212
212
 
213
213
  @font_sizes = {
@@ -398,20 +398,32 @@ class Symbol
398
398
  @autoresizemasks = {
399
399
  none: UIViewAutoresizingNone,
400
400
 
401
- flexibleleft: UIViewAutoresizingFlexibleLeftMargin,
402
- flexiblewidth: UIViewAutoresizingFlexibleWidth,
403
- flexibleright: UIViewAutoresizingFlexibleRightMargin,
404
- flexibletop: UIViewAutoresizingFlexibleTopMargin,
405
- flexibleheight: UIViewAutoresizingFlexibleHeight,
406
- flexiblebottom: UIViewAutoresizingFlexibleBottomMargin,
407
-
408
- # aliases
409
- left: UIViewAutoresizingFlexibleLeftMargin,
410
- width: UIViewAutoresizingFlexibleWidth,
411
- right: UIViewAutoresizingFlexibleRightMargin,
412
- top: UIViewAutoresizingFlexibleTopMargin,
413
- height: UIViewAutoresizingFlexibleHeight,
414
- bottom: UIViewAutoresizingFlexibleBottomMargin,
401
+ flexible_left: UIViewAutoresizingFlexibleLeftMargin,
402
+ flexible_width: UIViewAutoresizingFlexibleWidth,
403
+ flexible_right: UIViewAutoresizingFlexibleRightMargin,
404
+ flexible_top: UIViewAutoresizingFlexibleTopMargin,
405
+ flexible_height: UIViewAutoresizingFlexibleHeight,
406
+ flexible_bottom: UIViewAutoresizingFlexibleBottomMargin,
407
+
408
+ # shorthands
409
+ full: UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight,
410
+ fixed_top: UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin,
411
+ fixed_bottom: UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin,
412
+ fixed_left: UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleRightMargin,
413
+ fixed_right: UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleLeftMargin,
414
+
415
+ fixed_top_left: UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin,
416
+ fixed_top_middle: UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin,
417
+ fixed_top_right: UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleBottomMargin,
418
+ fixed_middle_left: UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleRightMargin,
419
+ fixed_middle: UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin,
420
+ fixed_middle_right: UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin,
421
+ fixed_bottom_left: UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin,
422
+ fixed_bottom_middle: UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin,
423
+ fixed_bottom_right: UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleTopMargin,
424
+
425
+ float_horizontal: UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin,
426
+ float_vertical: UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin,
415
427
  }
416
428
 
417
429
  @image_sourcetypes = {
@@ -660,24 +672,24 @@ class Symbol
660
672
  # system fonts
661
673
  if Symbol.system_fonts.has_key? self
662
674
  font = look_in(Symbol.system_fonts)
663
- if size.is_a? Symbol
675
+ if size.is_a?(Symbol)
664
676
  size = Symbol.font_sizes.fetch(size).uifontsize
665
677
  end
678
+
666
679
  if font.is_a?(Symbol)
667
- font = UIFont.send(font, size)
680
+ return UIFont.send(font, size)
668
681
  else
669
- font.uifont(size)
682
+ return font.uifont(size)
670
683
  end
671
684
  else
672
685
  size = look_in(font_sizes).uifontsize
673
- font = UIFont.systemFontOfSize(size)
686
+ return UIFont.systemFontOfSize(size)
674
687
  end
675
- font
676
688
  end
677
689
 
678
690
  def uifontsize
679
691
  size = look_in(Symbol.font_sizes)
680
- if size.is_a? Symbol
692
+ if size.is_a?(Symbol)
681
693
  return UIFont.send(size)
682
694
  end
683
695
  return size.to_f
@@ -4,30 +4,57 @@ class UIButton
4
4
  self.buttonWithType(:custom.uibuttontype)
5
5
  end
6
6
  def rounded
7
+ if self != UIButton
8
+ raise "Custom subclasses of UIButton most be created using UIButton.custom"
9
+ end
7
10
  self.buttonWithType(:rounded.uibuttontype)
8
11
  end
9
12
  def rounded_rect
13
+ if self != UIButton
14
+ raise "Custom subclasses of UIButton most be created using UIButton.custom"
15
+ end
10
16
  self.buttonWithType(:rounded_rect.uibuttontype)
11
17
  end
12
18
  def detail
19
+ if self != UIButton
20
+ raise "Custom subclasses of UIButton most be created using UIButton.custom"
21
+ end
13
22
  self.buttonWithType(:detail.uibuttontype)
14
23
  end
15
24
  def detail_disclosure
25
+ if self != UIButton
26
+ raise "Custom subclasses of UIButton most be created using UIButton.custom"
27
+ end
16
28
  self.buttonWithType(:detail_disclosure.uibuttontype)
17
29
  end
18
30
  def info
31
+ if self != UIButton
32
+ raise "Custom subclasses of UIButton most be created using UIButton.custom"
33
+ end
19
34
  self.buttonWithType(:info.uibuttontype)
20
35
  end
21
36
  def info_light
37
+ if self != UIButton
38
+ raise "Custom subclasses of UIButton most be created using UIButton.custom"
39
+ end
22
40
  self.buttonWithType(:info_light.uibuttontype)
23
41
  end
24
42
  def info_dark
43
+ if self != UIButton
44
+ raise "Custom subclasses of UIButton most be created using UIButton.custom"
45
+ end
25
46
  self.buttonWithType(:info_dark.uibuttontype)
26
47
  end
27
48
  def contact
49
+ if self != UIButton
50
+ raise "Custom subclasses of UIButton most be created using UIButton.custom"
51
+ end
28
52
  self.buttonWithType(:contact.uibuttontype)
29
53
  end
30
54
  def contact_add
55
+ if self != UIButton
56
+ raise "Custom subclasses of UIButton most be created using UIButton.custom"
57
+ end
31
58
  self.buttonWithType(:contact_add.uibuttontype)
32
59
  end
33
60
  end
@@ -1,3 +1,3 @@
1
1
  module SugarCube
2
- Version = '0.18.1'
2
+ Version = '0.18.2'
3
3
  end
@@ -0,0 +1,30 @@
1
+ describe "Symbol" do
2
+
3
+ describe "uifont" do
4
+ it "should work with system fonts" do
5
+ UIFont.should === :system.uifont
6
+ UIFont.should === :bold.uifont
7
+ UIFont.should === :italic.uifont
8
+ end
9
+
10
+ it "should work with custom fonts" do
11
+ :monospace.uifont.should != nil
12
+ UIFont.should === :monospace.uifont
13
+ end
14
+
15
+ it "should allow customization" do
16
+ Symbol.system_fonts[:default] = 'Helvetica'
17
+ :default.uifont.tap do |subject|
18
+ UIFont.should === subject
19
+ subject.fontName.should == 'Helvetica'
20
+ end
21
+ end
22
+
23
+ it "should accept point size" do
24
+ :system.uifont(40).pointSize.should == 40
25
+ :bold.uifont(40).pointSize.should == 40
26
+ :italic.uifont(40).pointSize.should == 40
27
+ end
28
+
29
+ end
30
+ end
@@ -10,7 +10,7 @@ describe "UIView animation methods" do
10
10
  it 'should rotate 45 degrees' do
11
11
  angle = 45*Math::PI/180
12
12
  @view.rotate_to(angle)
13
- current_angle = Math.atan2(@view.transform.b, @view.transform.a)
13
+ current_angle = Math.atan2(@view.transform.b, @view.transform.a)
14
14
  current_angle.should == angle
15
15
  end
16
16
 
@@ -20,4 +20,38 @@ describe "UIView animation methods" do
20
20
  }
21
21
  CGRectEqualToRect(@view.frame, [[0, 0], [0, 0]]).should == true
22
22
  end
23
+
24
+ it 'should call the after block anything' do
25
+ @after_called = false
26
+ UIView.animate(after:->{ @after_called = true }, duration: 0.05) {
27
+ @view.frame = [[0, 0], [0, 0]]
28
+ @after_called = :animating
29
+ }
30
+ @after_called.should == :animating
31
+ wait 0.1 {
32
+ @after_called.should == true
33
+ }
34
+ end
35
+
36
+ it 'should animate if duration is 0 and delay > 0' do
37
+ @after_called = false
38
+ UIView.animate(after:->{ @after_called = true }, duration: 0.0, delay: 0.1) {
39
+ @view.frame = [[0, 0], [0, 0]]
40
+ @after_called = :animating
41
+ }
42
+ @after_called.should == :animating
43
+ wait 0.1 {
44
+ @after_called.should == true
45
+ }
46
+ end
47
+
48
+ it 'should not animate if duration is 0' do
49
+ @after_called = false
50
+ UIView.animate(after:->{ @after_called = true }, duration: 0.0) {
51
+ @view.frame = [[0, 0], [0, 0]]
52
+ @after_called = :animating
53
+ }
54
+ @after_called.should == true
55
+ end
56
+
23
57
  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.1
4
+ version: 0.18.2
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-16 00:00:00.000000000 Z
16
+ date: 2013-02-17 00:00:00.000000000 Z
17
17
  dependencies: []
18
18
  description: ! '== Description
19
19
 
@@ -137,6 +137,7 @@ files:
137
137
  - spec/nsstring_spec.rb
138
138
  - spec/nsurl_spec.rb
139
139
  - spec/numeric_spec.rb
140
+ - spec/symbol_spec.rb
140
141
  - spec/uicolor_components_spec.rb
141
142
  - spec/uicolor_css_spec.rb
142
143
  - spec/uicolor_spec.rb
@@ -192,6 +193,7 @@ test_files:
192
193
  - spec/nsstring_spec.rb
193
194
  - spec/nsurl_spec.rb
194
195
  - spec/numeric_spec.rb
196
+ - spec/symbol_spec.rb
195
197
  - spec/uicolor_components_spec.rb
196
198
  - spec/uicolor_css_spec.rb
197
199
  - spec/uicolor_spec.rb