motion-prime 0.1.6 → 0.1.7

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.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- Yzc2NmYzMWIzZTRkOTA3ODFjZjc0NTdkYWM0ZmVjMTQ0OTU1OGM4Yw==
4
+ MjdhZjg1NjJhYTYxNGZlMTA1ZWNkZGQ0ZmUwZTg3YzdiZjBkM2MyNw==
5
5
  data.tar.gz: !binary |-
6
- YWUzZWRiOTRjMmQyOTcyYzQzMjFhZWY4YzM0MDY0MzYwZDkzZThlOA==
6
+ Mjg3NjUzNDE3ZTA1ZDVkZmZmZWMwNDUwMmMxZjlhNDczN2I5NWVjNg==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- ZDNhMTg1MmYxYjhkMTE3MTAzMjAyY2M0NjAzODE4Mjc0ZjZmOTIxMzNkNmQ3
10
- Y2Q2MTlmNmYzMGI5YWE5YjExZmUwNWE3N2FkNWY2YzNmMmI5ZDU4OTliZDI2
11
- MzUxMzg5NGVmMWVkMjk0MDQxYjlmZWY2OGYzYzUzNGJjMjcyNTk=
9
+ MWVjMjhiMThkMjk3N2M1NWQ5MzU4ZjBjMDc3MWY5MmFiYzEwMWFlN2NlNzE0
10
+ OTM0NzM5NDMwZDMxNjhlODAzNjdiN2I3MmMyMGFlNDhiYjhjZmQ3MjFlOGI5
11
+ NjkzZTM5ZTQzZDNhMDMyZjgyYzg4MmUzYjYyZDI5ZGUzMjY1OWI=
12
12
  data.tar.gz: !binary |-
13
- YmI1OTU0YTVjYjE1NDY3MzJkMGMwZmJkOGVlZGVlOGJlZTllNjA1ODVjMzg1
14
- YWUxMDlhOGE1N2Q2YTY1ODVlNjhiYjVmOGUwN2JmYjYxYjJmZjg2MWU1ZTBi
15
- NTMwM2YwYTFkOGRmNmU1NjJhNDc5NjNiYzZmODk3ZTYzYzE2OTA=
13
+ MDY1MzIwNjJlOThmN2Q2NWZhZjI0YjJkMDZlMzBhNDI2MTc3MjZhNmYzMmRj
14
+ MGI2ODFhNWVlY2MyMjBhNTc4M2VjN2E2ZmM2ZWJlZDE1MGM2ODVmOTE1NjNk
15
+ YjNhZGYwNjZiZDRkMzQwZmIyYzBhMTRlNGFjZjdjODAxMzcyNzM=
@@ -1,3 +1,7 @@
1
+ === 0.1.7
2
+ * MP::BaseModel#fetch_associations now supports callback option
3
+ * MP::LabelDrawElement now supports `size_to_fit` option
4
+
1
5
  === 0.1.6
2
6
  * Section container options now support proc values
3
7
 
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- motion-prime (0.1.6)
4
+ motion-prime (0.1.7)
5
5
  bubble-wrap
6
6
  cocoapods
7
7
  motion-cocoapods
@@ -6,12 +6,18 @@ module MotionPrime
6
6
  def draw_in(rect)
7
7
  options = computed_options
8
8
  return if options[:hidden]
9
+
10
+ if options[:size_to_fit]
11
+ @computed_options[:height] = outer_height
12
+ end
13
+
9
14
  color = options[:text_color]
10
15
  color.uicolor.set if color
16
+ font = options[:font] || :system
11
17
  if options[:number_of_lines] != 0
12
18
  options[:text].to_s.drawAtPoint(
13
19
  CGPointMake(computed_left, computed_top),
14
- withFont: options[:font].uifont
20
+ withFont: font.uifont
15
21
  )
16
22
  else
