sugarcube 0.20.10 → 0.20.11

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1141,9 +1141,9 @@ puts @label.font.pointSize # => Will be 40 or less depending on the font type an
1141
1141
 
1142
1142
  ```ruby
1143
1143
  # Get an instance containing the specified system item.
1144
- UIBarButtonItem.done {
1144
+ UIBarButtonItem.done do
1145
1145
  self.dismissViewControllerAnimated true, completion:nil
1146
- }
1146
+ end
1147
1147
  # =>
1148
1148
  UIBarButtonItem.alloc.initWithBarButtonSystemItem(:done.uibarbuttonitem, target:self, action:"action:")
1149
1149
  # with 'action' defined as:
@@ -1152,52 +1152,49 @@ def action(sender)
1152
1152
  end
1153
1153
 
1154
1154
  # the method names are 1::1 with the uibarbuttonitem constants in symbol.rb
1155
- UIBarButtonItem.cancel(&action) => UIBarButtonItem.alloc.initWithBarButtonSystemItem(:cancel.uibarbuttonitem, target:self, action:"action:")
1156
- UIBarButtonItem.edit(&action) => UIBarButtonItem.alloc.initWithBarButtonSystemItem(:edit.uibarbuttonitem, target:self, action:"action:")
1157
- UIBarButtonItem.save(&action) => UIBarButtonItem.alloc.initWithBarButtonSystemItem(:save.uibarbuttonitem, target:self, action:"action:")
1155
+ UIBarButtonItem.cancel { ... } => UIBarButtonItem.alloc.initWithBarButtonSystemItem(:cancel.uibarbuttonitem, target:self, action:"action:")
1156
+ UIBarButtonItem.edit { ... } => UIBarButtonItem.alloc.initWithBarButtonSystemItem(:edit.uibarbuttonitem, target:self, action:"action:")
1157
+ UIBarButtonItem.save { ... } => UIBarButtonItem.alloc.initWithBarButtonSystemItem(:save.uibarbuttonitem, target:self, action:"action:")
1158
1158
  .
1159
1159
  .
1160
1160
  .
1161
- UIBarButtonItem.pagecurl(&action) => UIBarButtonItem.alloc.initWithBarButtonSystemItem(:pagecurl.uibarbuttonitem, target:self, action:"action:")
1161
+ UIBarButtonItem.pagecurl { ... } => UIBarButtonItem.alloc.initWithBarButtonSystemItem(:pagecurl.uibarbuttonitem, target:self, action:"action:")
1162
1162
 
1163
- # Get an instance containing the specified title.
1164
- UIBarButtonItem.titled('Close') {
1165
- self.dismissViewControllerAnimated true, completion:nil
1166
- }
1163
+ # Create a UIBarButtonItem, specifying the title
1164
+ UIBarButtonItem.titled('Close') do
1165
+ self.dismissViewControllerAnimated(true, completion:nil)
1166
+ end
1167
1167
  # =>
1168
1168
  UIBarButtonItem.alloc.initWithTitle('Close', style: :bordered.uibarbuttonstyle, target:self, action:"action:")
1169
-
1170
- def action:sender
1171
- self.dismissViewControllerAnimated true, completion:nil
1169
+ def action(sender)
1170
+ self.dismissViewControllerAnimated(true, completion:nil)
1172
1171
  end
1173
1172
 
1174
- # You can also specify a style.
1175
- UIBarButtonItem.titled('Close', :plain.uibarbuttonstyle) {
1176
- self.dismissViewControllerAnimated true, completion:nil
1177
- }
1178
1173
 
1174
+ # You can also specify the style.
1175
+ UIBarButtonItem.titled('Close', :plain) do # :plain, :bordered, :done
1176
+ # ...
1177
+ end
1179
1178
 
1180
- # Get an instance containing the specified image.
1181
- UIBarButtonItem.imaged('close'.uiimage) {
1182
- self.dismissViewControllerAnimated true, completion:nil
1183
- }
1184
- # =>
1185
- UIBarButtonItem.alloc.initWithImage('Close'.uiimage, style: :bordered.uibarbuttonstyle, target:self, action:"action:")
1186
- def action:sender
1187
- self.dismissViewControllerAnimated true, completion:nil
1179
+
1180
+ # Or specify the image instead
1181
+ UIBarButtonItem.imaged('close_icon') do # 'close_icon' will be coerced into a UIImage
1182
+ # ...
1188
1183
  end
1184
+ # =>
1185
+ UIBarButtonItem.alloc.initWithImage('Close'.uiimage, style: :bordered.uibarbuttonstyle, ...)
1189
1186
 
1190
- # You can also specify a style.
1191
- UIBarButtonItem.imaged('close'.uiimage, :plain.uibarbuttonstyle) {
1192
- self.dismissViewControllerAnimated true, completion:nil
1193
- }
1187
+ # And, like `titled`, specify the style
1188
+ UIBarButtonItem.imaged('close'.uiimage, :done) do
1189
+ # ...
1190
+ end
1194
1191
 
1195
- # Get an instance containing the specified array which contains a portrate image and a landscape iamge.
1196
- UIBarButtonItem.imaged(['portrate'.uiimage, 'landscape'.uiimage) {
1197
- self.dismissViewControllerAnimated true, completion:nil
1198
- }
1192
+ # If you provide two images, they will be used as the portrait and landscape images
1193
+ UIBarButtonItem.imaged(['portrait'.uiimage, 'landscape'.uiimage) do
1194
+ # ...
1195
+ end
1199
1196
  # =>
1200
- UIBarButtonItem.alloc.initWithImage('portrate'.uiimage, landscapeImagePhone:'landscape'.uiimage, style: :bordered.uibarbuttonstyle, target:self, action:"action:")
1197
+ UIBarButtonItem.alloc.initWithImage('portrait'.uiimage, landscapeImagePhone:'landscape'.uiimage, style: :bordered.uibarbuttonstyle, target:self, action:"action:")
1201
1198
  ```
