motion-prime 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/CHANGELOG.md +6 -0
- data/Gemfile.lock +1 -1
- data/doc/FAQ.md +2 -0
- data/lib/motion-prime.rb +0 -7
- data/motion-prime/elements/base.rb +2 -2
- data/motion-prime/elements/draw.rb +4 -4
- data/motion-prime/helpers/has_authorization.rb +7 -2
- data/motion-prime/models/association.rb +2 -2
- data/motion-prime/models/base.rb +66 -48
- data/motion-prime/sections/form/base_field_section.rb +1 -1
- data/motion-prime/sections/form.rb +0 -2
- data/motion-prime/sections/table.rb +0 -2
- data/motion-prime/support/dm_cell_with_section.rb +1 -1
- data/motion-prime/support/dm_view_with_section.rb +1 -1
- data/motion-prime/version.rb +1 -1
- data/motion-prime/views/view_builder.rb +14 -14
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NzcwMzdlNzc2NDFkODU4MzU1MzA2NjQ1NjcxYTg2MWMyODJmODkwYg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MTcyZjUyODMwN2ZjMzAyMzU3NzVkZmNmYjA0MzY0ODY1ODliMDEyMQ==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZTBlOTI1M2I0NDkyZmNiNzg5YWVjOTIwYzViYTQyZTZmNjdmM2U4MTIxY2Uz
|
10
|
+
YmVjMjQ4MGZkYjcxODY1MTRkMDkxYzQ1YTFiODY3MmEzM2M5Nzk4NzBkMDVi
|
11
|
+
OGUwYTI4ZTY0ZDVkMmNmN2Y2N2YzMGYyYzgwMjhkYjdhMzIyZTE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NTFmZmNmZmU4YWNmZjUzY2VjNjY3NGEyZjQ4ZGU1YTYzYTc5ZTg5NGEwMTJm
|
14
|
+
N2FmMDA3YTg2ZjIzNDI2NTZkMzRjNDMwNmQ0ODhkZmI1YWVjNTRhZThlYzY3
|
15
|
+
ZjgwZmI4ZjhjNmM2NTBjMDBjYzVhYzg5MzU1NDhkNDA1Yjg3YmI=
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
=== 0.1.4 (Breaking changes)
|
2
|
+
* MotionPrime::BaseModel#sync_with_url renamed to fetch_with_url
|
3
|
+
* MotionPrime::BaseModel#sync_with_attributes renamed to fetch_with_attributes
|
4
|
+
* MotionPrime::BaseModel#sync_association renamed to fetch_association
|
5
|
+
* MotionPrime::BaseModel#sync_attributes renamed to updatable_attributes
|
6
|
+
|
1
7
|
=== 0.1.3
|
2
8
|
* added google map element support
|
3
9
|
* fixes for tabbed section
|
data/Gemfile.lock
CHANGED
data/doc/FAQ.md
ADDED
data/lib/motion-prime.rb
CHANGED
@@ -3,12 +3,5 @@ require 'motion-require'
|
|
3
3
|
Motion::Require.all(Dir.glob(File.expand_path('../../motion-prime/**/*.rb', __FILE__)))
|
4
4
|
|
5
5
|
Motion::Project::App.setup do |app|
|
6
|
-
app.pods do
|
7
|
-
pod 'PKRevealController'
|
8
|
-
pod 'NanoStore', '~> 2.7.7'
|
9
|
-
pod 'SDWebImage'
|
10
|
-
pod 'SVPullToRefresh'
|
11
|
-
pod 'MBAlertView'
|
12
|
-
end
|
13
6
|
app.detect_dependencies = false
|
14
7
|
end
|
@@ -11,7 +11,7 @@ module MotionPrime
|
|
11
11
|
|
12
12
|
def initialize(options = {})
|
13
13
|
@options = options
|
14
|
-
@section =
|
14
|
+
@section = options.delete(:section)
|
15
15
|
@name = options[:name]
|
16
16
|
@block = options.delete(:block)
|
17
17
|
@view_class = options.delete(:view_class) || "UIView"
|
@@ -19,7 +19,7 @@ module MotionPrime
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def render(options = {}, &block)
|
22
|
-
|
22
|
+
@screen = options[:to]
|
23
23
|
run_callbacks :render do
|
24
24
|
render!(&block)
|
25
25
|
end
|
@@ -24,9 +24,9 @@ module MotionPrime
|
|
24
24
|
|
25
25
|
# calculate width if width is relative, e.g 0.7
|
26
26
|
if width > 0 && width <= 1
|
27
|
-
|
27
|
+
width * computed_max_width
|
28
28
|
else
|
29
|
-
|
29
|
+
width > computed_max_width ? computed_max_width : width
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
@@ -36,9 +36,9 @@ module MotionPrime
|
|
36
36
|
|
37
37
|
# calculate height if height is relative, e.g 0.7
|
38
38
|
if height > 0 && height <= 1
|
39
|
-
|
39
|
+
height * computed_max_height
|
40
40
|
else
|
41
|
-
|
41
|
+
height > computed_max_height ? computed_max_height : height
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
@@ -1,10 +1,15 @@
|
|
1
1
|
module MotionPrime
|
2
2
|
module HasAuthorization
|
3
3
|
def current_user
|
4
|
-
|
4
|
+
if defined?(User) && User.respond_to?(:current)
|
5
|
+
@current_user = User.current
|
6
|
+
end
|
7
|
+
end
|
8
|
+
def user_signed_in?
|
9
|
+
current_user.present?
|
5
10
|
end
|
6
11
|
def api_client
|
7
|
-
@api_client ||= ApiClient.new(access_token: current_user.access_token)
|
12
|
+
@api_client ||= ApiClient.new(access_token: current_user.try(:access_token))
|
8
13
|
end
|
9
14
|
end
|
10
15
|
end
|
@@ -70,7 +70,7 @@ module MotionPrime
|
|
70
70
|
self.send(bag_name).clear
|
71
71
|
|
72
72
|
association = association_name.classify.constantize.new
|
73
|
-
association.
|
73
|
+
association.fetch_with_attributes(value)
|
74
74
|
association.save
|
75
75
|
self.send(:"#{bag_name}") << association
|
76
76
|
association
|
@@ -97,7 +97,7 @@ module MotionPrime
|
|
97
97
|
association = []
|
98
98
|
value.each do |attrs|
|
99
99
|
model = association_name.classify.constantize.new
|
100
|
-
model.
|
100
|
+
model.fetch_with_attributes(attrs)
|
101
101
|
association << model
|
102
102
|
end
|
103
103
|
self.send(:"#{bag_name}=", association)
|
data/motion-prime/models/base.rb
CHANGED
@@ -7,7 +7,7 @@ motion_require './store_extension.rb'
|
|
7
7
|
module MotionPrime
|
8
8
|
class BaseModel < NSFNanoObject
|
9
9
|
class_attribute :sync_url
|
10
|
-
class_attribute :
|
10
|
+
class_attribute :_updatable_attributes
|
11
11
|
class_attribute :_associations
|
12
12
|
alias_method :attributes, :info
|
13
13
|
include MotionPrime::HasAuthorization
|
@@ -32,6 +32,7 @@ module MotionPrime
|
|
32
32
|
id.blank?
|
33
33
|
end
|
34
34
|
|
35
|
+
# destroy on server and delete on local
|
35
36
|
def destroy(&block)
|
36
37
|
use_callback = block_given?
|
37
38
|
api_client.delete(sync_url) do
|
@@ -40,41 +41,12 @@ module MotionPrime
|
|
40
41
|
delete
|
41
42
|
end
|
42
43
|
|
43
|
-
#
|
44
|
-
def sync_with_url(url, &block)
|
45
|
-
api_client.get(url) do |data|
|
46
|
-
if data.present?
|
47
|
-
sync_with_attributes(data, &block)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
def update_with_url(url, &block)
|
53
|
-
use_callback = block_given?
|
54
|
-
post_data = { model_name => filtered_sync_attributes}
|
55
|
-
api_client.send(id ? :put : :post, url, post_data) do |data|
|
56
|
-
self.id ||= data['id']
|
57
|
-
block.call() if use_callback
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
# set attributes
|
62
|
-
def sync_with_attributes(attrs, &block)
|
63
|
-
attrs.each do |key, value|
|
64
|
-
if respond_to?(:"sync_#{key}")
|
65
|
-
self.send(:"sync_#{key}", value)
|
66
|
-
elsif respond_to?(:"#{key}=")
|
67
|
-
self.send(:"#{key}=", value)
|
68
|
-
end
|
69
|
-
end
|
70
|
-
block.call(self) if block_given?
|
71
|
-
end
|
72
|
-
|
44
|
+
# sync with server and save on local
|
73
45
|
def sync!(sync_options = {}, &block)
|
74
46
|
sync(sync_options.merge(save: true), &block)
|
75
47
|
end
|
76
48
|
|
77
|
-
# sync with
|
49
|
+
# sync with with server
|
78
50
|
# TODO: order of fetch/update should be based on updated time
|
79
51
|
def sync(sync_options = {}, &block)
|
80
52
|
use_callback = block_given?
|
@@ -84,7 +56,7 @@ module MotionPrime
|
|
84
56
|
should_fetch = !new_record? if should_fetch.nil?
|
85
57
|
should_update = new_record? if should_update.nil?
|
86
58
|
|
87
|
-
|
59
|
+
fetch_with_url self.sync_url do
|
88
60
|
save if sync_options[:save]
|
89
61
|
block.call if use_callback
|
90
62
|
end if should_fetch
|
@@ -93,24 +65,55 @@ module MotionPrime
|
|
93
65
|
block.call if use_callback
|
94
66
|
end if should_update
|
95
67
|
|
96
|
-
|
68
|
+
fetch_associations(sync_options)
|
97
69
|
end
|
98
70
|
|
99
|
-
|
71
|
+
# fetch from server using url
|
72
|
+
def fetch_with_url(url, &block)
|
73
|
+
api_client.get(url) do |data|
|
74
|
+
if data.present?
|
75
|
+
fetch_with_attributes(data, &block)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
# update on server using url
|
81
|
+
def update_with_url(url, &block)
|
82
|
+
use_callback = block_given?
|
83
|
+
post_data = { model_name => filtered_updatable_attributes}
|
84
|
+
api_client.send(id ? :put : :post, url, post_data) do |data|
|
85
|
+
self.id ||= data['id']
|
86
|
+
block.call() if use_callback
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
# set attributes, using fetch
|
91
|
+
def fetch_with_attributes(attrs, &block)
|
92
|
+
attrs.each do |key, value|
|
93
|
+
if respond_to?(:"fetch_#{key}")
|
94
|
+
self.send(:"fetch_#{key}", value)
|
95
|
+
elsif respond_to?(:"#{key}=")
|
96
|
+
self.send(:"#{key}=", value)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
block.call(self) if block_given?
|
100
|
+
end
|
101
|
+
|
102
|
+
def fetch_associations(sync_options = {})
|
100
103
|
(self.class._associations || []).each do |key, options|
|
101
|
-
|
104
|
+
fetch_association(key, sync_options)
|
102
105
|
end
|
103
106
|
end
|
104
107
|
|
105
|
-
def
|
108
|
+
def fetch_association(key, sync_options = {}, &block)
|
106
109
|
options = self.class._associations[key]
|
107
110
|
return unless options[:sync_url]
|
108
111
|
options[:type] == :many ?
|
109
|
-
|
110
|
-
|
112
|
+
fetch_has_many(key, options, sync_options, &block) :
|
113
|
+
fetch_has_one(key, options, sync_options, &block)
|
111
114
|
end
|
112
115
|
|
113
|
-
def
|
116
|
+
def fetch_has_many(key, options = {}, sync_options = {}, &block)
|
114
117
|
old_collection = self.send(key)
|
115
118
|
use_callback = block_given?
|
116
119
|
puts "SYNC: started sync for #{key} in #{self.class.name}"
|
@@ -123,7 +126,7 @@ module MotionPrime
|
|
123
126
|
model = key.singularize.to_s.classify.constantize.new
|
124
127
|
self.send(:"#{key}_bag") << model
|
125
128
|
end
|
126
|
-
model.
|
129
|
+
model.fetch_with_attributes(attributes)
|
127
130
|
model.save if sync_options[:save]
|
128
131
|
end
|
129
132
|
old_collection.each do |old_model|
|
@@ -142,7 +145,7 @@ module MotionPrime
|
|
142
145
|
end
|
143
146
|
end
|
144
147
|
|
145
|
-
def
|
148
|
+
def fetch_has_one(key, options = {}, &block)
|
146
149
|
# TODO: add implementation
|
147
150
|
end
|
148
151
|
|
@@ -150,10 +153,16 @@ module MotionPrime
|
|
150
153
|
"#<#{self.class}:0x#{self.object_id.to_s(16)}> " + MotionPrime::JSON.generate(attributes)
|
151
154
|
end
|
152
155
|
|
153
|
-
def
|
154
|
-
return attributes if self.class.
|
155
|
-
|
156
|
-
|
156
|
+
def filtered_updatable_attributes
|
157
|
+
return attributes if self.class.updatable_attributes.blank?
|
158
|
+
self.class.updatable_attributes.to_a.inject({}) do |hash, attribute|
|
159
|
+
key, options = *attribute
|
160
|
+
if block = options[:block]
|
161
|
+
value = instance_eval(&block)
|
162
|
+
else
|
163
|
+
value = attributes[key]
|
164
|
+
end
|
165
|
+
hash.merge!(key => value)
|
157
166
|
end
|
158
167
|
end
|
159
168
|
|
@@ -162,8 +171,17 @@ module MotionPrime
|
|
162
171
|
url ? self.sync_url = url : super
|
163
172
|
end
|
164
173
|
|
165
|
-
def
|
166
|
-
|
174
|
+
def updatable_attributes(*attrs)
|
175
|
+
return self._updatable_attributes if attrs.blank?
|
176
|
+
attrs.each do |attribute|
|
177
|
+
updatable_attribute attribute
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
def updatable_attribute(attribute, options = {}, &block)
|
182
|
+
options[:block] = block if block_given?
|
183
|
+
self._updatable_attributes ||= {}
|
184
|
+
self._updatable_attributes[attribute] = options
|
167
185
|
end
|
168
186
|
end
|
169
187
|
end
|
data/motion-prime/version.rb
CHANGED
@@ -8,17 +8,17 @@ module MotionPrime
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def view_for_class(klass, root_klass, options = {})
|
11
|
-
if VIEWS_MAP.key?(klass)
|
12
|
-
VIEWS_MAP[klass].call root_klass, options
|
11
|
+
if VIEWS_MAP.key?(klass.name)
|
12
|
+
VIEWS_MAP[klass.name].call root_klass, options
|
13
13
|
else
|
14
14
|
view_for_class klass.superclass, root_klass, options
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
18
|
VIEWS_MAP = {
|
19
|
-
UIView => Proc.new {|klass, options| klass.alloc.initWithFrame CGRectZero },
|
20
|
-
UIControl => Proc.new {|klass, options| klass.alloc.init },
|
21
|
-
UIActionSheet => Proc.new {|klass, options|
|
19
|
+
'UIView' => Proc.new {|klass, options| klass.alloc.initWithFrame CGRectZero },
|
20
|
+
'UIControl' => Proc.new {|klass, options| klass.alloc.init },
|
21
|
+
'UIActionSheet' => Proc.new {|klass, options|
|
22
22
|
title = options.delete(:title) || ''
|
23
23
|
delegate = options.delete(:delegate)
|
24
24
|
cancel_button_title = options.delete(:cancel_button_title)
|
@@ -31,17 +31,17 @@ module MotionPrime
|
|
31
31
|
destructiveButtonTitle: destructive_button_title,
|
32
32
|
otherButtonTitles: other_button_titles, nil
|
33
33
|
},
|
34
|
-
UIActivityIndicatorView => Proc.new{|klass, options|
|
34
|
+
'UIActivityIndicatorView' => Proc.new{|klass, options|
|
35
35
|
style = options.delete(:style) || :large.uiactivityindicatorstyle
|
36
36
|
klass.alloc.initWithActivityIndicatorStyle style
|
37
37
|
},
|
38
|
-
UIButton => Proc.new{|klass, options|
|
38
|
+
'UIButton' => Proc.new{|klass, options|
|
39
39
|
is_custom_button = options[:background_image] || options[:title_color]
|
40
40
|
default_button_type = is_custom_button ? :custom : :rounded
|
41
41
|
button_type = (options.delete(:button_type) || default_button_type).uibuttontype
|
42
42
|
klass.buttonWithType button_type
|
43
43
|
},
|
44
|
-
UIImageView => Proc.new{|klass, options|
|
44
|
+
'UIImageView' => Proc.new{|klass, options|
|
45
45
|
image = options.delete(:image)
|
46
46
|
highlighted_image = options.delete(:highlighted_image)
|
47
47
|
|
@@ -53,29 +53,29 @@ module MotionPrime
|
|
53
53
|
klass.alloc.initWithFrame CGRectZero
|
54
54
|
end
|
55
55
|
},
|
56
|
-
UIProgressView => Proc.new{|klass, options|
|
56
|
+
'UIProgressView' => Proc.new{|klass, options|
|
57
57
|
style = options.delete(:style) || UIProgressViewStyleDefault
|
58
58
|
klass.alloc.initWithProgressViewStyle style
|
59
59
|
},
|
60
|
-
UISegmentedControl => Proc.new{|klass, options|
|
60
|
+
'UISegmentedControl' => Proc.new{|klass, options|
|
61
61
|
items = options.delete(:items) || []
|
62
62
|
klass.alloc.initWithItems items
|
63
63
|
},
|
64
|
-
UITableView => Proc.new{|klass, options|
|
64
|
+
'UITableView' => Proc.new{|klass, options|
|
65
65
|
style = options.delete(:style) || UITableViewStylePlain
|
66
66
|
klass.alloc.initWithFrame CGRectZero, style: style
|
67
67
|
},
|
68
|
-
UITableViewCell => Proc.new{|klass, options|
|
68
|
+
'UITableViewCell' => Proc.new{|klass, options|
|
69
69
|
style = options.delete(:style) || UITableViewCellStyleDefault
|
70
70
|
klass.alloc.initWithStyle style, reuseIdentifier: options.delete(:reuse_identifier)
|
71
71
|
},
|
72
|
-
UISearchBar => Proc.new{|klass, options|
|
72
|
+
'UISearchBar' => Proc.new{|klass, options|
|
73
73
|
klass = options[:search_field_background_image] ? UISearchBarCustom : UISearchBar
|
74
74
|
search_bar = klass.alloc.init
|
75
75
|
search_bar.autoresizingMask = UIViewAutoresizingFlexibleWidth
|
76
76
|
search_bar
|
77
77
|
},
|
78
|
-
GMSMapView => Proc.new{|klass, options|
|
78
|
+
'GMSMapView' => Proc.new{|klass, options|
|
79
79
|
camera = GMSCameraPosition.cameraWithLatitude(35.689466, longitude: 139.700196, zoom: 15)
|
80
80
|
map = GMSMapView.mapWithFrame(CGRectZero, camera: camera)
|
81
81
|
map
|
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.
|
4
|
+
version: 0.1.4
|
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-
|
11
|
+
date: 2013-08-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -165,6 +165,7 @@ files:
|
|
165
165
|
- README.md
|
166
166
|
- Rakefile
|
167
167
|
- app/app_delegate.rb
|
168
|
+
- doc/FAQ.md
|
168
169
|
- doc/SECTION.md
|
169
170
|
- doc/STYLE.md
|
170
171
|
- files/Gemfile
|