sugarcube 0.18.21 → 0.19.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/README.md +53 -6
- data/lib/sugarcube/nsdate.rb +5 -5
- data/lib/sugarcube/nsstring.rb +6 -0
- data/lib/sugarcube/symbol.rb +48 -48
- data/lib/sugarcube/symbol/symbol_uicolor.rb +3 -0
- data/lib/sugarcube/uicolor.rb +38 -5
- data/lib/sugarcube/uiview.rb +32 -6
- data/lib/sugarcube/uiviewcontroller.rb +7 -2
- data/lib/sugarcube/version.rb +1 -1
- data/spec/nsattributedstring_spec.rb +6 -0
- data/spec/nsdate_spec.rb +10 -4
- data/spec/nsstring_spec.rb +5 -0
- data/spec/uicolor_spec.rb +39 -0
- data/spec/uiview_spec.rb +20 -0
- data/spec/uiviewcontroller_spec.rb +87 -0
- metadata +4 -2
data/README.md
CHANGED
@@ -240,7 +240,7 @@ recurring events)
|
|
240
240
|
`start_of_day` and `end_of_day` methods help
|
241
241
|
you here. They are akin to `floor` and `ceil`; if you consider the time to
|
242
242
|
be the "floating" component, and the date to be the nearest "integer".
|
243
|
-
4. Formatting is made easier with `NSDate#string_with_style(NSDateStyleConstant or Symbol)`
|
243
|
+
4. Formatting is made easier with `NSDate#string_with_style(NSDateStyleConstant or Symbol for date, time)`
|
244
244
|
and `NSDate#string_with_format(format_string)`. See
|
245
245
|
<http://www.unicode.org/reports/tr35/tr35-25.html#Date_Format_Patterns> for
|
246
246
|
the formatters, they take getting used to, coming from `strftime`, but they
|
@@ -302,13 +302,23 @@ recurring events)
|
|
302
302
|
=> [9, 19, 6]
|
303
303
|
(main)> now.datetime_array
|
304
304
|
=> [2012, 9, 13, 9, 19, 6]
|
305
|
+
```
|
306
|
+
|
307
|
+
Use `NSDate#string_with_style` to generate date and/or time strings.
|
305
308
|
|
309
|
+
```ruby
|
306
310
|
(main)> now.string_with_style
|
307
311
|
=> "January 29, 2013"
|
308
312
|
(main)> now.string_with_style(NSDateFormatterShortStyle)
|
309
313
|
=> "1/29/13"
|
310
314
|
(main)> now.string_with_style(:short)
|
311
315
|
=> "1/29/13"
|
316
|
+
(main)> now.string_with_style(NSDateFormatterMediumStyle, NSDateFormatterShortStyle)
|
317
|
+
=> "Jan 29, 2013, 9:19 AM"
|
318
|
+
(main)> now.string_with_style(:short, :medium)
|
319
|
+
=> "1/29/13, 9:19:06 AM"
|
320
|
+
(main)> now.string_with_style(:none, :long)
|
321
|
+
=> "9:19:06 AM GMT+01:00"
|
312
322
|
```
|
313
323
|
|
314
324
|
It is easy to add seconds to the date using the time-related methods added to
|
@@ -491,6 +501,9 @@ NSError.new('Error Message', code: 404, userInfo: { warnings: ['blabla'] })
|
|
491
501
|
|
492
502
|
# NSURL
|
493
503
|
"https://github.com".nsurl # => NSURL.URLWithString("https://github.com")
|
504
|
+
|
505
|
+
# check if string is not a number
|
506
|
+
"pi".nan? # => NSNumberFormatter.alloc.init.numberFromString("pi").nil?
|
494
507
|
```
|
495
508
|
|
496
509
|
NSIndexPath
|
@@ -671,6 +684,30 @@ UIActionSheet.alert 'I mean, is this cool?', buttons: ['Nah', 'With fire!', 'Sur
|
|
671
684
|
success: proc { |pressed| self.proceed if pressed == 'Sure' }
|
672
685
|
```
|
673
686
|
|
687
|
+
UIColor
|
688
|
+
---------
|
689
|
+
|
690
|
+
Methods to merge or manipulate a color, or to get information about a color.
|
691
|
+
Works best on RGB colors, but HSB will work well, too. `UIColor`s based on
|
692
|
+
image patterns can't easily be inverted or mixed.
|
693
|
+
|
694
|
+
```ruby
|
695
|
+
:red.uicolor.invert # => UIColor.cyanColor
|
696
|
+
:blue.uicolor.invert # => UIColor.yellowColor
|
697
|
+
:green.uicolor.invert # => UIColor.magentaColor
|
698
|
+
:red.uicolor + :blue.uicolor # => UIColor.purpleColor
|
699
|
+
:red.uicolor + :green.uicolor # => :olive.uicolor
|
700
|
+
# (I didn't know that until I tried it in the REPL, but it was pretty cool to
|
701
|
+
# see the UIColor#to_s method match that mixture to olive!)
|
702
|
+
|
703
|
+
# a more generic color mixing method (`+` delegates to this method):
|
704
|
+
:white.uicolor.mix_with(:black.uicolor, 0) # => :white
|
705
|
+
:white.uicolor.mix_with(:black.uicolor, 0.25) # => 0x404040.uicolor
|
706
|
+
:white.uicolor.mix_with(:black.uicolor, 0.5) # => :gray, same as :white + :black
|
707
|
+
:white.uicolor.mix_with(:black.uicolor, 0.75) # => 0xbfbfbf.uicolor
|
708
|
+
:white.uicolor.mix_with(:black.uicolor, 1) # => :black
|
709
|
+
```
|
710
|
+
|
674
711
|
UIView
|
675
712
|
--------
|
676
713
|
|
@@ -684,6 +721,10 @@ self.view.hide # => self.hidden = true
|
|
684
721
|
|
685
722
|
# convert to UIImage. retina-ready.
|
686
723
|
my_view.uiimage
|
724
|
+
# that will use the `bounds` property to size the image. but if you want a
|
725
|
+
# screen shot of the contents of a scroll view, pass in `true` or `:all` to this
|
726
|
+
# method.
|
727
|
+
my_scroll_view.uiimage(:all)
|
687
728
|
```
|
688
729
|
|
689
730
|
When defining a UIView subclass, you often have attributes that affect your
|
@@ -973,16 +1014,22 @@ controller.present_modal(other_controller) { puts "presented" }
|
|
973
1014
|
------------------------
|
974
1015
|
|
975
1016
|
`push`, `<<` and `pop` instead of `pushViewController` and `popViewController`.
|
976
|
-
`!` and `!(view)` instead of `popToRootViewController` and `popToViewController`
|
977
1017
|
|
978
1018
|
animated is `true` for all these.
|
979
1019
|
|
1020
|
+
`pop` accepts an argument: either a view controller to pop to, or the symbol
|
1021
|
+
`:root` which does what you might expect
|
1022
|
+
|
980
1023
|
```ruby
|
981
|
-
nav_ctlr
|
1024
|
+
nav_ctlr << root_ctlr
|
1025
|
+
# or nav_ctlr.push(root_ctlr)
|
982
1026
|
nav_ctlr << new_ctlr
|
983
|
-
|
984
|
-
nav_ctlr
|
985
|
-
nav_ctlr
|
1027
|
+
# ... imagine we push on a ton of controllers ...
|
1028
|
+
nav_ctlr << another_ctlr
|
1029
|
+
nav_ctlr << last_ctlr
|
1030
|
+
nav_ctlr.pop # => pops to another_ctlr, because it's next on the stack
|
1031
|
+
nav_ctlr.pop new_ctlr # => pops to new_ctlr
|
1032
|
+
nav_ctlr.pop :root # => pops to root_ctlr, because it's on the bottom
|
986
1033
|
```
|
987
1034
|
|
988
1035
|
UITabBarController
|
data/lib/sugarcube/nsdate.rb
CHANGED
@@ -9,12 +9,12 @@ class NSDate
|
|
9
9
|
return calendar.dateFromComponents(date_components)
|
10
10
|
end
|
11
11
|
|
12
|
-
def string_with_style(
|
12
|
+
def string_with_style(date_style=NSDateFormatterMediumStyle,time_style=NSDateFormatterNoStyle)
|
13
13
|
date_formatter = NSDateFormatter.new
|
14
|
-
if
|
15
|
-
|
16
|
-
|
17
|
-
date_formatter.
|
14
|
+
date_style = date_style.nsdatestyle if date_style.is_a? Symbol
|
15
|
+
time_style = time_style.nsdatestyle if time_style.is_a? Symbol
|
16
|
+
date_formatter.setDateStyle(date_style)
|
17
|
+
date_formatter.setTimeStyle(time_style)
|
18
18
|
date_formatter.stringFromDate(self)
|
19
19
|
end
|
20
20
|
|
data/lib/sugarcube/nsstring.rb
CHANGED
@@ -71,6 +71,12 @@ class NSString
|
|
71
71
|
)
|
72
72
|
end
|
73
73
|
|
74
|
+
# @return boolean
|
75
|
+
def nan?
|
76
|
+
number_formatter = NSNumberFormatter.new
|
77
|
+
number = number_formatter.numberFromString(self)
|
78
|
+
number.nil?
|
79
|
+
end
|
74
80
|
# This can be called as `"Hello".localized` or `"Hello"._`. The `str._`
|
75
81
|
# syntax is meant to be reminiscent of gettext-style `_(str)`.
|
76
82
|
def localized(value=nil, table=nil)
|
data/lib/sugarcube/symbol.rb
CHANGED
@@ -24,54 +24,54 @@ You can extend the defaults by adding entries:
|
|
24
24
|
=end
|
25
25
|
class Symbol
|
26
26
|
class << self
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
27
|
+
attr :devices
|
28
|
+
attr :device_orientations
|
29
|
+
attr :interface_orientations
|
30
|
+
attr :interface_masks
|
31
|
+
attr :orientations
|
32
|
+
attr :returnkeys
|
33
|
+
attr :statusbar_styles
|
34
|
+
attr :barmetrics
|
35
|
+
attr :barbuttonitems
|
36
|
+
attr :barbuttonstyles
|
37
|
+
attr :keyboardtypes
|
38
|
+
attr :autoresizemasks
|
39
|
+
|
40
|
+
attr :textalignments
|
41
|
+
attr :linebreakmodes
|
42
|
+
attr :baselineadjustments
|
43
|
+
attr :system_fonts
|
44
|
+
attr :font_sizes
|
45
|
+
attr :date_styles
|
46
|
+
attr :number_styles
|
47
|
+
|
48
|
+
attr :buttontypes
|
49
|
+
attr :border_types
|
50
|
+
attr :control_states
|
51
|
+
attr :control_events
|
52
|
+
attr :activityindicator_styles
|
53
|
+
attr :segmented_styles
|
54
|
+
attr :datepicker_modes
|
55
|
+
attr :content_modes
|
56
|
+
|
57
|
+
attr :tableview_styles
|
58
|
+
attr :tableview_rowanimation
|
59
|
+
attr :tableview_cellstyles
|
60
|
+
attr :tableview_cellaccessorytype
|
61
|
+
attr :tableview_cellselectionstyle
|
62
|
+
attr :tableview_cellseparatorstyle
|
63
|
+
|
64
|
+
attr :image_sourcetypes
|
65
|
+
attr :image_capturemode
|
66
|
+
attr :image_cameradevice
|
67
|
+
attr :image_quality
|
68
|
+
|
69
|
+
attr :ca_timingfunctions
|
70
|
+
|
71
|
+
attr :cg_linecapstyles
|
72
|
+
attr :cg_linejoinstyles
|
73
|
+
|
74
|
+
attr :gesture_recognizer_states
|
75
75
|
end
|
76
76
|
|
77
77
|
@devices = {
|
@@ -52,6 +52,7 @@ class Symbol
|
|
52
52
|
aqua: 0x00ffff,
|
53
53
|
aquamarine: 0x7fffd4,
|
54
54
|
azure: 0xf0ffff,
|
55
|
+
babygray: 0x576077,
|
55
56
|
beige: 0xf5f5dc,
|
56
57
|
bisque: 0xffe4c4,
|
57
58
|
blanchedalmond: 0xffebcd,
|
@@ -60,6 +61,7 @@ class Symbol
|
|
60
61
|
cadetblue: 0x5f9ea0,
|
61
62
|
chartreuse: 0x7fff00,
|
62
63
|
chocolate: 0xd2691e,
|
64
|
+
colingray: 0x526691,
|
63
65
|
coral: 0xff7f50,
|
64
66
|
cornflowerblue: 0x6495ed,
|
65
67
|
cornsilk: 0xfff8dc,
|
@@ -168,6 +170,7 @@ class Symbol
|
|
168
170
|
teal: 0x008080,
|
169
171
|
thistle: 0xd8bfd8,
|
170
172
|
tomato: 0xff6347,
|
173
|
+
torygray: 0x5c5a5d,
|
171
174
|
turquoise: 0x40e0d0,
|
172
175
|
violet: 0xee82ee,
|
173
176
|
wheat: 0xf5deb3,
|
data/lib/sugarcube/uicolor.rb
CHANGED
@@ -14,12 +14,45 @@ class UIColor
|
|
14
14
|
|
15
15
|
# blends two colors by averaging the RGB and alpha components.
|
16
16
|
# @example
|
17
|
-
#
|
17
|
+
# :white.uicolor + :black.uicolor == :gray.uicolor
|
18
18
|
def +(color)
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
19
|
+
mix_with(color, 0.5)
|
20
|
+
end
|
21
|
+
|
22
|
+
# a more generic color mixing method. mixes two colors, but a second
|
23
|
+
# parameter determines how much of each. 0.5 means equal parts, 0.0 means use
|
24
|
+
# all of the first, and 1.0 means use all of the second
|
25
|
+
def mix_with(color, amount)
|
26
|
+
# make amount between 0 and 1
|
27
|
+
amount = [[0, amount].max, 1].min
|
28
|
+
# start with precise amounts: 0, 0.5, and 1.
|
29
|
+
if amount == 0
|
30
|
+
self
|
31
|
+
elsif amount == 1
|
32
|
+
color
|
33
|
+
elsif amount == 0.5
|
34
|
+
r = (self.red + color.red) / 2
|
35
|
+
g = (self.green + color.green) / 2
|
36
|
+
b = (self.blue + color.blue) / 2
|
37
|
+
a = (self.alpha + color.alpha) / 2
|
38
|
+
UIColor.colorWithRed(r, green:g, blue:b, alpha:a)
|
39
|
+
else
|
40
|
+
r = (color.red - self.red) * amount + self.red
|
41
|
+
g = (color.green - self.green) * amount + self.green
|
42
|
+
b = (color.blue - self.blue) * amount + self.blue
|
43
|
+
a = (color.alpha - self.alpha) * amount + self.alpha
|
44
|
+
UIColor.colorWithRed(r, green:g, blue:b, alpha:a)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# inverts the RGB channel. keeps the alpha channel unchanged
|
49
|
+
# @example
|
50
|
+
# :white.uicolor.invert == :black.uicolor
|
51
|
+
def invert
|
52
|
+
r = 1.0 - self.red
|
53
|
+
g = 1.0 - self.green
|
54
|
+
b = 1.0 - self.blue
|
55
|
+
a = self.alpha
|
23
56
|
UIColor.colorWithRed(r, green:g, blue:b, alpha:a)
|
24
57
|
end
|
25
58
|
|
data/lib/sugarcube/uiview.rb
CHANGED
@@ -358,13 +358,39 @@ class UIView
|
|
358
358
|
}
|
359
359
|
end
|
360
360
|
|
361
|
-
# Easily take a snapshot of a UIView
|
362
|
-
|
361
|
+
# Easily take a snapshot of a `UIView`.
|
362
|
+
#
|
363
|
+
# Calling `uiimage` with no arguments will return the image based on the
|
364
|
+
# `bounds` of the image. In the case of container views (notably
|
365
|
+
# `UIScrollView` and its children) this does not include the entire contents,
|
366
|
+
# which is something you probably want.
|
367
|
+
#
|
368
|
+
# If you pass a truthy value to this method, it will use the `contentSize` of
|
369
|
+
# the view instead of the `bounds`, and it will draw all the child views, not
|
370
|
+
# just those that are visible in the viewport.
|
371
|
+
#
|
372
|
+
# It is guaranteed that `true` and `:all` will always have this behavior. In
|
373
|
+
# the future, if this argument becomes something that accepts multiple values,
|
374
|
+
# those two are sacred.
|
375
|
+
def uiimage(use_content_size=false)
|
363
376
|
scale = UIScreen.mainScreen.scale
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
377
|
+
if use_content_size
|
378
|
+
UIGraphicsBeginImageContextWithOptions(contentSize, false, scale)
|
379
|
+
context = UIGraphicsGetCurrentContext()
|
380
|
+
subviews.each do |subview|
|
381
|
+
CGContextSaveGState(context)
|
382
|
+
CGContextTranslateCTM(context, subview.frame.origin.x, subview.frame.origin.y)
|
383
|
+
subview.layer.renderInContext(context)
|
384
|
+
CGContextRestoreGState(context)
|
385
|
+
end
|
386
|
+
image = UIGraphicsGetImageFromCurrentImageContext()
|
387
|
+
UIGraphicsEndImageContext()
|
388
|
+
else
|
389
|
+
UIGraphicsBeginImageContextWithOptions(bounds.size, false, scale)
|
390
|
+
layer.renderInContext(UIGraphicsGetCurrentContext())
|
391
|
+
image = UIGraphicsGetImageFromCurrentImageContext()
|
392
|
+
UIGraphicsEndImageContext()
|
393
|
+
end
|
368
394
|
return image
|
369
395
|
end
|
370
396
|
|
@@ -23,7 +23,9 @@ class UINavigationController
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def pop(to_view=nil)
|
26
|
-
if to_view
|
26
|
+
if to_view == :root
|
27
|
+
self.popToRootViewControllerAnimated(true)
|
28
|
+
elsif to_view
|
27
29
|
self.popToViewController(to_view, animated: true)
|
28
30
|
else
|
29
31
|
self.popViewControllerAnimated(true)
|
@@ -36,7 +38,10 @@ end
|
|
36
38
|
class UITabBarController
|
37
39
|
|
38
40
|
def push(view_controller)
|
39
|
-
view_controllers = []
|
41
|
+
view_controllers = []
|
42
|
+
if self.viewControllers
|
43
|
+
view_controllers += self.viewControllers
|
44
|
+
end
|
40
45
|
view_controllers << view_controller
|
41
46
|
self.setViewControllers(view_controllers, animated: true)
|
42
47
|
self
|
data/lib/sugarcube/version.rb
CHANGED
@@ -26,6 +26,12 @@ describe 'NSAttributeString' do
|
|
26
26
|
subject.attributesAtIndex(0, effectiveRange:nil).should == {'NSUnderline' => NSUnderlineStyleSingle}
|
27
27
|
end
|
28
28
|
|
29
|
+
it 'should be chainable' do
|
30
|
+
subject = 'test'.bold.underline
|
31
|
+
NSAttributedString.should === subject
|
32
|
+
subject.attributesAtIndex(0, effectiveRange:nil).should == {'NSFont' => :bold.uifont, 'NSUnderline' => NSUnderlineStyleSingle}
|
33
|
+
end
|
34
|
+
|
29
35
|
end
|
30
36
|
|
31
37
|
describe "should support all attribute names" do
|
data/spec/nsdate_spec.rb
CHANGED
@@ -11,16 +11,22 @@ describe "NSDate" do
|
|
11
11
|
@date = NSDate.from_components(year: 2013, month: 1, day: 2, hour:12, minute: 15, second: 30)
|
12
12
|
end
|
13
13
|
|
14
|
-
it "should have an NSDate#string_with_style(
|
14
|
+
it "should have an NSDate#string_with_style(date_style, time_style) method that accepts symbols" do
|
15
15
|
@date.string_with_style(:medium).should == 'Jan 2, 2013'
|
16
|
+
@date.string_with_style(:medium, :none).should == 'Jan 2, 2013'
|
17
|
+
@date.string_with_style(:short, :medium).should == '1/2/13, 12:15:30 PM'
|
18
|
+
@date.string_with_style(:none, :short).should == '12:15 PM'
|
16
19
|
end
|
17
20
|
|
18
|
-
it "should have an NSDate#string_with_style(
|
21
|
+
it "should have an NSDate#string_with_style(date_style, time_style) method that has default" do
|
19
22
|
@date.string_with_style.should == 'Jan 2, 2013'
|
20
23
|
end
|
21
24
|
|
22
|
-
it "should have an NSDate#string_with_style(
|
23
|
-
@date.string_with_style(
|
25
|
+
it "should have an NSDate#string_with_style(date_style, time_style) method that accepts NSDateStyle constants" do
|
26
|
+
@date.string_with_style(NSDateFormatterMediumStyle).should == 'Jan 2, 2013'
|
27
|
+
@date.string_with_style(NSDateFormatterMediumStyle, NSDateFormatterNoStyle).should == 'Jan 2, 2013'
|
28
|
+
@date.string_with_style(NSDateFormatterShortStyle, NSDateFormatterMediumStyle).should == '1/2/13, 12:15:30 PM'
|
29
|
+
@date.string_with_style(NSDateFormatterNoStyle, NSDateFormatterShortStyle).should == '12:15 PM'
|
24
30
|
end
|
25
31
|
|
26
32
|
it "should have an NSDate#string_with_format method (1)" do
|
data/spec/nsstring_spec.rb
CHANGED
data/spec/uicolor_spec.rb
CHANGED
@@ -15,4 +15,43 @@ describe 'UIColor' do
|
|
15
15
|
new_color.blue.should == 0.5
|
16
16
|
end
|
17
17
|
|
18
|
+
it "should have a #invert method" do
|
19
|
+
:red.uicolor.invert.should == UIColor.cyanColor
|
20
|
+
:green.uicolor.invert.should == UIColor.magentaColor
|
21
|
+
:blue.uicolor.invert.should == UIColor.yellowColor
|
22
|
+
|
23
|
+
:white.uicolor.invert.red.should == 0
|
24
|
+
:white.uicolor.invert.green.should == 0
|
25
|
+
:white.uicolor.invert.blue.should == 0
|
26
|
+
|
27
|
+
:black.uicolor.invert.red.should == 1
|
28
|
+
:black.uicolor.invert.green.should == 1
|
29
|
+
:black.uicolor.invert.blue.should == 1
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should have a #mix_with method" do
|
33
|
+
white = :white.uicolor
|
34
|
+
black = :black.uicolor
|
35
|
+
gray = :gray.uicolor
|
36
|
+
white.mix_with(black, 0).red.should == 1
|
37
|
+
white.mix_with(black, 0).green.should == 1
|
38
|
+
white.mix_with(black, 0).blue.should == 1
|
39
|
+
|
40
|
+
white.mix_with(black, 1).red.should == 0
|
41
|
+
white.mix_with(black, 1).green.should == 0
|
42
|
+
white.mix_with(black, 1).blue.should == 0
|
43
|
+
|
44
|
+
white.mix_with(black, 0.5).red.should == 0.5
|
45
|
+
white.mix_with(black, 0.5).green.should == 0.5
|
46
|
+
white.mix_with(black, 0.5).blue.should == 0.5
|
47
|
+
|
48
|
+
white.mix_with(black, 0.25).red.should == 0.75
|
49
|
+
white.mix_with(black, 0.25).green.should == 0.75
|
50
|
+
white.mix_with(black, 0.25).blue.should == 0.75
|
51
|
+
|
52
|
+
white.mix_with(black, 0.75).red.should == 0.25
|
53
|
+
white.mix_with(black, 0.75).green.should == 0.25
|
54
|
+
white.mix_with(black, 0.75).blue.should == 0.25
|
55
|
+
end
|
56
|
+
|
18
57
|
end
|
data/spec/uiview_spec.rb
CHANGED
@@ -8,4 +8,24 @@ describe "UIView" do
|
|
8
8
|
image.scale.should == UIScreen.mainScreen.scale
|
9
9
|
end
|
10
10
|
|
11
|
+
it "should convert a UIScrollView to a UIImage" do
|
12
|
+
test = UIScrollView.alloc.initWithFrame([[0, 0], [10, 10]])
|
13
|
+
test.contentSize = [20, 20]
|
14
|
+
|
15
|
+
image = test.uiimage
|
16
|
+
image.class.should == UIImage
|
17
|
+
CGSizeEqualToSize(image.size, [10, 10]).should == true
|
18
|
+
image.scale.should == UIScreen.mainScreen.scale
|
19
|
+
|
20
|
+
image = test.uiimage(:all)
|
21
|
+
image.class.should == UIImage
|
22
|
+
CGSizeEqualToSize(image.size, [20, 20]).should == true
|
23
|
+
image.scale.should == UIScreen.mainScreen.scale
|
24
|
+
|
25
|
+
image = test.uiimage(true)
|
26
|
+
image.class.should == UIImage
|
27
|
+
CGSizeEqualToSize(image.size, [20, 20]).should == true
|
28
|
+
image.scale.should == UIScreen.mainScreen.scale
|
29
|
+
end
|
30
|
+
|
11
31
|
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
describe 'UIViewController' do
|
2
|
+
|
3
|
+
it 'should have `push` method' do
|
4
|
+
controller = UIViewController.new
|
5
|
+
controller.push UIViewController.new
|
6
|
+
controller.childViewControllers.length.should == 1
|
7
|
+
controller.push UIViewController.new
|
8
|
+
controller.childViewControllers.length.should == 2
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should have `<<` method' do
|
12
|
+
controller = UIViewController.new
|
13
|
+
controller << UIViewController.new
|
14
|
+
controller.childViewControllers.length.should == 1
|
15
|
+
controller << UIViewController.new
|
16
|
+
controller.childViewControllers.length.should == 2
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
describe 'UINavigationViewController' do
|
23
|
+
|
24
|
+
before do
|
25
|
+
@root_controller = UIViewController.new
|
26
|
+
second_controller = UIViewController.new
|
27
|
+
@target_controller = UIViewController.new
|
28
|
+
fourth_controller = UIViewController.new
|
29
|
+
@nav_controller = UINavigationController.alloc.initWithRootViewController(@root_controller)
|
30
|
+
@nav_controller.pushViewController(second_controller, animated: false)
|
31
|
+
@nav_controller.pushViewController(@target_controller, animated: false)
|
32
|
+
@nav_controller.pushViewController(fourth_controller, animated: false)
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should have `push` method' do
|
36
|
+
test_controller = UIViewController.new
|
37
|
+
length = @nav_controller.viewControllers.length
|
38
|
+
@nav_controller.push(test_controller)
|
39
|
+
@nav_controller.viewControllers.length.should == length + 1
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should have `<<` method' do
|
43
|
+
test_controller = UIViewController.new
|
44
|
+
length = @nav_controller.viewControllers.length
|
45
|
+
@nav_controller << test_controller
|
46
|
+
@nav_controller.viewControllers.length.should == length + 1
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'should have `pop()` method' do
|
50
|
+
length = @nav_controller.viewControllers.length
|
51
|
+
@nav_controller.pop
|
52
|
+
@nav_controller.viewControllers.length.should == length - 1
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'should have `pop(:root)` method' do
|
56
|
+
@nav_controller.pop :root
|
57
|
+
@nav_controller.viewControllers.length.should == 1
|
58
|
+
@nav_controller.visibleViewController.should == @root_controller
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'should have `pop(@target_controller)` method' do
|
62
|
+
@nav_controller.pop @target_controller
|
63
|
+
@nav_controller.visibleViewController.should == @target_controller
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
describe 'UITabBarController' do
|
70
|
+
|
71
|
+
it 'should have `push` method' do
|
72
|
+
controller = UITabBarController.new
|
73
|
+
controller.push UIViewController.new
|
74
|
+
controller.viewControllers.length.should == 1
|
75
|
+
controller.push UIViewController.new
|
76
|
+
controller.viewControllers.length.should == 2
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'should have `<<` method' do
|
80
|
+
controller = UITabBarController.new
|
81
|
+
controller << UIViewController.new
|
82
|
+
controller.viewControllers.length.should == 1
|
83
|
+
controller << UIViewController.new
|
84
|
+
controller.viewControllers.length.should == 2
|
85
|
+
end
|
86
|
+
|
87
|
+
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.
|
4
|
+
version: 0.19.0
|
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-03-
|
16
|
+
date: 2013-03-17 00:00:00.000000000 Z
|
17
17
|
dependencies: []
|
18
18
|
description: ! '== Description
|
19
19
|
|
@@ -153,6 +153,7 @@ files:
|
|
153
153
|
- spec/uiview_animation_spec.rb
|
154
154
|
- spec/uiview_attr_updates_spec.rb
|
155
155
|
- spec/uiview_spec.rb
|
156
|
+
- spec/uiviewcontroller_spec.rb
|
156
157
|
- spec/unholy_spec.rb
|
157
158
|
- sugarcube.gemspec
|
158
159
|
homepage: https://github.com/rubymotion/sugarcube
|
@@ -212,5 +213,6 @@ test_files:
|
|
212
213
|
- spec/uiview_animation_spec.rb
|
213
214
|
- spec/uiview_attr_updates_spec.rb
|
214
215
|
- spec/uiview_spec.rb
|
216
|
+
- spec/uiviewcontroller_spec.rb
|
215
217
|
- spec/unholy_spec.rb
|
216
218
|
has_rdoc:
|