motion-loco 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +6 -14
- data/README.md +1 -1
- data/lib/motion-loco/adapter.rb +1 -1
- data/lib/motion-loco/array_controller.rb +15 -0
- data/lib/motion-loco/associatable.rb +122 -0
- data/lib/motion-loco/controller.rb +9 -0
- data/lib/motion-loco/model.rb +2 -170
- data/lib/motion-loco/persistable.rb +96 -0
- data/lib/motion-loco/record_array.rb +48 -6
- data/lib/motion-loco/resizable.rb +48 -0
- data/lib/motion-loco/sqlite_adapter.rb +11 -0
- data/lib/motion-loco/version.rb +1 -1
- data/lib/motion-loco/views.rb +55 -0
- metadata +11 -8
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
metadata.gz: !binary |-
|
9
|
-
MzQ5YTcyNjAxODRlYTU5NGVlMmE1YWU2OTc5MTcxYzVjZmVhNzkxNTk2NmQ3
|
10
|
-
ZDQxMzQ3ZTJlNzczYjYxYWI2OTQ2NTlmY2JlZGUzNzI4ODNiNTI2YjMxNTll
|
11
|
-
ZGZhNDI5MGFhZGM2MzM3ZTYwNWU4Y2NlMDYyODlmYTk2NGQxYTg=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
MzlhNDI5ODUzODczZDZlNzgzMDIxOGNkYjkyMGU5YTZiY2M3YWM2NDg3YTNm
|
14
|
-
YWZiZjE2NzE3NWNiZTExNTZkYTAwOGYzY2NmZTlmYTY3MmUxOWVkZjU4NTVk
|
15
|
-
NTVlYzlkMWRkOTRmNWFhNWQxMTU4ZDZjMzQwY2JkODY0NmZhNTQ=
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c98e3096247b7eae3292a67a95d2b51a05683124
|
4
|
+
data.tar.gz: 808638ee1a7b95c5dd44b6758afaade0394526f2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e3c2603821b5329287281c3f9ea3aeaace0fe69195bddc2bf4122c42db9a37d7ea61aa0993d9eaa658c6ab38ba0201d40ab1b11b9848b6fe4190683faada48e7
|
7
|
+
data.tar.gz: 682dd22c9ec387eacb23d69b9129304e707a00b501d26bf02f9888d42f38325e237aa17090711f0a4470bea3004f02722b86957676a7bacf7adec3fa25afd7d7
|
data/README.md
CHANGED
@@ -10,7 +10,7 @@ computed properties, and observers. **And Ember-Data inspired [data](#locofixtur
|
|
10
10
|
|
11
11
|
#### SQLiteAdapter and Relationships!
|
12
12
|
|
13
|
-
I need to write up some better documentation, but be sure to check out the [Loco::SQLiteAdapter](locosqliteadapter) and the new `has_many` and `belongs_to` relationships in `Loco::Model`.
|
13
|
+
I need to write up some better documentation, but be sure to check out the [Loco::SQLiteAdapter](#locosqliteadapter) and the new `has_many` and `belongs_to` relationships in `Loco::Model`.
|
14
14
|
|
15
15
|
The relationship stuff needs some major code clean up, so don't copy my code if you're doing anything similar for loading/saving relationship data. :)
|
16
16
|
|
data/lib/motion-loco/adapter.rb
CHANGED
@@ -0,0 +1,122 @@
|
|
1
|
+
module Loco
|
2
|
+
|
3
|
+
module Associatable
|
4
|
+
|
5
|
+
def initialize(properties={})
|
6
|
+
super
|
7
|
+
initialize_relationships
|
8
|
+
self
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize_relationships
|
12
|
+
self.class.get_class_relationships.select{|relationship| relationship[:has_many] }.each do |relationship|
|
13
|
+
has_many_class = relationship[:has_many].to_s.classify.constantize
|
14
|
+
self.send("#{relationship[:has_many]}=", RecordArray.new(item_class: has_many_class, belongs_to: self))
|
15
|
+
self.send("#{relationship[:has_many].to_s.singularize}_ids=", [])
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
module ClassMethods
|
20
|
+
|
21
|
+
def belongs_to(model)
|
22
|
+
attr_accessor model
|
23
|
+
attr_accessor "#{model}_id"
|
24
|
+
|
25
|
+
define_method "#{model}" do |&block|
|
26
|
+
belongs_to_class = model.to_s.classify.constantize
|
27
|
+
record = instance_variable_get("@#{model}")
|
28
|
+
if record
|
29
|
+
block.call(record) if block.is_a? Proc
|
30
|
+
record
|
31
|
+
else
|
32
|
+
belongs_to_id = self.send("#{model}_id")
|
33
|
+
if belongs_to_id
|
34
|
+
belongs_to_class.find(belongs_to_id) do |record|
|
35
|
+
instance_variable_set("@#{model}", record)
|
36
|
+
block.call(record) if block.is_a? Proc
|
37
|
+
end
|
38
|
+
else
|
39
|
+
block.call(record) if block.is_a? Proc
|
40
|
+
record
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
define_method "#{model}=" do |record|
|
46
|
+
belongs_to_class = model.to_s.classify.constantize
|
47
|
+
raise TypeError, "Expecting a #{belongs_to_class} as defined by #belongs_to :#{model}" unless record.is_a? belongs_to_class
|
48
|
+
instance_variable_set("@#{model}", record)
|
49
|
+
self.send("#{model}_id=", (record.nil? ? nil : record.id))
|
50
|
+
record
|
51
|
+
end
|
52
|
+
|
53
|
+
relationships = get_class_relationships
|
54
|
+
relationships << { belongs_to: model }
|
55
|
+
end
|
56
|
+
|
57
|
+
def has_many(model)
|
58
|
+
attr_accessor model
|
59
|
+
attr_accessor "#{model.to_s.singularize}_ids"
|
60
|
+
|
61
|
+
define_method "#{model}" do |&block|
|
62
|
+
has_many_class = model.to_s.singularize.classify.constantize
|
63
|
+
|
64
|
+
record_array = instance_variable_get("@#{model}")
|
65
|
+
if record_array.is_loaded
|
66
|
+
block.call(record_array) if block.is_a? Proc
|
67
|
+
record_array
|
68
|
+
else
|
69
|
+
has_many_ids = instance_variable_get("@#{model.to_s.singularize}_ids")
|
70
|
+
if has_many_ids
|
71
|
+
array = has_many_class.find(has_many_ids) do |records|
|
72
|
+
record_array.load(records)
|
73
|
+
instance_variable_set("@#{model}", record_array)
|
74
|
+
block.call(record_array) if block.is_a? Proc
|
75
|
+
end
|
76
|
+
record_array.load(array)
|
77
|
+
else
|
78
|
+
query = {}
|
79
|
+
query["#{self.class.to_s.underscore.singularize}_id"] = self.id
|
80
|
+
array = has_many_class.find(query) do |records|
|
81
|
+
record_array.load(records)
|
82
|
+
instance_variable_set("@#{model}", record_array)
|
83
|
+
block.call(record_array) if block.is_a? Proc
|
84
|
+
end
|
85
|
+
record_array.load(array)
|
86
|
+
end
|
87
|
+
instance_variable_set("@#{model}", record_array)
|
88
|
+
record_array
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
define_method "#{model}=" do |records|
|
93
|
+
has_many_class = model.to_s.singularize.classify.constantize
|
94
|
+
|
95
|
+
if (records.is_a?(RecordArray) || records.is_a?(Array)) && (records.length == 0 || (records.length > 0 && records.first.class == has_many_class))
|
96
|
+
unless records.is_a?(RecordArray)
|
97
|
+
record_array = RecordArray.new(item_class: has_many_class, belongs_to: self)
|
98
|
+
record_array.addObjectsFromArray(records)
|
99
|
+
records = record_array
|
100
|
+
end
|
101
|
+
else
|
102
|
+
raise TypeError, "Expecting a Loco::RecordArray of #{has_many_class} objects as defined by #has_many :#{model}"
|
103
|
+
end
|
104
|
+
|
105
|
+
instance_variable_set("@#{model}", records)
|
106
|
+
instance_variable_set("@#{model.to_s.singularize}_ids", records.map(&:id))
|
107
|
+
records
|
108
|
+
end
|
109
|
+
|
110
|
+
relationships = get_class_relationships
|
111
|
+
relationships << { has_many: model }
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
115
|
+
|
116
|
+
def self.included(base)
|
117
|
+
base.extend(ClassMethods)
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
@@ -4,6 +4,15 @@ module Loco
|
|
4
4
|
|
5
5
|
class Controller
|
6
6
|
include Observable
|
7
|
+
property :content
|
8
|
+
|
9
|
+
def method_missing(method, *args, &block)
|
10
|
+
if self.content.respond_to? method
|
11
|
+
self.content.send(method, *args)
|
12
|
+
else
|
13
|
+
super
|
14
|
+
end
|
15
|
+
end
|
7
16
|
|
8
17
|
def self.instance
|
9
18
|
@instance ||= new
|
data/lib/motion-loco/model.rb
CHANGED
@@ -4,178 +4,10 @@ motion_require 'record_array'
|
|
4
4
|
module Loco
|
5
5
|
|
6
6
|
class Model
|
7
|
+
include Associatable
|
7
8
|
include Observable
|
9
|
+
include Persistable
|
8
10
|
property :id, :integer
|
9
|
-
|
10
|
-
def destroy(&block)
|
11
|
-
adapter = self.class.get_class_adapter
|
12
|
-
unless self.new?
|
13
|
-
adapter.delete_record(self) do |record|
|
14
|
-
block.call(record) if block.is_a? Proc
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def load(id, data)
|
20
|
-
data.merge!({ id: id })
|
21
|
-
self.set_properties(data)
|
22
|
-
self
|
23
|
-
end
|
24
|
-
|
25
|
-
def new?
|
26
|
-
self.id.nil?
|
27
|
-
end
|
28
|
-
|
29
|
-
def save(&block)
|
30
|
-
adapter = self.class.get_class_adapter
|
31
|
-
if self.new?
|
32
|
-
adapter.create_record(self) do |record|
|
33
|
-
block.call(record) if block.is_a? Proc
|
34
|
-
end
|
35
|
-
else
|
36
|
-
adapter.update_record(self) do |record|
|
37
|
-
block.call(record) if block.is_a? Proc
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def serialize(options={})
|
43
|
-
self.class.get_class_adapter.serialize(self, options)
|
44
|
-
end
|
45
|
-
|
46
|
-
class << self
|
47
|
-
|
48
|
-
def adapter(adapter_class, *args)
|
49
|
-
if adapter_class.is_a? String
|
50
|
-
@adapter = adapter_class.constantize.new(*args)
|
51
|
-
else
|
52
|
-
@adapter = adapter_class.new(*args)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
def belongs_to(model)
|
57
|
-
attr_accessor model
|
58
|
-
attr_accessor "#{model}_id"
|
59
|
-
|
60
|
-
belongs_to_class_name = model.to_s.classify
|
61
|
-
|
62
|
-
define_method "#{model}" do |&block|
|
63
|
-
record = instance_variable_get("@#{model}")
|
64
|
-
if record
|
65
|
-
block.call(record) if block.is_a? Proc
|
66
|
-
record
|
67
|
-
else
|
68
|
-
belongs_to_id = self.send("#{model}_id")
|
69
|
-
if belongs_to_id
|
70
|
-
belongs_to_class_name.constantize.find(belongs_to_id) do |record|
|
71
|
-
instance_variable_set("@#{model}", record)
|
72
|
-
block.call(record) if block.is_a? Proc
|
73
|
-
end
|
74
|
-
else
|
75
|
-
block.call(record) if block.is_a? Proc
|
76
|
-
record
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
define_method "#{model}=" do |record|
|
82
|
-
raise TypeError, "Expecting a #{belongs_to_class_name} as defined by #belongs_to :#{model}" unless record.is_a? belongs_to_class_name.constantize
|
83
|
-
self.send("#{model}_id=", (record.nil? ? nil : record.id))
|
84
|
-
instance_variable_set("@#{model}", record)
|
85
|
-
record
|
86
|
-
end
|
87
|
-
|
88
|
-
relationships = get_class_relationships
|
89
|
-
relationships << { belongs_to: model }
|
90
|
-
end
|
91
|
-
|
92
|
-
def has_many(model)
|
93
|
-
attr_accessor model
|
94
|
-
attr_accessor "#{model.to_s.singularize}_ids"
|
95
|
-
|
96
|
-
has_many_class_name = model.to_s.singularize.classify
|
97
|
-
|
98
|
-
define_method "#{model}" do |&block|
|
99
|
-
has_many_class = has_many_class_name.constantize
|
100
|
-
records = instance_variable_get("@#{model}")
|
101
|
-
if records
|
102
|
-
block.call(records) if block.is_a? Proc
|
103
|
-
records
|
104
|
-
else
|
105
|
-
has_many_ids = self.send("#{model.to_s.singularize}_ids")
|
106
|
-
if has_many_ids
|
107
|
-
has_many_class.find(has_many_ids) do |records|
|
108
|
-
block.call(records) if block.is_a? Proc
|
109
|
-
end
|
110
|
-
else
|
111
|
-
query = {}
|
112
|
-
query["#{self.class.to_s.underscore.singularize}_id"] = self.id
|
113
|
-
has_many_class.find(query) do |records|
|
114
|
-
block.call(records) if block.is_a? Proc
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
define_method "#{model}=" do |records|
|
121
|
-
has_many_class = has_many_class_name.constantize
|
122
|
-
if (records.is_a?(RecordArray) || records.is_a?(Array)) && (records.length == 0 || (records.length > 0 && records.first.class == has_many_class))
|
123
|
-
unless records.is_a?(RecordArray)
|
124
|
-
record_array = RecordArray.new
|
125
|
-
record_array.addObjectsFromArray(records)
|
126
|
-
records = record_array
|
127
|
-
end
|
128
|
-
else
|
129
|
-
raise TypeError, "Expecting a Loco::RecordArray of #{has_many_class_name} objects as defined by #has_many :#{model}"
|
130
|
-
end
|
131
|
-
|
132
|
-
self.send("#{model.to_s.singularize}_ids=", records.map(&:id))
|
133
|
-
instance_variable_set("@#{model}", records)
|
134
|
-
end
|
135
|
-
|
136
|
-
relationships = get_class_relationships
|
137
|
-
relationships << { has_many: model }
|
138
|
-
end
|
139
|
-
|
140
|
-
def find(id=nil, &block)
|
141
|
-
adapter = self.get_class_adapter
|
142
|
-
if id.nil?
|
143
|
-
# Return all records
|
144
|
-
records = RecordArray.new
|
145
|
-
adapter.find_all(self, records) do |records|
|
146
|
-
block.call(records) if block.is_a? Proc
|
147
|
-
end
|
148
|
-
elsif id.is_a? Array
|
149
|
-
# Return records with given ids
|
150
|
-
records = RecordArray.new
|
151
|
-
id.each do |i|
|
152
|
-
records << self.new(id: i)
|
153
|
-
end
|
154
|
-
adapter.find_many(self, records, id) do |records|
|
155
|
-
block.call(records) if block.is_a? Proc
|
156
|
-
end
|
157
|
-
elsif id.is_a? Hash
|
158
|
-
# Return records matching query
|
159
|
-
records = RecordArray.new
|
160
|
-
adapter.find_query(self, records, id) do |records|
|
161
|
-
block.call(records) if block.is_a? Proc
|
162
|
-
end
|
163
|
-
else
|
164
|
-
record = self.new(id: id)
|
165
|
-
adapter.find(record, id) do |record|
|
166
|
-
block.call(record) if block.is_a? Proc
|
167
|
-
end
|
168
|
-
end
|
169
|
-
end
|
170
|
-
alias_method :all, :find
|
171
|
-
alias_method :where, :find
|
172
|
-
|
173
|
-
def get_class_adapter
|
174
|
-
@adapter ||= Adapter.new
|
175
|
-
end
|
176
|
-
|
177
|
-
end
|
178
|
-
|
179
11
|
end
|
180
12
|
|
181
13
|
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
module Loco
|
2
|
+
|
3
|
+
module Persistable
|
4
|
+
|
5
|
+
def destroy(&block)
|
6
|
+
adapter = self.class.get_class_adapter
|
7
|
+
unless self.new?
|
8
|
+
adapter.delete_record(self) do |record|
|
9
|
+
block.call(record) if block.is_a? Proc
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def load(id, data)
|
15
|
+
data.merge!({ id: id })
|
16
|
+
self.set_properties(data)
|
17
|
+
self
|
18
|
+
end
|
19
|
+
|
20
|
+
def new?
|
21
|
+
self.id.nil?
|
22
|
+
end
|
23
|
+
|
24
|
+
def save(&block)
|
25
|
+
adapter = self.class.get_class_adapter
|
26
|
+
if self.new?
|
27
|
+
adapter.create_record(self) do |record|
|
28
|
+
block.call(record) if block.is_a? Proc
|
29
|
+
end
|
30
|
+
else
|
31
|
+
adapter.update_record(self) do |record|
|
32
|
+
block.call(record) if block.is_a? Proc
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def serialize(options={})
|
38
|
+
self.class.get_class_adapter.serialize(self, options)
|
39
|
+
end
|
40
|
+
|
41
|
+
module ClassMethods
|
42
|
+
|
43
|
+
def adapter(adapter_class, *args)
|
44
|
+
if adapter_class.is_a? String
|
45
|
+
@adapter = adapter_class.constantize.new(*args)
|
46
|
+
else
|
47
|
+
@adapter = adapter_class.new(*args)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def find(id=nil, &block)
|
52
|
+
adapter = self.get_class_adapter
|
53
|
+
if id.nil?
|
54
|
+
# Return all records
|
55
|
+
records = RecordArray.new(item_class: self.class)
|
56
|
+
adapter.find_all(self, records) do |records|
|
57
|
+
block.call(records) if block.is_a? Proc
|
58
|
+
end
|
59
|
+
elsif id.is_a? Array
|
60
|
+
# Return records with given ids
|
61
|
+
records = RecordArray.new(item_class: self.class)
|
62
|
+
id.each do |i|
|
63
|
+
records << self.new(id: i)
|
64
|
+
end
|
65
|
+
adapter.find_many(self, records, id) do |records|
|
66
|
+
block.call(records) if block.is_a? Proc
|
67
|
+
end
|
68
|
+
elsif id.is_a? Hash
|
69
|
+
# Return records matching query
|
70
|
+
records = RecordArray.new(item_class: self.class)
|
71
|
+
adapter.find_query(self, records, id) do |records|
|
72
|
+
block.call(records) if block.is_a? Proc
|
73
|
+
end
|
74
|
+
else
|
75
|
+
record = self.new(id: id)
|
76
|
+
adapter.find(record, id) do |record|
|
77
|
+
block.call(record) if block.is_a? Proc
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
alias_method :all, :find
|
82
|
+
alias_method :where, :find
|
83
|
+
|
84
|
+
def get_class_adapter
|
85
|
+
@adapter ||= Adapter.new
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
def self.included(base)
|
91
|
+
base.extend(ClassMethods)
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
@@ -2,22 +2,64 @@ motion_require 'observable'
|
|
2
2
|
|
3
3
|
module Loco
|
4
4
|
|
5
|
-
class RecordArray
|
5
|
+
class RecordArray
|
6
6
|
include Observable
|
7
|
+
property :belongs_to
|
8
|
+
property :content
|
9
|
+
property :is_loaded, :string
|
10
|
+
property :item_class
|
11
|
+
property :length, :integer
|
7
12
|
|
8
|
-
def
|
9
|
-
self.
|
10
|
-
|
11
|
-
|
13
|
+
def <<(record)
|
14
|
+
self.addObjectsFromArray([record])
|
15
|
+
end
|
16
|
+
|
17
|
+
def addObjectsFromArray(objects)
|
18
|
+
objects.each do |object|
|
19
|
+
object.send("#{self.belongs_to.class.to_s.underscore}=", self.belongs_to) if self.belongs_to
|
12
20
|
end
|
21
|
+
self.content.addObjectsFromArray(objects)
|
22
|
+
update_properties
|
13
23
|
self
|
14
24
|
end
|
15
25
|
|
16
26
|
def initialize(properties={})
|
17
|
-
|
27
|
+
super
|
28
|
+
self.content = Array.new
|
29
|
+
self.length = 0
|
30
|
+
self
|
31
|
+
end
|
32
|
+
|
33
|
+
def load(type, data=nil)
|
34
|
+
if type.is_a? RecordArray
|
35
|
+
self.content = type.content
|
36
|
+
else
|
37
|
+
self.item_class = type
|
38
|
+
self.content.removeAllObjects
|
39
|
+
data.each do |item_data|
|
40
|
+
self.content.addObject(type.new(item_data))
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
update_properties
|
45
|
+
self.is_loaded = true
|
46
|
+
|
18
47
|
self
|
19
48
|
end
|
20
49
|
|
50
|
+
def method_missing(method, *args, &block)
|
51
|
+
self.content.send(method, *args, &block)
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def update_properties
|
57
|
+
self.length = self.content.length
|
58
|
+
if self.belongs_to
|
59
|
+
self.belongs_to.send("#{self.item_class.to_s.underscore.singularize}_ids=", self.content.map(&:id))
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
21
63
|
end
|
22
64
|
|
23
65
|
end
|
@@ -9,6 +9,17 @@ module Loco
|
|
9
9
|
# relative to the superview's bottom edge.
|
10
10
|
# @return [Integer]
|
11
11
|
attr_accessor :bottom
|
12
|
+
def bottom
|
13
|
+
if @bottom.is_a?(String)
|
14
|
+
if self.parentView
|
15
|
+
self.parentView.bounds.size.height * (@bottom.gsub('%', '').to_f / 100.0)
|
16
|
+
else
|
17
|
+
0
|
18
|
+
end
|
19
|
+
else
|
20
|
+
@bottom
|
21
|
+
end
|
22
|
+
end
|
12
23
|
def bottom=(bottom)
|
13
24
|
super
|
14
25
|
refresh_layout
|
@@ -17,6 +28,13 @@ module Loco
|
|
17
28
|
# The height of the view.
|
18
29
|
# @return [Integer]
|
19
30
|
attr_accessor :height
|
31
|
+
def height
|
32
|
+
if @height.is_a?(String)
|
33
|
+
self.parentView ? self.parentView.bounds.size.height * (@height.gsub('%', '').to_f / 100.0) : 0
|
34
|
+
else
|
35
|
+
@height
|
36
|
+
end
|
37
|
+
end
|
20
38
|
def height=(height)
|
21
39
|
super
|
22
40
|
refresh_layout
|
@@ -26,6 +44,13 @@ module Loco
|
|
26
44
|
# relative to the superview's left edge.
|
27
45
|
# @return [Integer]
|
28
46
|
attr_accessor :left
|
47
|
+
def left
|
48
|
+
if @left.is_a?(String)
|
49
|
+
self.parentView ? self.parentView.bounds.size.width * (@left.gsub('%', '').to_f / 100.0) : 0
|
50
|
+
else
|
51
|
+
@left
|
52
|
+
end
|
53
|
+
end
|
29
54
|
def left=(left)
|
30
55
|
super
|
31
56
|
refresh_layout
|
@@ -35,6 +60,13 @@ module Loco
|
|
35
60
|
# relative to the superview's right edge.
|
36
61
|
# @return [Integer]
|
37
62
|
attr_accessor :right
|
63
|
+
def right
|
64
|
+
if @right.is_a?(String)
|
65
|
+
self.parentView ? self.parentView.bounds.size.width * (@right.gsub('%', '').to_f / 100.0) : 0
|
66
|
+
else
|
67
|
+
@right
|
68
|
+
end
|
69
|
+
end
|
38
70
|
def right=(right)
|
39
71
|
super
|
40
72
|
refresh_layout
|
@@ -44,6 +76,13 @@ module Loco
|
|
44
76
|
# relative to the superview's top edge.
|
45
77
|
# @return [Integer]
|
46
78
|
attr_accessor :top
|
79
|
+
def top
|
80
|
+
if @top.is_a?(String)
|
81
|
+
self.parentView ? self.parentView.bounds.size.height * (@top.gsub('%', '').to_f / 100.0) : 0
|
82
|
+
else
|
83
|
+
@top
|
84
|
+
end
|
85
|
+
end
|
47
86
|
def top=(top)
|
48
87
|
super
|
49
88
|
refresh_layout
|
@@ -52,6 +91,13 @@ module Loco
|
|
52
91
|
# The width of the view.
|
53
92
|
# @return [Integer]
|
54
93
|
attr_accessor :width
|
94
|
+
def width
|
95
|
+
if @width.is_a?(String)
|
96
|
+
self.parentView ? self.parentView.bounds.size.width * (@width.gsub('%', '').to_f / 100.0) : 0
|
97
|
+
else
|
98
|
+
@width
|
99
|
+
end
|
100
|
+
end
|
55
101
|
def width=(width)
|
56
102
|
super
|
57
103
|
refresh_layout
|
@@ -235,6 +281,7 @@ module Loco
|
|
235
281
|
view.refresh_layout(self) if view.is_a? Resizable
|
236
282
|
end
|
237
283
|
end
|
284
|
+
alias_method :refreshLayout, :refresh_layout
|
238
285
|
|
239
286
|
def view_setup
|
240
287
|
viewSetup
|
@@ -249,6 +296,7 @@ module Loco
|
|
249
296
|
self.parentView = superview
|
250
297
|
refresh_layout(superview)
|
251
298
|
end
|
299
|
+
|
252
300
|
end
|
253
301
|
|
254
302
|
end
|
@@ -14,6 +14,7 @@ module Loco
|
|
14
14
|
end
|
15
15
|
save_data_for_type(type)
|
16
16
|
load(type, record, data)
|
17
|
+
save_has_many(record)
|
17
18
|
block.call(record) if block.is_a? Proc
|
18
19
|
record
|
19
20
|
end
|
@@ -73,6 +74,7 @@ module Loco
|
|
73
74
|
end
|
74
75
|
save_data_for_type(type)
|
75
76
|
load(type, record, data)
|
77
|
+
save_has_many(record)
|
76
78
|
block.call(record) if block.is_a? Proc
|
77
79
|
record
|
78
80
|
else
|
@@ -186,6 +188,15 @@ module Loco
|
|
186
188
|
raise "Error when saving #{type}: #{error[0].description}" unless context(type).save(error)
|
187
189
|
end
|
188
190
|
|
191
|
+
def save_has_many(record)
|
192
|
+
record.class.get_class_relationships.select{|relationship| relationship[:has_many] }.each do |relationship|
|
193
|
+
related = record.send("#{relationship[:has_many]}")
|
194
|
+
related.each do |r|
|
195
|
+
r.save
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
189
200
|
def transform_data(type, data)
|
190
201
|
if data.is_a? Array
|
191
202
|
super(type, data.map{|object|
|
data/lib/motion-loco/version.rb
CHANGED
data/lib/motion-loco/views.rb
CHANGED
@@ -23,6 +23,51 @@ module Loco
|
|
23
23
|
class Label < UILabel
|
24
24
|
include Resizable
|
25
25
|
include Observable
|
26
|
+
|
27
|
+
def text_align
|
28
|
+
case self.textAlignment
|
29
|
+
when NSTextAlignmentLeft
|
30
|
+
'left'
|
31
|
+
when NSTextAlignmentCenter
|
32
|
+
'center'
|
33
|
+
when NSTextAlignmentRight
|
34
|
+
'right'
|
35
|
+
when NSTextAlignmentJustified
|
36
|
+
'justified'
|
37
|
+
when NSTextAlignmentNatural
|
38
|
+
'natural'
|
39
|
+
end
|
40
|
+
end
|
41
|
+
alias_method :textAlign, :text_align
|
42
|
+
|
43
|
+
def text_align=(alignment)
|
44
|
+
case alignment
|
45
|
+
when 'left'
|
46
|
+
self.textAlignment = NSTextAlignmentLeft
|
47
|
+
when 'center'
|
48
|
+
self.textAlignment = NSTextAlignmentCenter
|
49
|
+
when 'right'
|
50
|
+
self.textAlignment = NSTextAlignmentRight
|
51
|
+
when 'justified'
|
52
|
+
self.textAlignment = NSTextAlignmentJustified
|
53
|
+
when 'natural'
|
54
|
+
self.textAlignment = NSTextAlignmentNatural
|
55
|
+
end
|
56
|
+
end
|
57
|
+
alias_method :textAlign=, :text_align=
|
58
|
+
|
59
|
+
def textAlignment=(alignment)
|
60
|
+
if alignment.is_a? String
|
61
|
+
self.text_align = alignment
|
62
|
+
else
|
63
|
+
super
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
class PageControl < UIPageControl
|
69
|
+
include Resizable
|
70
|
+
include Observable
|
26
71
|
end
|
27
72
|
|
28
73
|
class PickerView < UIPickerView
|
@@ -58,6 +103,16 @@ module Loco
|
|
58
103
|
class View < UIView
|
59
104
|
include Resizable
|
60
105
|
include Observable
|
106
|
+
|
107
|
+
def border_radius
|
108
|
+
self.layer.cornerRadius
|
109
|
+
end
|
110
|
+
alias_method :borderRadius, :border_radius
|
111
|
+
|
112
|
+
def border_radius=(radius)
|
113
|
+
self.layer.cornerRadius = radius
|
114
|
+
end
|
115
|
+
alias_method :borderRadius=, :border_radius=
|
61
116
|
end
|
62
117
|
|
63
118
|
class WebView < UIWebView
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: motion-loco
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Pattison
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-09-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: awesome_print_motion
|
@@ -70,17 +70,17 @@ dependencies:
|
|
70
70
|
name: rake
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - '>='
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - '>='
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
-
description:
|
83
|
+
description: "Motion-Loco is a library for RubyMotion that includes Ember.js inspired\n
|
84
84
|
\ bindings, computed properties, and observers.\n Also
|
85
85
|
included is a set of views that are easier to position and size.\n "
|
86
86
|
email:
|
@@ -91,11 +91,14 @@ extra_rdoc_files: []
|
|
91
91
|
files:
|
92
92
|
- README.md
|
93
93
|
- lib/motion-loco/adapter.rb
|
94
|
+
- lib/motion-loco/array_controller.rb
|
95
|
+
- lib/motion-loco/associatable.rb
|
94
96
|
- lib/motion-loco/controller.rb
|
95
97
|
- lib/motion-loco/convenience_methods.rb
|
96
98
|
- lib/motion-loco/fixture_adapter.rb
|
97
99
|
- lib/motion-loco/model.rb
|
98
100
|
- lib/motion-loco/observable.rb
|
101
|
+
- lib/motion-loco/persistable.rb
|
99
102
|
- lib/motion-loco/proc.rb
|
100
103
|
- lib/motion-loco/record_array.rb
|
101
104
|
- lib/motion-loco/resizable.rb
|
@@ -116,17 +119,17 @@ require_paths:
|
|
116
119
|
- lib
|
117
120
|
required_ruby_version: !ruby/object:Gem::Requirement
|
118
121
|
requirements:
|
119
|
-
- -
|
122
|
+
- - '>='
|
120
123
|
- !ruby/object:Gem::Version
|
121
124
|
version: '0'
|
122
125
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
126
|
requirements:
|
124
|
-
- -
|
127
|
+
- - '>='
|
125
128
|
- !ruby/object:Gem::Version
|
126
129
|
version: '0'
|
127
130
|
requirements: []
|
128
131
|
rubyforge_project:
|
129
|
-
rubygems_version: 2.
|
132
|
+
rubygems_version: 2.1.4
|
130
133
|
signing_key:
|
131
134
|
specification_version: 4
|
132
135
|
summary: Library for RubyMotion that includes Ember.js inspired bindings, computed
|