ProMotion-form 0.2.4 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b922948c52029bb1454414b2e927d91b440d6e43
4
- data.tar.gz: e10fcd0f56e5e7c26aa9a5734becfb985d5c7829
3
+ metadata.gz: a9e98a207439d8f6f934f0cf7e0ad64b0b856158
4
+ data.tar.gz: 35513b987a9c722aa6c4df7de95d5c0dbf5cd66e
5
5
  SHA512:
6
- metadata.gz: 9d5cd76b789dff0ef1f5e0b4a3a2ac7817913bd30f84397daec58603373b50e911deefcf24506706c7654c2b014baa3704cb7b3a15342447e75a74b35b97909f
7
- data.tar.gz: 58a88eb9ea2edf44d47c19b0e368c23d8c9afe1b6ba7f9ae666aa24b97927f0865cadfc2690066be1d3374405e1dd371f9623077bb6665568ea6f30f1f3f2529
6
+ metadata.gz: 2dc1a5e2e9fd723142c4fbd53de5412669a36a963b7a68fe758f2e21cf319f64d2f0138fffedd85830814ca7adba7ac9557cb3e14937321d7133abed1f4a4bf7
7
+ data.tar.gz: 57e88697ef4ce65a8d8b7b5df6023056dc89562223c7f8269f1222a2eda683b3fc349b674271e3b000058687d76c4a40063e6a333f296a96c1d18a301e74a7d5
data/README.md CHANGED
@@ -1,11 +1,11 @@
1
1
  # ProMotion-form
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/ProMotion-form.svg)](http://badge.fury.io/rb/ProMotion-form) [![Build Status](https://travis-ci.org/clearsightstudio/ProMotion-form.svg)](https://travis-ci.org/clearsightstudio/ProMotion-form) [![Code Climate](https://codeclimate.com/github/clearsightstudio/ProMotion-form/badges/gpa.svg)](https://codeclimate.com/github/clearsightstudio/ProMotion-form)
3
+ [![Gem Version](https://badge.fury.io/rb/ProMotion-form.svg)](http://badge.fury.io/rb/ProMotion-form) [![Build Status](https://travis-ci.org/clearsightstudio/ProMotion-form.svg?branch=master)](https://travis-ci.org/clearsightstudio/ProMotion-form) [![Code Climate](https://codeclimate.com/github/clearsightstudio/ProMotion-form/badges/gpa.svg)](https://codeclimate.com/github/clearsightstudio/ProMotion-form)
4
4
 
5
5
  ProMotion-form provides a PM::FormScreen for the
6
6
  popular RubyMotion gem [ProMotion](https://github.com/clearsightstudio/ProMotion).
7
7
 
8
- ![form](http://clrsight.co/jh/Screen_Shot_2014-08-29_at_4.03.13_PM.png?+)
8
+ ![form](http://i.imgur.com/pQbGqK1.png)
9
9
 
10
10
  ## Installation
11
11
 
@@ -24,7 +24,7 @@ $ rake pod:install
24
24
 
25
25
  Easily create a form screen. Powered by the CocoaPod [FXForms](https://github.com/nicklockwood/FXForms).
26
26
 
27
- *Has all the methods of PM::Screen*
27
+ #### Has all the methods of PM::Screen
28
28
 
29
29
  ```ruby
30
30
  class MyFormScreen < PM::FormScreen
@@ -51,6 +51,35 @@ class MyFormScreen < PM::FormScreen
51
51
  end
52
52
  ```
53
53
 
54
+ #### Can also be driven by properties available in [FXForms](https://github.com/nicklockwood/FXForms) Docs.
55
+
56
+ ```ruby
57
+ class MyFormScreen < PM::FormScreen
58
+ title "My Form"
59
+
60
+ def form_data
61
+ [{
62
+ title: "Account Information",
63
+ footer: "Some help text",
64
+ cells: [{
65
+ key: "email",
66
+ label: "ID",
67
+ type: :email,
68
+ "textLabel.font" => UIFont.fontWithName('Helvetica-Light', size: 25),
69
+ value: current_user.email,
70
+ }, {
71
+ key: "password",
72
+ label: "New Password",
73
+ type: :password,
74
+ "textLabel.color" => UIColor.blueColor,
75
+ value: "",
76
+ }]
77
+ }]
78
+ end
79
+
80
+ end
81
+ ```
82
+
54
83
  ### What about Formotion?
55
84
 
56
85
  We have used and like Formotion for some form-heavy apps, but it's a rather bulky gem. ProMotion-form works better with ProMotion and is a lot smaller.
@@ -97,11 +126,20 @@ class AccountScreen < PM::FormScreen
97
126
  end
98
127
  ```
99
128
 
100
- All possible form field properties:
129
+ All form field properties from FXForms are exposed. A full listing can be found [here in their Readme](https://github.com/nicklockwood/FXForms#form-field-properties).
130
+
131
+ Additional "helper" field properties have been started, and are listed below:
132
+ * `name` - a convenience alias to FXForms `key`. If no name is provided, title is converted to a symbol and used as the key.
133
+ * `title` - when no title is provided, label and then name are used respectively.
134
+ * `cell_class` - a convenience alias to FXForms `cell`, but with the ProMotion naming scheme.
135
+ }
136
+ ```
137
+
138
+ Here are sample form fields with some explanation
101
139
 
102
140
  ```ruby
103
141
  {
104
- label: "Name", # or title:
142
+ label: "Name", # or title
105
143
  name: :name, # defaults to symbol of snake_cased label/title
106
144
  type: :string, # :default is default...like a button
107
145
  options: [ "Water", "Fire", "Wind" ], # for a subform select (`type` can be anything)
@@ -112,7 +150,7 @@ All possible form field properties:
112
150
  }
113
151
  ```
114
152
 
115
- ##### Types of fields:
153
+ ##### Field types:
116
154
 
117
155
  * `:default`
118
156
  * `:label`
@@ -124,7 +162,7 @@ All possible form field properties:
124
162
  * `:password`
125
163
  * `:number`
126
164
  * `:integer`
127
- * `:unsigned` - Coming soon
165
+ * `:unsigned`
128
166
  * `:float`
129
167
  * `:bitfield`
130
168
  * `:boolean`
@@ -134,10 +172,76 @@ All possible form field properties:
134
172
  * `:datetime`
135
173
  * `:image`
136
174
 
175
+ ##### Helper keys:
176
+
177
+ * `:cell` or `:cell_class` - use a custom cell class
178
+ * `:properties` - a flexible way to set cell properties (see Styling section below)
179
+ * string keys - you can also define styling parameters as top-level strings
180
+
181
+ ## Styling
182
+
183
+ #### Method 1: Put them into a hash
184
+
185
+ ```
186
+ properties: {
187
+ "accessoryView" => CustomAccessory.new,
188
+ "backgroundColor" => UIColor.colorWhite,
189
+ "detailTextLabel.font" => UIFont.fontWithName("MyFont", size:20),
190
+ },
191
+ }
192
+ ```
193
+
194
+ #### Method 2: Use the `style` helper
195
+
196
+ ```
197
+ def styles
198
+ {
199
+ basic: {
200
+ "accessoryView" => CustomAccessory.new,
201
+ "detailTextLabel.font" => UIFont.fontWithName("MyFont", size:20),
202
+ },
203
+ }
204
+ end
205
+
206
+ ...
207
+
208
+ properties: style(:basic),
209
+ }
210
+ ```
211
+
212
+ #### Method 3: Combine styles
213
+
214
+ ```
215
+ def styles
216
+ {
217
+ basic: {
218
+ "accessoryView" => CustomAccessory.new,
219
+ "detailTextLabel.font" => UIFont.fontWithName("MyFont", size:20),
220
+ },
221
+ alert: {
222
+ "backgroundColor" => UIColor.redColor,
223
+ },
224
+ }
225
+ end
226
+
227
+ ...
228
+
229
+ properties: style(:basic, :alert),
230
+ }
231
+ ```
232
+
233
+ #### Method 4: Combine styles, with overrides (using '+')
234
+
235
+ ```
236
+ properties: style(:basic, :alert) + {
237
+ "backgroundColor" => UIColor.yellowColor,
238
+ },
239
+ }
240
+ ```
137
241
 
138
242
  #### update_form_data
139
243
 
140
- Forces a reload of the form.
244
+ Forces a reload of the form. This is useful when you have changed the hash you returned in your `form_data` method.
141
245
 
142
246
  #### render_form
143
247
 
@@ -7,7 +7,9 @@ require 'motion-cocoapods'
7
7
  Motion::Project::App.setup do |app|
8
8
  lib_dir_path = File.dirname(File.expand_path(__FILE__))
9
9
  app.files << File.join(lib_dir_path, "ProMotion/form/form_view_controller.rb")
10
+ app.files << File.join(lib_dir_path, "ProMotion/form/form_style.rb")
10
11
  app.files << File.join(lib_dir_path, "ProMotion/form/form.rb")
12
+ app.files << File.join(lib_dir_path, "ProMotion/form/form_screen_style.rb")
11
13
  app.files << File.join(lib_dir_path, "ProMotion/form/form_screen.rb")
12
14
 
13
15
  app.pods do
@@ -47,15 +47,20 @@ module ProMotion
47
47
 
48
48
  def input_data(input)
49
49
  data = {}
50
- data[:key] = input[:name] || input[:title].downcase.gsub(/[^0-9a-z]/i, '_').to_sym
51
- data[:type] = input[:type] if input[:type]
52
- data[:title] = input[:label] || input[:title] || input[:name].to_s
53
- data[:options] = input[:options] if input[:options]
54
- data[:placeholder] = input[:placeholder] if input[:placeholder]
55
- data[:default] = input[:default] if input[:default]
56
- data[:value] = input[:value] if input[:value]
57
- data[:action] = input[:action] if input[:action]
58
- data[:cell] = input[:cell_class] if input[:cell_class]
50
+
51
+ # process "before" helper keys
52
+ data.update(FormStyle.to_style(input[:properties])) if input[:properties]
53
+ data.update(FormStyle.to_style(input[:style ])) if input[:style ]
54
+
55
+ # pass non-helper keys to FXForms
56
+ helpers = [ :cell_class, :name, :style, :properties ]
57
+ (input.keys - helpers).each {|key| data[key] = input[key] }
58
+
59
+ # process "after" helper keys
60
+ data[:key ] ||= input[:name ] || input[:title].downcase.gsub(/[^0-9a-z]/i, '_').to_sym
61
+ data[:title] ||= input[:label] || input[:name ].to_s
62
+ data[:cell ] ||= input[:cell_class] if input[:cell_class]
63
+
59
64
  data
60
65
  end
61
66
 
@@ -71,41 +76,44 @@ module ProMotion
71
76
  end
72
77
  end
73
78
 
74
- # static NSString *const key = @"key";
75
- # static NSString *const FXFormFieldType = @"type";
76
- # static NSString *const FXFormFieldClass = @"class";
77
- # static NSString *const cell = @"cell";
78
- # static NSString *const title = @"title";
79
- # static NSString *const placeholder = @"placeholder";
80
- # static NSString *const default = @"default";
81
- # static NSString *const options = @"options";
82
- # static NSString *const FXFormFieldTemplate = @"template";
83
- # static NSString *const valueTransformer = @"valueTransformer";
84
- # static NSString *const action = @"action";
85
- # static NSString *const FXFormFieldSegue = @"segue";
86
- # static NSString *const header = @"header";
87
- # static NSString *const FXFormFieldFooter = @"footer";
88
- # static NSString *const FXFormFieldInline = @"inline";
89
- # static NSString *const FXFormFieldSortable = @"sortable";
90
- # static NSString *const FXFormFieldViewController = @"viewController";
91
-
92
- # static NSString *const FXFormFieldTypeDefault = @"default";
93
- # static NSString *const FXFormFieldTypeLabel = @"label";
94
- # static NSString *const FXFormFieldTypeText = @"text";
95
- # static NSString *const :longtext = @"longtext";
96
- # static NSString *const FXFormFieldTypeURL = @"url";
97
- # static NSString *const FXFormFieldTypeEmail = @"email";
98
- # static NSString *const FXFormFieldTypePhone = @"phone";
99
- # static NSString *const FXFormFieldTypePassword = @"password";
100
- # static NSString *const FXFormFieldTypeNumber = @"number";
101
- # static NSString *const FXFormFieldTypeInteger = @"integer";
102
- # static NSString *const FXFormFieldTypeUnsigned = @"unsigned";
103
- # static NSString *const FXFormFieldTypeFloat = @"float";
104
- # static NSString *const :bitfield = @"bitfield";
105
- # static NSString *const FXFormFieldTypeBoolean = @"boolean";
106
- # static NSString *const :option = @"option";
107
- # static NSString *const FXFormFieldTypeDate = @"date";
108
- # static NSString *const FXFormFieldTypeTime = @"time";
109
- # static NSString *const FXFormFieldTypeDateTime = @"datetime";
110
- # static NSString *const FXFormFieldTypeImage = @"image";
79
+ # Fields
80
+ # ======
81
+ # NSString *const FXFormFieldKey = @"key";
82
+ # NSString *const FXFormFieldType = @"type";
83
+ # NSString *const FXFormFieldClass = @"class";
84
+ # NSString *const FXFormFieldCell = @"cell";
85
+ # NSString *const FXFormFieldTitle = @"title";
86
+ # NSString *const FXFormFieldPlaceholder = @"placeholder";
87
+ # NSString *const FXFormFieldDefaultValue = @"default";
88
+ # NSString *const FXFormFieldOptions = @"options";
89
+ # NSString *const FXFormFieldTemplate = @"template";
90
+ # NSString *const FXFormFieldValueTransformer = @"valueTransformer";
91
+ # NSString *const FXFormFieldAction = @"action";
92
+ # NSString *const FXFormFieldSegue = @"segue";
93
+ # NSString *const FXFormFieldHeader = @"header";
94
+ # NSString *const FXFormFieldFooter = @"footer";
95
+ # NSString *const FXFormFieldInline = @"inline";
96
+ # NSString *const FXFormFieldSortable = @"sortable";
97
+ # NSString *const FXFormFieldViewController = @"viewController";
111
98
 
99
+ # Types
100
+ # =====
101
+ # NSString *const FXFormFieldTypeDefault = @"default";
102
+ # NSString *const FXFormFieldTypeLabel = @"label";
103
+ # NSString *const FXFormFieldTypeText = @"text";
104
+ # NSString *const FXFormFieldTypeLongText = @"longtext";
105
+ # NSString *const FXFormFieldTypeURL = @"url";
106
+ # NSString *const FXFormFieldTypeEmail = @"email";
107
+ # NSString *const FXFormFieldTypePhone = @"phone";
108
+ # NSString *const FXFormFieldTypePassword = @"password";
109
+ # NSString *const FXFormFieldTypeNumber = @"number";
110
+ # NSString *const FXFormFieldTypeInteger = @"integer";
111
+ # NSString *const FXFormFieldTypeUnsigned = @"unsigned";
112
+ # NSString *const FXFormFieldTypeFloat = @"float";
113
+ # NSString *const FXFormFieldTypeBitfield = @"bitfield";
114
+ # NSString *const FXFormFieldTypeBoolean = @"boolean";
115
+ # NSString *const FXFormFieldTypeOption = @"option";
116
+ # NSString *const FXFormFieldTypeDate = @"date";
117
+ # NSString *const FXFormFieldTypeTime = @"time";
118
+ # NSString *const FXFormFieldTypeDateTime = @"datetime";
119
+ # NSString *const FXFormFieldTypeImage = @"image";
@@ -1,6 +1,7 @@
1
1
  module ProMotion
2
- class FormScreen < PM::FormViewController
2
+ class FormScreen < FormViewController
3
3
  include ProMotion::ScreenModule
4
+ include ProMotion::FormScreenStyle
4
5
 
5
6
  attr_reader :form_object
6
7
 
@@ -28,6 +29,5 @@ module ProMotion
28
29
  def render_form
29
30
  Hash[form_object.each_pair.to_a].tap{|h| h.delete(:fields) }
30
31
  end
31
-
32
32
  end
33
33
  end
@@ -0,0 +1,21 @@
1
+ module ProMotion
2
+ module FormScreenStyle
3
+ def style(*ary)
4
+ @form_styles ||= styles
5
+ @form_styles_cache ||= {}
6
+ @form_styles_cache[ary * ':'] ||= ary.inject(PM::FormStyle.new) do |all, one|
7
+ one ? (all << @form_styles[one]) : all
8
+ end
9
+ end
10
+
11
+ def style!(*ary)
12
+ @form_style_sticky = ary.empty? ? nil : ary
13
+ style(*ary)
14
+ end
15
+
16
+ def style?(*ary)
17
+ ary.unshift(*@form_style_sticky) if @form_style_sticky
18
+ style(*ary)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,28 @@
1
+ module ProMotion
2
+ class FormStyle < Hash
3
+ def initialize(obj=nil)
4
+ replace(obj) if obj.kind_of? Hash
5
+ end
6
+
7
+ def +(obj)
8
+ merge(obj || {})
9
+ end
10
+
11
+ def <<(obj)
12
+ merge!(obj || {})
13
+ end
14
+
15
+ def self.to_style(obj, out={}, ary=[])
16
+ obj.each do |key, val|
17
+ case val
18
+ when Hash then next to_style(val, out, ary + [key.to_s])
19
+ when Class then val = val.new
20
+ when Proc then val = val.call
21
+ end
22
+ all = (ary + [key.to_s]) * '.'
23
+ val ? (out[all] = val) : out.delete(all)
24
+ end
25
+ out
26
+ end
27
+ end
28
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ProMotion-form
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jamon Holmgren
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-30 00:00:00.000000000 Z
11
+ date: 2014-11-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ProMotion
@@ -91,6 +91,8 @@ files:
91
91
  - lib/ProMotion-form.rb
92
92
  - lib/ProMotion/form/form.rb
93
93
  - lib/ProMotion/form/form_screen.rb
94
+ - lib/ProMotion/form/form_screen_style.rb
95
+ - lib/ProMotion/form/form_style.rb
94
96
  - lib/ProMotion/form/form_view_controller.rb
95
97
  homepage: https://github.com/clearsightstudio/ProMotion-form
96
98
  licenses:
@@ -117,4 +119,3 @@ signing_key:
117
119
  specification_version: 4
118
120
  summary: Adds PM::FormScreen support to ProMotion, similar to Formotion but lighter.
119
121
  test_files: []
120
- has_rdoc: