sugarcube 0.13 → 0.13.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
@@ -141,6 +141,20 @@ decoder.int(key)
141
141
  decoder.point(key)
142
142
  decoder.rect(key)
143
143
  decoder.size(key)
144
+ ```
145
+
146
+ NSData
147
+ ------
148
+
149
+ Going to and from `NSData` is really useful when doing HTTP posts.
150
+
151
+ ```ruby
152
+ string_data = 'String'.nsdata # => default encoding is UTF8.
153
+ image = 'an image'.uiimage
154
+ image_data = image.nsdata # PNG data representation
155
+
156
+ string_data.nsstring # => 'String'
157
+ image_data.nsimage # => whatever 'an image' was
144
158
  ```
145
159
 
146
160
  NSDate
@@ -294,6 +308,22 @@ The `delta` method is smart.
294
308
  # unfortunately you will, in the edge cases, end up with stuff like this:
295
309
  (main)> feb_28_2012 == feb_28_2012.delta(days:1, months:12).delta(months:-12)
296
310
  => true
311
+ ```
312
+
313
+ NSError
314
+ -------
315
+
316
+ `NSError.new` was just a mess, so I made it a legal method.
317
+
318
+ ```ruby
319
+ NSError.new('Error Message') # code: 0, domain: 'Error'
320
+ # with options
321
+ NSError.new('Error Message', code: 404)
322
+
323
+ # error messages ('Error Message' in this example) are stored in a Hash with the
324
+ # key 'NSLocalizedDescriptionKey'. If you pass a `userInfo` option, it will get
325
+ # merged with this array. So you can ignore that ugly-looking key.
326
+ NSError.new('Error Message', code: 404, userInfo: { warnings: ['blabla'] })
297
327
  ```
298
328
 
299
329
  NSURL
@@ -332,6 +362,7 @@ The `delta` method is smart.
332
362
  # file location
333
363
  "my.plist".exists? # => NSFileManager.defaultManager.fileExistsAtPath("my.plist")
334
364
  "my.plist".document # => NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, true)[0].stringByAppendingPathComponent("my.plist")
365
+ "my.plist".remove! # => NSFileManager.defaultManager.removeItemAtPath("my.plist".document, error: error) (returns error, if any occurred)
335
366
 
336
367
  # NSURL
337
368
  "https://github.com".nsurl # => NSURL.URLWithString("https://github.com")