1202
1199
 
1203
1200
  Example Usage:
@@ -81,11 +81,13 @@ module SugarCube
81
81
  handler = success_handler
82
82
  end
83
83
 
84
- if handler.arity == 0
85
- handler.call
86
- else
87
- button = buttons[index]
88
- handler.call(button)
84
+ if handler
85
+ if handler.arity == 0
86
+ handler.call
87
+ else
88
+ button = buttons[index]
89
+ handler.call(button)
90
+ end
89
91
  end
90
92
 
91
93
  self.send(:autorelease)
@@ -1,111 +1,112 @@
1
+ # Factory methods for UIBarButtonItem
1
2
  class UIBarButtonItem
2
-
3
+
3
4
  class << self
4
-
5
+
5
6
  def done(&action)
6
- sugarcube_barbuttonitem :done.uibarbuttonitem, action
7
+ sugarcube_barbuttonitem(:done, action)
7
8
  end
8
9
 
9
10
  def cancel(&action)
10
- sugarcube_barbuttonitem :cancel.uibarbuttonitem, action
11
+ sugarcube_barbuttonitem(:cancel, action)
11
12
  end
12
-
13
+
13
14
  def edit(&action)
14
- sugarcube_barbuttonitem :edit.uibarbuttonitem, action
15
+ sugarcube_barbuttonitem(:edit, action)
15
16
  end
16
-
17
+
17
18
  def save(&action)
18
- sugarcube_barbuttonitem :save.uibarbuttonitem, action
19
+ sugarcube_barbuttonitem(:save, action)
19
20
  end
20
-
21
+
21
22
  def add(&action)
22
- sugarcube_barbuttonitem :add.uibarbuttonitem, action
23
+ sugarcube_barbuttonitem(:add, action)
23
24
  end
24
-
25
+
25
26
  def flexiblespace(&action)
26
- sugarcube_barbuttonitem :flexiblespace.uibarbuttonitem, action
27
+ sugarcube_barbuttonitem(:flexiblespace, action)
27
28
  end
28
-
29
+
29
30
  def fixedspace(&action)
30
- sugarcube_barbuttonitem :fixedspace.uibarbuttonitem, action
31
+ sugarcube_barbuttonitem(:fixedspace, action)
31
32
  end
