formotion 1.1.2 → 1.1.3

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/CHANGELOG.md CHANGED
@@ -1,3 +1,19 @@
1
+ ## 1.1.3 - ??
2
+
3
+ ### Features
4
+
5
+ - Support a generic `:button` `RowType` which can be used in conjunction with a `Row`'s `on_tap` method.
6
+
7
+ ### Bug Fixes
8
+
9
+ - Fixed bug where pushing a subform inherited from current controller class, which could cause expected behavior.
10
+
11
+ - Fixed crash when a Slider or Switch row type had an empty :title
12
+
13
+ - Fixed device crash when taking photo
14
+
15
+ - Fixed problems related to KVO-ing `Formable` objects.
16
+
1
17
  ## 1.1.2 - October 6, 2012
2
18
 
3
19
  ### Bug Fixes
data/LIST_OF_ROW_TYPES.md CHANGED
@@ -18,6 +18,7 @@
18
18
  [Template](#template)
19
19
 
20
20
  **Buttons**<br/>
21
+ [Button](#button)<br/>
21
22
  [Submit](#submit)<br/>
22
23
  [Back](#back)<br/>
23
24
  [Edit](#edit)<br/>
@@ -343,6 +344,22 @@ Use a `:display_key` to show the value of the subform in the row:
343
344
 
344
345
  ## Buttons
345
346
 
347
+ ### <a name="button"></a> Button row
348
+
349
+ ```ruby
350
+ {
351
+ title: "Any Button",
352
+ type: :button,
353
+ }
354
+
355
+ # later...
356
+ form.sections[0].rows[0].on_tap do |row|
357
+ # do something when tapped
358
+ end
359
+ ```
360
+
361
+ The `SubmitRow` triggers the `form.submit` which triggers the defined `on_submit` callback.
362
+
346
363
  ### <a name="submit"></a> Submit row
347
364
  ![Submit row](https://github.com/clayallsopp/formotion/wiki/row-types/submit.png)
348
365
 
@@ -50,7 +50,6 @@ module Formotion
50
50
  @form.controller = self
51
51
  end
52
52
 
53
-
54
53
  def viewWillAppear(animated)
55
54
  super
56
55
 
@@ -59,7 +58,7 @@ module Formotion
59
58
 
60
59
  # Subview Methods
61
60
  def push_subform(form)
62
- @subform_controller = self.class.alloc.initWithForm(form)
61
+ @subform_controller = Formotion::FormController.alloc.initWithForm(form)
63
62
 
64
63
  if self.navigationController
65
64
  self.navigationController.pushViewController(@subform_controller, animated: true)
@@ -1,7 +1,7 @@
1
1
  module Formotion
2
2
  class Form < Formotion::Base
3
- extend BW::KVO
4
- include BW::KVO
3
+ extend BubbleWrap::KVO
4
+ include BubbleWrap::KVO
5
5
 
6
6
  PROPERTIES = [
7
7
  # By default, Formotion::Controller will set it's title to this
@@ -9,6 +9,8 @@ module Formotion
9
9
  attr_accessor prop
10
10
  end
11
11
 
12
+ # Does NOT get called when KVO occurs.
13
+ # (KVO uses isa swizzling and not proper subclassing)
12
14
  def inherited(subclass)
13
15
  INHERITABLE_ATTRIBUTES.each do |inheritable_attribute|
14
16
  instance_var = "@#{inheritable_attribute}"
@@ -17,6 +19,7 @@ module Formotion
17
19
  end
18
20
 
19
21
  def form_properties
22
+ @form_properties ||= self.superclass.form_properties if is_kvo_subclass?
20
23
  @form_properties ||= []
21
24
  end
22
25
 
@@ -38,9 +41,16 @@ module Formotion
38
41
  # EX
39
42
  # form_title "Some Settings"
40
43
  def form_title(title = -1)
44
+ @form_title ||= self.superclass.form_title if is_kvo_subclass?
41
45
  @form_title = title if title != -1
42
46
  @form_title
43
47
  end
48
+
49
+ private
50
+ # Terrible, terrible hack.
51
+ def is_kvo_subclass?
52
+ self.to_s =~ /^NSKVONotifying_/
53
+ end
44
54
  end
45
55
 
46
56
  # Creates a Formotion::Form out of the model
@@ -103,6 +103,9 @@ module Formotion
103
103
  # callback for what happens when the user
104
104
  # starts editing #text_field.
105
105
  attr_accessor :on_begin_callback
106
+ # callback for what happens when the user
107
+ # taps a ButtonRow
108
+ attr_accessor :on_tap_callback
106
109
 
107
110
  # RowType object
108
111
  attr_accessor :object
@@ -226,6 +229,11 @@ module Formotion
226
229
  self.on_begin_callback = block
227
230
  end
228
231
 
232
+ # Used in :button type rows
233
+ def on_tap(&block)
234
+ self.on_tap_callback = block
235
+ end
236
+
229
237
  #########################
230
238
  # Methods for making cells
231
239
  # Called in UITableViewDataSource methods
@@ -1,6 +1,6 @@
1
1
  module Formotion
2
2
  module RowType
3
- class BackRow < Button
3
+ class BackRow < ButtonRow
4
4
 
5
5
  def on_select(tableView, tableViewDelegate)
6
6
  row.form.controller.pop_subform
@@ -1,7 +1,6 @@
1
1
  module Formotion
2
2
  module RowType
3
- class Button < Base
4
-
3
+ class ButtonRow < Base
5
4
  def button?
6
5
  true
7
6
  end
@@ -25,6 +24,12 @@ module Formotion
25
24
  nil
26
25
  end
27
26
 
27
+ def on_select(tableView, tableViewDelegate)
28
+ # Override in subclasses
29
+ if self.row.on_tap_callback
30
+ self.row.on_tap_callback.call(self.row)
31
+ end
32
+ end
28
33
  end
29
34
  end
30
35
  end
@@ -1,6 +1,6 @@
1
1
  module Formotion
2
2
  module RowType
3
- class EditRow < Button
3
+ class EditRow < ButtonRow
4
4
  def on_select(tableView, tableViewDelegate)
5
5
  was_editing = tableView.isEditing
6
6
  if row.alt_title
@@ -75,7 +75,7 @@ module Formotion
75
75
  end
76
76
 
77
77
  if source
78
- @camera = BW::Device.camera.any
78
+ @camera = BW::Device.camera.send((source == :camera) ? :rear : :any)
79
79
  @camera.picture(source_type: source, media_types: [:image]) do |result|
80
80
  if result[:original_image]
81
81
  row.value = result[:original_image]
@@ -14,7 +14,7 @@ module Formotion
14
14
  slideView.maximumValue = row.range.last
15
15
  slideView.tag = SLIDER_VIEW_TAG
16
16
  slideView.setValue(row.value, animated:true) if row.value
17
- slideView.accessibilityLabel = row.title + " Slider"
17
+ slideView.accessibilityLabel = (row.title || "") + " Slider"
18
18
 
19
19
  slideView.when(UIControlEventValueChanged) do
20
20
  break_with_semaphore do
@@ -1,6 +1,6 @@
1
1
  module Formotion
2
2
  module RowType
3
- class SubmitRow < Button
3
+ class SubmitRow < ButtonRow
4
4
 
5
5
  def on_select(tableView, tableViewDelegate)
6
6
  tableViewDelegate.submit
@@ -6,7 +6,7 @@ module Formotion
6
6
  def build_cell(cell)
7
7
  cell.selectionStyle = UITableViewCellSelectionStyleNone
8
8
  switchView = UISwitch.alloc.initWithFrame(CGRectZero)
9
- switchView.accessibilityLabel = row.title + " Switch"
9
+ switchView.accessibilityLabel = (row.title || "") + " Switch"
10
10
  cell.accessoryView = cell.editingAccessoryView = switchView
11
11
  switchView.setOn(row.value || false, animated:false)
12
12
  switchView.when(UIControlEventValueChanged) do
@@ -1,3 +1,3 @@
1
1
  module Formotion
2
- VERSION = "1.1.2"
2
+ VERSION = "1.1.3"
3
3
  end
@@ -0,0 +1,45 @@
1
+ class User
2
+ include Formotion::Formable
3
+
4
+ attr_accessor :name, :score, :team
5
+
6
+ form_property :name, :string
7
+ form_property :score, :number, transform: lambda { |value| value.to_i }
8
+
9
+ form_property :team, :picker, items: ["Red", "Blue", "Green"]
10
+
11
+ form_title "Edit User"
12
+
13
+ def initialize(name, score, team)
14
+ self.name = name
15
+ self.score = score
16
+ self.team = team
17
+ end
18
+ end
19
+
20
+ class ObserverTest
21
+ include BubbleWrap::KVO
22
+
23
+ def users
24
+ @users ||= [User.new("Harry", 100, "Green"),
25
+ User.new("Ron", 80, "Blue"),
26
+ User.new("Hermione", 120, "Red")]
27
+ end
28
+
29
+ def start_observing
30
+ observe(self.users.first, "team") do |old_value, new_value|
31
+ end
32
+ end
33
+ end
34
+
35
+ describe "Formotion::Formable w/ KVO" do
36
+ it "should work" do
37
+ test = ObserverTest.new
38
+ test.start_observing
39
+
40
+ test.users[0].to_form.title.should == test.users[1].to_form.title
41
+ test.users[0].class.form_properties.should == test.users[1].class.form_properties
42
+
43
+ test.unobserve_all
44
+ end
45
+ end
@@ -0,0 +1,31 @@
1
+ class User
2
+ include Formotion::Formable
3
+
4
+ attr_accessor :name, :score, :team
5
+
6
+ form_property :name, :string
7
+ form_property :score, :number, transform: lambda { |value| value.to_i }
8
+
9
+ form_property :team, :picker, items: ["Red", "Blue", "Green"]
10
+
11
+ form_title "Edit User"
12
+
13
+ def initialize(name, score, team)
14
+ self.name = name
15
+ self.score = score
16
+ self.team = team
17
+ end
18
+ end
19
+
20
+ class AwesomeUser < User
21
+ end
22
+
23
+ describe "Formotion::Formable w/ Subclasses" do
24
+ it "should work" do
25
+ user = User.new("Harry", 100, "Green")
26
+ awesome = AwesomeUser.new("Clay", 200, "Red")
27
+
28
+ user.to_form.title.should == awesome.to_form.title
29
+ user.class.form_properties.should == awesome.class.form_properties
30
+ end
31
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: formotion
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-06 00:00:00.000000000 Z
12
+ date: 2012-10-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bubble-wrap
@@ -145,6 +145,8 @@ files:
145
145
  - lib/formotion/version.rb
146
146
  - spec/form/persist_spec.rb
147
147
  - spec/form_spec.rb
148
+ - spec/formable/kvo_spec.rb
149
+ - spec/formable/subclass_spec.rb
148
150
  - spec/formable_spec.rb
149
151
  - spec/functional/character_spec.rb
150
152
  - spec/functional/check_row_spec.rb
@@ -194,7 +196,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
194
196
  version: '0'
195
197
  segments:
196
198
  - 0
197
- hash: -1236886504313804300
199
+ hash: 397181298113025173
198
200
  required_rubygems_version: !ruby/object:Gem::Requirement
199
201
  none: false
200
202
  requirements:
@@ -203,7 +205,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
203
205
  version: '0'
204
206
  segments:
205
207
  - 0
206
- hash: -1236886504313804300
208
+ hash: 397181298113025173
207
209
  requirements: []
208
210
  rubyforge_project:
209
211
  rubygems_version: 1.8.23
@@ -213,6 +215,8 @@ summary: Making iOS Forms insanely great with RubyMotion
213
215
  test_files:
214
216
  - spec/form/persist_spec.rb
215
217
  - spec/form_spec.rb
218
+ - spec/formable/kvo_spec.rb
219
+ - spec/formable/subclass_spec.rb
216
220
  - spec/formable_spec.rb
217
221
  - spec/functional/character_spec.rb
218
222
  - spec/functional/check_row_spec.rb