motion-loco 0.1.3 → 0.2.0
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 +8 -8
- data/README.md +55 -27
- data/lib/motion-loco.rb +5 -1
- data/lib/motion-loco/adapter.rb +168 -4
- data/lib/motion-loco/fixture_adapter.rb +9 -8
- data/lib/motion-loco/model.rb +172 -3
- data/lib/motion-loco/observable.rb +57 -17
- data/lib/motion-loco/record_array.rb +0 -6
- data/lib/motion-loco/resizable.rb +8 -8
- data/lib/motion-loco/rest_adapter.rb +27 -9
- data/lib/motion-loco/sqlite_adapter.rb +235 -0
- data/lib/motion-loco/table_view.rb +83 -79
- data/lib/motion-loco/version.rb +1 -1
- data/lib/motion-loco/views.rb +51 -47
- metadata +3 -3
- data/lib/motion-loco/savable.rb +0 -127
@@ -3,108 +3,112 @@ motion_require 'resizable'
|
|
3
3
|
|
4
4
|
module Loco
|
5
5
|
|
6
|
-
|
7
|
-
|
6
|
+
module UI
|
7
|
+
|
8
|
+
class TableViewCell < UITableViewCell
|
9
|
+
include Observable
|
8
10
|
|
9
|
-
|
11
|
+
property :content
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
-
|
13
|
+
def initWithStyle(style, reuseIdentifier:reuseIdentifier)
|
14
|
+
if super
|
15
|
+
view_setup # Needed because it's not Loco::Resizable
|
16
|
+
end
|
17
|
+
self
|
14
18
|
end
|
15
|
-
self
|
16
|
-
end
|
17
|
-
|
18
|
-
def select
|
19
|
-
Loco.debug("Override #{self.class}#select with the action to take when the row is selected")
|
20
|
-
end
|
21
19
|
|
22
|
-
|
23
|
-
|
24
|
-
view_controller = superview.nextResponder
|
25
|
-
else
|
26
|
-
view_controller = self.superview.nextResponder
|
20
|
+
def select
|
21
|
+
Loco.debug("Override #{self.class}#select with the action to take when the row is selected")
|
27
22
|
end
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
23
|
+
|
24
|
+
def view_controller(superview=nil)
|
25
|
+
if superview
|
26
|
+
view_controller = superview.nextResponder
|
27
|
+
else
|
28
|
+
view_controller = self.superview.nextResponder
|
29
|
+
end
|
30
|
+
if view_controller.is_a? UIViewController
|
31
|
+
view_controller
|
32
|
+
elsif view_controller.is_a? UIView
|
33
|
+
self.view_controller(view_controller)
|
34
|
+
end
|
32
35
|
end
|
33
|
-
|
34
|
-
alias_method :viewController, :view_controller
|
36
|
+
alias_method :viewController, :view_controller
|
35
37
|
|
36
|
-
|
37
|
-
|
38
|
-
|
38
|
+
def view_setup
|
39
|
+
viewSetup
|
40
|
+
end
|
39
41
|
|
40
|
-
|
41
|
-
|
42
|
+
def viewSetup
|
43
|
+
Loco.debug("Override #{self.class}#viewSetup or #{self.class}#view_setup to customize the view")
|
44
|
+
end
|
42
45
|
end
|
43
|
-
end
|
44
46
|
|
45
|
-
|
46
|
-
|
47
|
-
|
47
|
+
class TableView < UITableView
|
48
|
+
include Resizable
|
49
|
+
include Observable
|
48
50
|
|
49
|
-
|
50
|
-
|
51
|
-
def content=(value)
|
52
|
-
super
|
53
|
-
self.reloadData
|
54
|
-
end
|
51
|
+
property :content
|
55
52
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
def initWithFrame(frame)
|
61
|
-
super(frame)
|
62
|
-
self.dataSource = self.delegate = self
|
63
|
-
end
|
53
|
+
def content=(value)
|
54
|
+
super
|
55
|
+
self.reloadData
|
56
|
+
end
|
64
57
|
|
65
|
-
|
66
|
-
|
67
|
-
|
58
|
+
def cell_id
|
59
|
+
@cell_id ||= "CELL_#{self.object_id}"
|
60
|
+
end
|
68
61
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
62
|
+
def initWithFrame(frame)
|
63
|
+
super(frame)
|
64
|
+
self.dataSource = self.delegate = self
|
65
|
+
end
|
66
|
+
|
67
|
+
def item_view_class
|
68
|
+
self.class.get_item_view_class
|
69
|
+
end
|
70
|
+
|
71
|
+
# UITableViewDelegate implementation for returning the cell at a given indexPath.
|
72
|
+
# @return [Loco::TableViewCell]
|
73
|
+
def tableView(tableView, cellForRowAtIndexPath:indexPath)
|
74
|
+
cell = tableView.dequeueReusableCellWithIdentifier(cell_id)
|
75
|
+
unless cell
|
76
|
+
cell = self.item_view_class.alloc.initWithStyle(UITableViewCellStyleDefault, reuseIdentifier:cell_id)
|
77
|
+
end
|
78
|
+
cell.content = self.content[indexPath.row]
|
79
|
+
cell
|
75
80
|
end
|
76
|
-
cell.content = self.content[indexPath.row]
|
77
|
-
cell
|
78
|
-
end
|
79
81
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
82
|
+
# UITableViewDelegate implementation for selecting a cell at a given indexPath.
|
83
|
+
def tableView(tableView, didSelectRowAtIndexPath:indexPath)
|
84
|
+
cell = tableView.cellForRowAtIndexPath(indexPath)
|
85
|
+
cell.select
|
86
|
+
end
|
85
87
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
88
|
+
# UITableViewDelegate implementation for returning the number of rows in a section.
|
89
|
+
# @return [Integer]
|
90
|
+
def tableView(tableView, numberOfRowsInSection:section)
|
91
|
+
if self.content.is_a? Array
|
92
|
+
self.content.length
|
93
|
+
else
|
94
|
+
0
|
95
|
+
end
|
93
96
|
end
|
94
|
-
end
|
95
97
|
|
96
|
-
|
98
|
+
class << self
|
97
99
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
100
|
+
def item_view_class(view_class)
|
101
|
+
@item_view_class = view_class
|
102
|
+
end
|
103
|
+
alias_method :itemViewClass, :item_view_class
|
102
104
|
|
103
|
-
|
104
|
-
|
105
|
-
|
105
|
+
def get_item_view_class
|
106
|
+
@item_view_class ||= TableViewCell
|
107
|
+
end
|
106
108
|
|
109
|
+
end
|
107
110
|
end
|
111
|
+
|
108
112
|
end
|
109
113
|
|
110
114
|
end
|
data/lib/motion-loco/version.rb
CHANGED
data/lib/motion-loco/views.rb
CHANGED
@@ -3,64 +3,68 @@ motion_require 'resizable'
|
|
3
3
|
|
4
4
|
module Loco
|
5
5
|
|
6
|
-
|
7
|
-
include Resizable
|
8
|
-
include Observable
|
9
|
-
end
|
6
|
+
module UI
|
10
7
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
8
|
+
class Button < UIButton
|
9
|
+
include Resizable
|
10
|
+
include Observable
|
11
|
+
end
|
15
12
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
13
|
+
class DatePicker < UIDatePicker
|
14
|
+
include Resizable
|
15
|
+
include Observable
|
16
|
+
end
|
17
|
+
|
18
|
+
class ImageView < UIImageView
|
19
|
+
include Resizable
|
20
|
+
include Observable
|
21
|
+
end
|
20
22
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
23
|
+
class Label < UILabel
|
24
|
+
include Resizable
|
25
|
+
include Observable
|
26
|
+
end
|
25
27
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
28
|
+
class PickerView < UIPickerView
|
29
|
+
include Resizable
|
30
|
+
include Observable
|
31
|
+
end
|
30
32
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
33
|
+
class ProgressView < UIProgressView
|
34
|
+
include Resizable
|
35
|
+
include Observable
|
36
|
+
end
|
35
37
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
38
|
+
class ScrollView < UIScrollView
|
39
|
+
include Resizable
|
40
|
+
include Observable
|
41
|
+
end
|
40
42
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
43
|
+
class Slider < UISlider
|
44
|
+
include Resizable
|
45
|
+
include Observable
|
46
|
+
end
|
45
47
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
48
|
+
class TextView < UITextView
|
49
|
+
include Resizable
|
50
|
+
include Observable
|
51
|
+
end
|
50
52
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
53
|
+
class Toolbar < UIToolbar
|
54
|
+
include Resizable
|
55
|
+
include Observable
|
56
|
+
end
|
55
57
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
58
|
+
class View < UIView
|
59
|
+
include Resizable
|
60
|
+
include Observable
|
61
|
+
end
|
60
62
|
|
61
|
-
|
62
|
-
|
63
|
-
|
63
|
+
class WebView < UIWebView
|
64
|
+
include Resizable
|
65
|
+
include Observable
|
66
|
+
end
|
67
|
+
|
64
68
|
end
|
65
69
|
|
66
70
|
end
|
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.
|
4
|
+
version: 0.2.0
|
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-06-
|
11
|
+
date: 2013-06-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: awesome_print_motion
|
@@ -100,7 +100,7 @@ files:
|
|
100
100
|
- lib/motion-loco/record_array.rb
|
101
101
|
- lib/motion-loco/resizable.rb
|
102
102
|
- lib/motion-loco/rest_adapter.rb
|
103
|
-
- lib/motion-loco/
|
103
|
+
- lib/motion-loco/sqlite_adapter.rb
|
104
104
|
- lib/motion-loco/table_view.rb
|
105
105
|
- lib/motion-loco/version.rb
|
106
106
|
- lib/motion-loco/view_controller.rb
|
data/lib/motion-loco/savable.rb
DELETED
@@ -1,127 +0,0 @@
|
|
1
|
-
motion_require 'observable'
|
2
|
-
motion_require 'record_array'
|
3
|
-
|
4
|
-
module Loco
|
5
|
-
|
6
|
-
module Savable
|
7
|
-
|
8
|
-
def destroy(&block)
|
9
|
-
adapter = self.class.get_class_adapter
|
10
|
-
unless self.id.nil?
|
11
|
-
adapter.delete_record(self) do |record|
|
12
|
-
self.did_delete
|
13
|
-
block.call(record) if block.is_a? Proc
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def did_create
|
19
|
-
# Override to perform actions after creating the record
|
20
|
-
end
|
21
|
-
alias_method :didCreate, :did_create
|
22
|
-
|
23
|
-
def did_load
|
24
|
-
# Override to perform actions after loading data
|
25
|
-
end
|
26
|
-
alias_method :didLoad, :did_load
|
27
|
-
|
28
|
-
def did_update
|
29
|
-
# Override to perform actions after updating the record
|
30
|
-
end
|
31
|
-
alias_method :didUpdate, :did_update
|
32
|
-
|
33
|
-
def load(id, data)
|
34
|
-
data.merge!({ id: id })
|
35
|
-
self.set_properties(data)
|
36
|
-
self.did_load
|
37
|
-
self
|
38
|
-
end
|
39
|
-
|
40
|
-
def save(&block)
|
41
|
-
adapter = self.class.get_class_adapter
|
42
|
-
if self.id.nil?
|
43
|
-
adapter.create_record(self) do |record|
|
44
|
-
self.did_create
|
45
|
-
block.call(record) if block.is_a? Proc
|
46
|
-
end
|
47
|
-
else
|
48
|
-
adapter.update_record(self) do |record|
|
49
|
-
self.did_update
|
50
|
-
block.call(record) if block.is_a? Proc
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
def serialize(options={})
|
56
|
-
json = {}
|
57
|
-
if options[:root] == false
|
58
|
-
self.class.send(:get_class_properties).each do |key|
|
59
|
-
json[key.to_sym] = self.send(key)
|
60
|
-
end
|
61
|
-
else
|
62
|
-
if options[:root].nil? || options[:root] == true
|
63
|
-
root = self.class.to_s.underscore.to_sym
|
64
|
-
else
|
65
|
-
root = options[:root].to_sym
|
66
|
-
end
|
67
|
-
json[root] = {}
|
68
|
-
self.class.send(:get_class_properties).each do |key|
|
69
|
-
json[root][key.to_sym] = self.send(key)
|
70
|
-
end
|
71
|
-
end
|
72
|
-
json
|
73
|
-
end
|
74
|
-
|
75
|
-
module ClassMethods
|
76
|
-
|
77
|
-
def adapter(adapter_class, *args)
|
78
|
-
if adapter_class.is_a? String
|
79
|
-
@adapter = adapter_class.split('::').inject(Object) {|mod, class_name| mod.const_get(class_name) }.new(*args)
|
80
|
-
else
|
81
|
-
@adapter = adapter_class.new(*args)
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
def find(id=nil, &block)
|
86
|
-
adapter = self.get_class_adapter
|
87
|
-
if id.nil?
|
88
|
-
# Return all records
|
89
|
-
records = RecordArray.new
|
90
|
-
adapter.find_all(self, records) do |records|
|
91
|
-
block.call(records) if block.is_a? Proc
|
92
|
-
end
|
93
|
-
elsif id.is_a? Array
|
94
|
-
# Return records with given ids
|
95
|
-
records = RecordArray.new
|
96
|
-
adapter.find_many(self, records, id) do |records|
|
97
|
-
block.call(records) if block.is_a? Proc
|
98
|
-
end
|
99
|
-
elsif id.is_a? Hash
|
100
|
-
# Return records matching query
|
101
|
-
records = RecordArray.new
|
102
|
-
adapter.find_query(self, records, id) do |records|
|
103
|
-
block.call(records) if block.is_a? Proc
|
104
|
-
end
|
105
|
-
else
|
106
|
-
record = self.new(id: id)
|
107
|
-
adapter.find(record, id) do |record|
|
108
|
-
block.call(record) if block.is_a? Proc
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
112
|
-
alias_method :all, :find
|
113
|
-
alias_method :where, :find
|
114
|
-
|
115
|
-
def get_class_adapter
|
116
|
-
@adapter ||= Adapter.new
|
117
|
-
end
|
118
|
-
|
119
|
-
end
|
120
|
-
|
121
|
-
def self.included(base)
|
122
|
-
base.extend(ClassMethods)
|
123
|
-
end
|
124
|
-
|
125
|
-
end
|
126
|
-
|
127
|
-
end
|