32
-
33
+
33
34
  def compose(&action)
34
- sugarcube_barbuttonitem :compose.uibarbuttonitem, action
35
+ sugarcube_barbuttonitem(:compose, action)
35
36
  end
36
-
37
+
37
38
  def reply(&action)
38
- sugarcube_barbuttonitem :reply.uibarbuttonitem, action
39
+ sugarcube_barbuttonitem(:reply, action)
39
40
  end
40
-
41
+
41
42
  def action(&action)
42
- sugarcube_barbuttonitem :action.uibarbuttonitem, action
43
+ sugarcube_barbuttonitem(:action, action)
43
44
  end
44
-
45
+
45
46
  def organize(&action)
46
- sugarcube_barbuttonitem :organize.uibarbuttonitem, action
47
+ sugarcube_barbuttonitem(:organize, action)
47
48
  end
48
-
49
+
49
50
  def bookmarks(&action)
50
- sugarcube_barbuttonitem :bookmarks.uibarbuttonitem, action
51
+ sugarcube_barbuttonitem(:bookmarks, action)
51
52
  end
52
-
53
+
53
54
  def search(&action)
54
- sugarcube_barbuttonitem :search.uibarbuttonitem, action
55
+ sugarcube_barbuttonitem(:search, action)
55
56
  end
56
-
57
+
57
58
  def refresh(&action)
58
- sugarcube_barbuttonitem :refresh.uibarbuttonitem, action
59
+ sugarcube_barbuttonitem(:refresh, action)
59
60
  end
60
-
61
+
61
62
  def stop(&action)
62
- sugarcube_barbuttonitem :stop.uibarbuttonitem, action
63
+ sugarcube_barbuttonitem(:stop, action)
63
64
  end
64
-
65
+
65
66
  def camera(&action)
66
- sugarcube_barbuttonitem :camera.uibarbuttonitem, action
67
+ sugarcube_barbuttonitem(:camera, action)
67
68
  end
68
-
69
+
69
70
  def trash(&action)
70
- sugarcube_barbuttonitem :trash.uibarbuttonitem, action
71
+ sugarcube_barbuttonitem(:trash, action)
71
72
  end
72
-
73
+
73
74
  def play(&action)
74
- sugarcube_barbuttonitem :play.uibarbuttonitem, action
75
+ sugarcube_barbuttonitem(:play, action)
75
76
  end
76
-
77
+
77
78
  def pause(&action)
78
- sugarcube_barbuttonitem :pause.uibarbuttonitem, action
79
+ sugarcube_barbuttonitem(:pause, action)
79
80
  end
80
-
81
+
81
82
  def rewind(&action)
82
- sugarcube_barbuttonitem :rewind.uibarbuttonitem, action
83
+ sugarcube_barbuttonitem(:rewind, action)
83
84
  end
84
85
 
85
86
  def fastforward(&action)
86
- sugarcube_barbuttonitem :fastforward.uibarbuttonitem, action
87
+ sugarcube_barbuttonitem(:fastforward, action)
87
88
  end
88
89
 
89
90
  def undo(&action)
90
- sugarcube_barbuttonitem :undo.uibarbuttonitem, action
91
+ sugarcube_barbuttonitem(:undo, action)
91
92
  end
92
93
 
93
94
  def redo(&action)
94
- sugarcube_barbuttonitem :redo.uibarbuttonitem, action
95
+ sugarcube_barbuttonitem(:redo, action)
95
96
  end
96
97
 
97
98
  def pagecurl(&action)
98
- sugarcube_barbuttonitem :pagecurl.uibarbuttonitem, action
99
+ sugarcube_barbuttonitem(:pagecurl, action)
99
100
  end
100
101
 
101
- def titled(title, style = :bordered.uibarbuttonstyle, &action)
102
+ def titled(title, style = :bordered, &action)
102
103
  sugarcube_barbuttonitem_with_title(title, style, action)
103
104
  end
104
-
105
- def imaged(image, style = :bordered.uibarbuttonstyle, &action)
105
+
106
+ def imaged(image, style = :bordered, &action)
106
107
  sugarcube_barbuttonitem_with_image(image, style, action)