@@ -486,6 +517,7 @@ UIActionSheet.alert 'I mean, is this cool?', buttons: ['Nah', 'With fire!', 'Sur
486
517
  ```ruby
487
518
  UIView.first_responder # => returns the first responder, starting at UIApplication.sharedApplication.keyWindow
488
519
  my_view.first_responder # => also returns the first responder, but starts looking in my_view
520
+ my_view.controller # => returns the UIViewController that this view belongs to
489
521
  self.view << subview # => self.view.addSubview(subview)
490
522
  self.view.show # => self.hidden = false
491
523
  self.view.hide # => self.hidden = true
@@ -548,14 +580,21 @@ UIButton.contact_add => UIButton.buttonWithType(:contact_add.uibuttontype)
548
580
 
549
581
  ###### UITableView
550
582
 
583
+ Default frame is `[[0, 0], [0, 0]]`, but most containers will resize it to be
584
+ the correct size. But heads up, it *used* to be `[[0, 0], [320, 480]]` (until
585
+ the iphone 5 / 4-inch retina came out).
586
+
551
587
  ```ruby
588
+ UITableView.alloc.initWithFrame([[0, 0], [0, 0]], style: :plain.uitableviewstyle)
552
589
  UITableView.alloc.initWithFrame([[0, 0], [320, 480]], style: :plain.uitableviewstyle)
590
+ UITableView.alloc.initWithFrame([[0, 0], [320, 568]], style: :plain.uitableviewstyle)
553
591
  # custom frame:
554
592
  UITableView.alloc.initWithFrame([[0, 0], [320, 400]], style: :grouped.uitableviewstyle)
555
593
 
556
594
  # =>
557
-
558
595
  UITableView.plain
596
+ UITableView.plain([[0, 0], [320, 480]])
597
+ UITableView.plain([[0, 0], [320, 568]])
559
598
  # custom frame:
560
599
  UITableView.grouped([[0, 0], [320, 400]])
561
600
  ```
@@ -744,6 +783,8 @@ end
744
783
  # other time-related methods
745
784
  # for compatibility with Time methods, the mins/secs (and min/sec) aliases are provided. Personally,
746
785
  # I like the more verbose minutes/seconds.
786
+ 1.millisecond || 2.milliseconds
787
+ 1.millisec || 2.millisecs
747
788
  1.second || 2.seconds
748
789
  1.sec || 2.secs # aliases
749
790
  1.minute || 2.minutes # 1.minute = 60 seconds
@@ -762,9 +803,22 @@ date1.today?
762
803
  date2.same_day? date1
763
804
  ```
764
805
 
765
- NSUserDefaults
806
+ NSUserDefaults
766
807
  ----------------
767
808
 
809
+ This file does *one* thing very **DANGEROUS**... to "help" with defaults.
810
+
811
+ When storing `nil` into `NSUserDefaults`, it is converted into `false`, because
812
+ Cocoa complains if you give it `nil`, and the RubyMotion runtime refuses to
813
+ allow the `NSNull.null` object. Without relying on an external project (like
814
+ [nsnulldammit]<https://github.com/colinta/nsnulldammit>) I don't know of a
815
+ sensible workaround...
816
+
817
+ If you want to "tap into" the defaults system that SugarCube uses, add a
818
+ `to_nsuserdefaults` method an that will get called if you hand your object to
819
+ `NSUserDefaults[]=`. However, there's no way to get it *back* later, so the
820
+ usefulness of this is very limited.
821
+
768
822
  ```ruby
769
823
  'key'.set_default(['any', 'objects']) # => NSUserDefaults.standardUserDefaults.setObject(['any', 'objects'], forKey: :key)
770
824
  'key'.get_default # => NSUserDefaults.standardUserDefaults.objectForKey(:key)
@@ -5,4 +5,4 @@ class CALayer
5
5
  return self
6
6
  end
7
7
 
8
- end
8
+ end
@@ -1,21 +1,22 @@
1
1
  module SugarCube
2
2
  module Modal
3
3
  module_function
4
- def present_modal(view_ctlr, target=nil, &block)
5
- target ||= UIApplication.sharedApplication.keyWindow.rootViewController
6
- target.presentViewController(view_ctlr, animated:true, completion:block)
4
+ def present_modal(view_ctlr, options={}, &block)
5
+ target = options.fetch(:target, UIApplication.sharedApplication.keyWindow.rootViewController)
6
+ animated = options.fetch(:animated, true)
7
+ target.presentViewController(view_ctlr, animated:animated, completion:block)
7
8
  end
8
9
 
9
- def present_modal_in_nav(view_ctlr, target=nil, &block)
10
+ def present_modal_in_nav(view_ctlr, options={}, &block)
10
11
  ctlr = UINavigationController.alloc.initWithRootViewController(view_ctlr)
11
12
  ctlr.modalTransitionStyle = UIModalTransitionStyleCoverVertical
12
13
 
13
- SugarCube::Modal.present_modal(ctlr, target, &block)
14
+ SugarCube::Modal.present_modal(ctlr, options, &block)
14
15
  ctlr
15
16
  end
16
17
 
17
- def dismiss_modal(target=nil, &block)
18
- target ||= UIApplication.sharedApplication.keyWindow.rootViewController
18
+ def dismiss_modal(options={}, &block)
19
+ target = options.fetch(:target, UIApplication.sharedApplication.keyWindow.rootViewController)
19
20
  target.dismissViewControllerAnimated(true, completion:block)
20
21
  end
21
22
  end
@@ -24,16 +25,19 @@ end
24
25
 
25
26
  class UIViewController
26
27
 
27
- def present_modal(view_ctlr, &block)
28
- SugarCube::Modal.present_modal(view_ctlr, self, &block)
28
+ def present_modal(view_ctlr, options={}, &block)
29
+ options = options.merge(target: self)
30
+ super(view_ctlr, options, &block)
29
31
  end
30
32
 
31
- def present_modal_in_nav(view_ctlr, &block)
32
- SugarCube::Modal.present_modal_in_nav(view_ctlr, self, &block)
33
+ def present_modal_in_nav(view_ctlr, options={}, &block)
34
+ options = options.merge(target: self)
35
+ super(view_ctlr, options, &block)
33
36
  end
34
37
 
35
- def dismiss_modal(view_ctlr, &block)
36
- SugarCube::Modal.dismiss_modal(view_ctlr, self, &block)
38
+ def dismiss_modal(view_ctlr, options={}, &block)
39
+ options = options.merge(target: self)
40
+ super(view_ctlr, options, &block)
37
41
  end
38
42
 
39
43
  end
@@ -553,7 +553,7 @@ class Symbol
553
553
  def uiautoresizemask
554
554
  look_in(Symbol.autoresizemasks)
555
555
  end
556
- alias uiviewautoresizing uiautoresize
556
+ alias uiviewautoresizing uiautoresizemask
557
557
  alias uiautoresizingmask uiautoresizemask
558
558
  alias uiautoresize uiautoresizemask
559
559
 
@@ -1,6 +1,5 @@
1
1
  class UIColor
2
2
  def uicolor ; self ; end
3
- alias cgcolor CGColor
4
3
 
5
4
  def red
6
5
  _sugarcube_colors[:red]
@@ -153,8 +153,11 @@ class UIView
153
153
  options = { duration: options }
154
154
  end
155
155
 
156
+ original_opacity = self.layer.opacity
157
+
156
158
  after_remove = proc {
157
159
  removeFromSuperview
160
+ self.layer.opacity = original_opacity
158
161
  after.call if after
159
162
  }
160
163
 
@@ -1,3 +1,3 @@
1
1
  module SugarCube
2
- Version = '0.13'
2
+ Version = '0.13.2'
3
3
  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.13'
4
+ version: 0.13.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-12-27 00:00:00.000000000 Z
13
+ date: 2012-12-28 00:00:00.000000000 Z
14
14
  dependencies: []
15
15
  description: ! '== Description
16
16