17
23
  rect = CGRectMake(
@@ -20,7 +26,7 @@ module MotionPrime
20
26
  line_break = options.has_key?(:line_break_mode) ? options[:line_break_mode] : :wordwrap
21
27
  alignment = options.has_key?(:text_alignment) ? options[:text_alignment] : :left
22
28
  options[:text].to_s.drawInRect(
23
- rect, withFont: options[:font].uifont,
29
+ rect, withFont: font.uifont,
24
30
  lineBreakMode: line_break.uilinebreakmode,
25
31
  alignment: alignment.uitextalignment
26
32
  )
@@ -6,7 +6,7 @@ motion_require './store.rb'
6
6
  motion_require './store_extension.rb'
7
7
  module MotionPrime
8
8
  class BaseModel < NSFNanoObject
9
- class_attribute :sync_url
9
+ class_attribute :_sync_url
10
10
  class_attribute :_updatable_attributes
11
11
  class_attribute :_associations
12
12
  alias_method :attributes, :info
@@ -21,7 +21,7 @@ module MotionPrime
21
21
  extend MotionPrime::ModelAssociationClassMethods
22
22
 
23
23
  def sync_url
24
- self.class.sync_url.to_s.gsub(':id', id.to_s)
24
+ normalize_sync_url(self.class.sync_url)
25
25
  end
26
26
 
27
27
  def model_name
@@ -53,6 +53,9 @@ module MotionPrime
53
53
  should_fetch = sync_options[:fetch]
54
54
  should_update = sync_options[:update]
55
55
 
56
+ should_fetch = false if sync_url.blank?
57
+ should_update = false if sync_url.blank?
58
+
56
59
  should_fetch = !new_record? if should_fetch.nil?
57
60
  should_update = new_record? if should_update.nil?
58
61
 
@@ -62,10 +65,15 @@ module MotionPrime
62
65
  end if should_fetch
63
66
  update_with_url self.sync_url do
64
67
  save if sync_options[:save]
65
- block.call if use_callback
68
+
69
+ # run callback only if it wasn't run on fetch
70
+ block.call if use_callback && !should_fetch
66
71
  end if should_update
67
72
 
68
- fetch_associations(sync_options)
73
+ fetch_associations(sync_options) do
74
+ # run callback only if it wasn't run on fetch or update
75
+ block.call if use_callback && !should_fetch && !should_update
76
+ end
69
77
  end
70
78
 
71
79
  # fetch from server using url
@@ -99,9 +107,16 @@ module MotionPrime
99
107
  block.call(self) if block_given?
100
108
  end
101
109
 
102
- def fetch_associations(sync_options = {})
103
- (self.class._associations || []).each do |key, options|
104
- fetch_association(key, sync_options)
110
+ def fetch_associations(sync_options = {}, &block)
111
+ use_callback = block_given?
112
+ associations = self.class._associations || {}
113
+
114
+ associations.keys.each_with_index do |key, index|
115
+ if use_callback && associations.count - 1 == index
116
+ fetch_association(key, sync_options, &block)
117
+ else
118
+ fetch_association(key, sync_options)
119
+ end
105
120
  end
106
121
  end
107
122
 
@@ -117,7 +132,8 @@ module MotionPrime
117
132
  old_collection = self.send(key)
118
133
  use_callback = block_given?
119
134
  puts "SYNC: started sync for #{key} in #{self.class.name}"
120
- api_client.get(options[:sync_url]) do |data|
135
+ api_client.get normalize_sync_url(options[:sync_url]) do |data|
136
+ data = data[options[:sync_key]] if options[:sync_key]
121
137
  if data.present?
122
138
  # Update/Create existing records
123
139
  data.each do |attributes|
@@ -167,9 +183,13 @@ module MotionPrime
167
183
  end
168
184
  end
169
185
 
186
+ def normalize_sync_url(url)
187
+ url.to_s.gsub(':id', id.to_s)
188
+ end
189
+
170
190
  class << self
171
191
  def sync_url(url = nil)
172
- url ? self.sync_url = url : super
192
+ url ? self._sync_url = url : self._sync_url
173
193
  end
174
194
 
175
195
  def updatable_attributes(*attrs)
@@ -0,0 +1,32 @@
1
+ module MotionPrime
2
+ class DateFieldSection < BaseFieldSection
3
+ container height: 190
4
+ element :label, type: :label do
5
+ {
6
+ styles: [
7
+ :base_field_label,
8
+ :base_date_picker_field_label,
9
+ :"#{form_name}_field_label",
10
+ :"#{form_name}_#{name}_field_label"
11
+ ]
12
+ }.merge(options[:label] || {})
13
+ end
14
+ element :date_picker, type: :date_picker do
15
+ {
16
+ styles: [
17
+ :base_date_picker,
18
+ :"#{form_name}_date_picker",
19
+ :"#{form_name}_#{name}_date_picker"
20
+ ]
21
+ }
22
+ end
23
+
24
+ after_render :bind_date_picker
25
+
26
+ def bind_date_picker
27
+ picker = view(:date_picker)
28
+ picker.setDelegate form
29
+ picker.setDate NSDate.date, animated: true
30
+ end
31
+ end
32
+ end
@@ -100,4 +100,9 @@ MotionPrime::Styles.define :base do
100
100
 
101
101
  style :google_map,
102
102
  top: 0, left: 0, right: 0, bottom: 0
103
+
104
+ style :date_picker,
105
+ width: 300,
106
+ height: 150,
107
+ top: 30, left: 0
103
108
  end
@@ -1,3 +1,3 @@
1
1
  module MotionPrime
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.7"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: motion-prime
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Iskander Haziev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-25 00:00:00.000000000 Z
11
+ date: 2013-08-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -223,6 +223,7 @@ files:
223
223
  - motion-prime/sections/draw.rb
224
224
  - motion-prime/sections/form.rb
225
225
  - motion-prime/sections/form/base_field_section.rb
226
+ - motion-prime/sections/form/date_field_section.rb
226
227
  - motion-prime/sections/form/password_field_section.rb
227
228
  - motion-prime/sections/form/select_field_section.rb
228
229
  - motion-prime/sections/form/string_field_section.rb