107
108
  end
108
-
109
+
109
110
  end
110
111
 
111
112
  # Adds the action and keeps a strong reference to the Proc object.
@@ -119,23 +120,26 @@ class UIBarButtonItem
119
120
  private
120
121
 
121
122
  def self.sugarcube_barbuttonitem(systemitem, action)
122
- b = UIBarButtonItem.alloc.initWithBarButtonSystemItem systemitem, target:nil, action:nil
123
+ systemitem = systemitem.uibarbuttonitem if systemitem.is_a?(Symbol)
124
+ b = UIBarButtonItem.alloc.initWithBarButtonSystemItem(systemitem, target:nil, action:nil)
123
125
  b.set_target_and_action b, action
124
126
  b
125
127
  end
126
128
 
127
129
  def self.sugarcube_barbuttonitem_with_title(title, style, action)
128
- b = UIBarButtonItem.alloc.initWithTitle title, style:style, target:nil, action:nil
130
+ style = style.uibarbuttonstyle if style.is_a?(Symbol)
131
+ b = UIBarButtonItem.alloc.initWithTitle(title, style:style, target:nil, action:nil)
129
132
  b.set_target_and_action b, action
130
133
  b
131
134
  end
132
135
 
133
136
  def self.sugarcube_barbuttonitem_with_image(image, style, action)
137
+ style = style.uibarbuttonstyle if style.is_a?(Symbol)
134
138
  case image
135
139
  when Array
136
- b = UIBarButtonItem.alloc.initWithImage image.first, landscapeImagePhone:image.last, style:style, target:nil, action:nil
140
+ b = UIBarButtonItem.alloc.initWithImage(image.first.uiimage, landscapeImagePhone:image.last.uiimage, style:style, target:nil, action:nil)
137
141
  else
138
- b = UIBarButtonItem.alloc.initWithImage image, style:style, target:nil, action:nil
142
+ b = UIBarButtonItem.alloc.initWithImage(image.uiimage, style:style, target:nil, action:nil)
139
143
  end
140
144
  b.set_target_and_action b, action
141
145
  b
@@ -228,24 +228,27 @@ class UIView
228
228
 
229
229
  # Changes the current rotation to `new_angle`
230
230
  # (`rotate` rotates relative to the current rotation)
231
- def rotate_to(options={}, &after)
231
+ def rotate_to(options={}, more_options={}, &after)
232
232
  if options.is_a? Numeric
233
- options = { angle: options }
233
+ new_angle = options
234
+ options = more_options
235
+ else
236
+ new_angle = options[:angle]
234
237
  end
235
238
 
236
239
  options[:after] = after
237
240
 
238
241
  animate(options) {
239
- self.transform = CGAffineTransformMakeRotation(options[:angle])
242
+ self.transform = CGAffineTransformMakeRotation(new_angle)
240
243
  }
241
244
  end
242
245
 
243
246
  # Changes the current rotation by `new_angle`
244
247
  # (`rotate` rotates to a specific angle)
245
- def rotate(options={}, &after)
248
+ def rotate(options={}, more_options={}, &after)
246
249
  if options.is_a? Numeric
247
250
  new_angle = options
248
- options = {}
251
+ options = more_options
249
252
  else
250
253
  new_angle = options[:angle]
251
254
  end
@@ -255,10 +258,10 @@ class UIView
255
258
  rotate_to(options, &after)
256
259
  end
257
260
 
258
- def slide(direction, options={}, more_options=nil, &after)
261
+ def slide(direction, options={}, more_options={}, &after)
259
262
  if options.is_a? Numeric
260
263
  size = options
261
- options = more_options || {}
264
+ options = more_options
262
265
  else
263
266
  size = options[:size]
264
267
  end
@@ -1,3 +1,3 @@
1
1
  module SugarCube
2
- Version = '0.20.10'
2
+ Version = '0.20.11'
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.20.10
4
+ version: 0.20.11
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-04-20 00:00:00.000000000 Z
16
+ date: 2013-04-21 00:00:00.000000000 Z
17
17
  dependencies: []
18
18
  description: ! '== Description
19
19