motion-util 0.1.3 → 0.1.4
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.
- data/README.md +36 -3
- data/lib/motion-util/command/generator.rb +11 -1
- data/lib/motion-util/version.rb +1 -1
- data/template/class/navigation_controller.rb +31 -0
- data/template/class/tab_bar_controller.rb +32 -0
- data/template/class/table_view_controller.rb +90 -0
- data/template/class/view.rb +34 -0
- data/template/class/view_controller.rb +38 -0
- data/template/spec/spec.rb +1 -1
- data/test/test_generator.rb +20 -2
- metadata +2 -2
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Motion
|
1
|
+
Motion Util
|
2
2
|
===
|
3
3
|
|
4
4
|
Convenient command set for Ruby Motion.
|
@@ -26,13 +26,46 @@ Generate class file.
|
|
26
26
|
motion-util g model Foo
|
27
27
|
motion-util generation model Foo
|
28
28
|
|
29
|
-
Generate Objective-C header file for Interface Builder.
|
30
|
-
|
29
|
+
Generate Objective-C header file for Interface Builder.
|
30
|
+
|
31
31
|
motion-util ib_header
|
32
32
|
|
33
33
|
You can also describe like this:
|
34
34
|
motion-util ibh
|
35
35
|
|
36
|
+
|
37
|
+
Your ruby motion class:
|
38
|
+
<pre>
|
39
|
+
# app_delegate.rb
|
40
|
+
class AppDelegate
|
41
|
+
|
42
|
+
attr_accessor :window # @type_info UIWindow
|
43
|
+
attr_accessor :controller # @type_info UIViewController
|
44
|
+
|
45
|
+
def application(application, didFinishLaunchingWithOptions:launchOptions)
|
46
|
+
@window.rootViewController = @controller
|
47
|
+
@window.makeKeyAndVisible
|
48
|
+
true
|
49
|
+
end
|
50
|
+
end
|
51
|
+
</pre>
|
52
|
+
|
53
|
+
@type_info is a marker to describe a class by Objective-C.
|
54
|
+
If it's not specified it will be id type.
|
55
|
+
|
56
|
+
After execute 'motion-util ibh', AppDelegate.h was generated in tmp/header directory like this.
|
57
|
+
|
58
|
+
<pre>
|
59
|
+
// AppDelegate.h
|
60
|
+
@interface AppDelegate : NSObject
|
61
|
+
@property (strong, nonatomic) IBOutlet UIWindow *window;
|
62
|
+
@property (strong, nonatomic) IBOutlet UIViewController *controller;
|
63
|
+
@end
|
64
|
+
</pre>
|
65
|
+
|
66
|
+
|
67
|
+
|
68
|
+
|
36
69
|
Licence
|
37
70
|
===
|
38
71
|
BSD Licence
|
@@ -24,7 +24,7 @@ module Motion
|
|
24
24
|
|
25
25
|
def destination_path
|
26
26
|
case file_type
|
27
|
-
when /controller/
|
27
|
+
when /controller/, /view/
|
28
28
|
"#{destination_dir}/#{class_file_name}_#{file_type}.rb"
|
29
29
|
else
|
30
30
|
"#{destination_dir}/#{class_file_name}.rb"
|
@@ -45,6 +45,7 @@ module Motion
|
|
45
45
|
def spec_context
|
46
46
|
c = File.read File.join(@template_dir, "spec", "spec.rb")
|
47
47
|
c.gsub! /#\{class_name\}/, class_name
|
48
|
+
c.gsub! /#\{camelized_file_type\}/, camelized_file_type
|
48
49
|
c
|
49
50
|
end
|
50
51
|
|
@@ -102,6 +103,15 @@ module Motion
|
|
102
103
|
@class_name
|
103
104
|
end
|
104
105
|
|
106
|
+
def camelized_file_type
|
107
|
+
case file_type
|
108
|
+
when "general", "model"
|
109
|
+
""
|
110
|
+
else
|
111
|
+
@file_type.split('_').map{|e| e.capitalize}.join('')
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
105
115
|
def class_file_name
|
106
116
|
class_name.downcase
|
107
117
|
end
|
data/lib/motion-util/version.rb
CHANGED
@@ -1,3 +1,34 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
class #{class_name}NavigationController < UINavigationController
|
3
|
+
|
4
|
+
=begin
|
5
|
+
def viewDidLoad
|
6
|
+
super
|
7
|
+
end
|
8
|
+
=end
|
9
|
+
|
10
|
+
=begin
|
11
|
+
def viewDidUnload
|
12
|
+
super
|
13
|
+
end
|
14
|
+
=end
|
15
|
+
|
16
|
+
=begin
|
17
|
+
def viewWillAppear animated
|
18
|
+
super
|
19
|
+
end
|
20
|
+
=end
|
21
|
+
|
22
|
+
=begin
|
23
|
+
def viewWillDisappear animated
|
24
|
+
super
|
25
|
+
end
|
26
|
+
=end
|
27
|
+
|
28
|
+
=begin
|
29
|
+
def shouldAutorotateToInterfaceOrientation interfaceOrientation
|
30
|
+
interfaceOrientation == UIInterfaceOrientationPortrait
|
31
|
+
end
|
32
|
+
=end
|
33
|
+
|
3
34
|
end
|
@@ -1,3 +1,35 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
class #{class_name}TabBarController < UITabBarController
|
3
|
+
|
4
|
+
=begin
|
5
|
+
def viewDidLoad
|
6
|
+
super
|
7
|
+
end
|
8
|
+
=end
|
9
|
+
|
10
|
+
=begin
|
11
|
+
def viewDidUnload
|
12
|
+
super
|
13
|
+
end
|
14
|
+
=end
|
15
|
+
|
16
|
+
=begin
|
17
|
+
def viewWillAppear animated
|
18
|
+
super
|
19
|
+
end
|
20
|
+
=end
|
21
|
+
|
22
|
+
=begin
|
23
|
+
def viewWillDisappear animated
|
24
|
+
super
|
25
|
+
end
|
26
|
+
=end
|
27
|
+
|
28
|
+
=begin
|
29
|
+
def shouldAutorotateToInterfaceOrientation interfaceOrientation
|
30
|
+
interfaceOrientation == UIInterfaceOrientationPortrait
|
31
|
+
end
|
32
|
+
=end
|
33
|
+
|
34
|
+
|
3
35
|
end
|
@@ -1,3 +1,93 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
class #{class_name}TableViewController < UITableViewController
|
3
|
+
|
4
|
+
=begin
|
5
|
+
def initWithStyle style
|
6
|
+
super
|
7
|
+
self
|
8
|
+
end
|
9
|
+
=end
|
10
|
+
|
11
|
+
=begin
|
12
|
+
def viewDidLoad
|
13
|
+
super
|
14
|
+
# navigationItem.rightBarButtonItem = editButtonItem;
|
15
|
+
end
|
16
|
+
=end
|
17
|
+
|
18
|
+
=begin
|
19
|
+
def viewDidUnload
|
20
|
+
super
|
21
|
+
end
|
22
|
+
=end
|
23
|
+
|
24
|
+
=begin
|
25
|
+
def viewWillAppear animated
|
26
|
+
super
|
27
|
+
end
|
28
|
+
=end
|
29
|
+
|
30
|
+
=begin
|
31
|
+
def viewWillDisappear animated
|
32
|
+
super
|
33
|
+
end
|
34
|
+
=end
|
35
|
+
|
36
|
+
=begin
|
37
|
+
def shouldAutorotateToInterfaceOrientation interfaceOrientation
|
38
|
+
interfaceOrientation == UIInterfaceOrientationPortrait
|
39
|
+
end
|
40
|
+
=end
|
41
|
+
|
42
|
+
|
43
|
+
=begin
|
44
|
+
def numberOfSectionsInTableView tableView
|
45
|
+
1
|
46
|
+
end
|
47
|
+
=end
|
48
|
+
|
49
|
+
=begin
|
50
|
+
def tableView tableView, numberOfRowsInSection:section
|
51
|
+
1
|
52
|
+
end
|
53
|
+
=end
|
54
|
+
|
55
|
+
=begin
|
56
|
+
CellIdentifier = "Cell"
|
57
|
+
def tableView tableView, cellForRowAtIndexPath:indexPath
|
58
|
+
cell = tableView.dequeueReusableCellWithIdentifier CellIdentifier
|
59
|
+
cell ||= UITableViewCell.alloc.initWithStyle UITableViewCellStyleDefault, reuseIdentifier:CellIdentifier
|
60
|
+
cell.textLabel.text = "Ruby Motion"
|
61
|
+
cell
|
62
|
+
end
|
63
|
+
=end
|
64
|
+
|
65
|
+
=begin
|
66
|
+
def tableView tableView, canEditRowAtIndexPath:indexPath
|
67
|
+
true
|
68
|
+
end
|
69
|
+
=end
|
70
|
+
|
71
|
+
=begin
|
72
|
+
def tableView tableView, commitEditingStyle:editingStyle, forRowAtIndexPath:indexPath
|
73
|
+
case editingStyle
|
74
|
+
when UITableViewCellEditingStyleDelete
|
75
|
+
tableView.deleteRowsAtIndexPaths [indexPath], withRowAnimation:UITableViewRowAnimationFade
|
76
|
+
when UITableViewCellEditingStyleInsert
|
77
|
+
#
|
78
|
+
end
|
79
|
+
end
|
80
|
+
=end
|
81
|
+
|
82
|
+
=begin
|
83
|
+
def tableView tableView, moveRowAtIndexPath:fromIndexPath, toIndexPath:toIndexPath
|
84
|
+
end
|
85
|
+
=end
|
86
|
+
|
87
|
+
=begin
|
88
|
+
def tableView tableView, canMoveRowAtIndexPath:indexPath
|
89
|
+
true
|
90
|
+
end
|
91
|
+
=end
|
92
|
+
|
3
93
|
end
|
data/template/class/view.rb
CHANGED
@@ -1,3 +1,37 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
class #{class_name}View < UIView
|
3
|
+
|
4
|
+
=begin
|
5
|
+
def initWithFrame frame
|
6
|
+
super
|
7
|
+
self
|
8
|
+
end
|
9
|
+
=end
|
10
|
+
|
11
|
+
=begin
|
12
|
+
def initWithCorder decode
|
13
|
+
super
|
14
|
+
self
|
15
|
+
end
|
16
|
+
=end
|
17
|
+
|
18
|
+
=begin
|
19
|
+
def awakeFromNib
|
20
|
+
end
|
21
|
+
=end
|
22
|
+
|
23
|
+
=begin
|
24
|
+
def drawRect rect
|
25
|
+
context = UIGraphicsGetCurrentContext()
|
26
|
+
# Draw your code here.
|
27
|
+
end
|
28
|
+
=end
|
29
|
+
|
30
|
+
=begin
|
31
|
+
def shouldAutorotateToInterfaceOrientation interfaceOrientation
|
32
|
+
interfaceOrientation == UIInterfaceOrientationPortrait
|
33
|
+
end
|
34
|
+
=end
|
35
|
+
|
3
36
|
end
|
37
|
+
|
@@ -1,3 +1,41 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
class #{class_name}ViewController < UIViewController
|
3
|
+
|
4
|
+
=begin
|
5
|
+
def initWithNibName nibNameOrNil, bundle:nibBundleOrNil
|
6
|
+
super
|
7
|
+
self
|
8
|
+
end
|
9
|
+
=end
|
10
|
+
|
11
|
+
=begin
|
12
|
+
def viewDidLoad
|
13
|
+
super
|
14
|
+
end
|
15
|
+
=end
|
16
|
+
|
17
|
+
=begin
|
18
|
+
def viewDidUnload
|
19
|
+
super
|
20
|
+
end
|
21
|
+
=end
|
22
|
+
|
23
|
+
=begin
|
24
|
+
def viewWillAppear animated
|
25
|
+
super
|
26
|
+
end
|
27
|
+
=end
|
28
|
+
|
29
|
+
=begin
|
30
|
+
def viewWillDisappear animated
|
31
|
+
super
|
32
|
+
end
|
33
|
+
=end
|
34
|
+
|
35
|
+
=begin
|
36
|
+
def shouldAutorotateToInterfaceOrientation interfaceOrientation
|
37
|
+
interfaceOrientation == UIInterfaceOrientationPortrait
|
38
|
+
end
|
39
|
+
=end
|
40
|
+
|
3
41
|
end
|
data/template/spec/spec.rb
CHANGED
data/test/test_generator.rb
CHANGED
@@ -21,9 +21,9 @@ class TestGenerate < Test::Unit::TestCase
|
|
21
21
|
assert_equal "app/model/foo.rb", @generator.destination_path
|
22
22
|
end
|
23
23
|
|
24
|
-
test "destination_path shoudle be 'app/view/
|
24
|
+
test "destination_path shoudle be 'app/view/foo_view.rb' with view, foo" do
|
25
25
|
ARGV.replace %w(generate view foo)
|
26
|
-
assert_equal "app/view/
|
26
|
+
assert_equal "app/view/foo_view.rb", @generator.destination_path
|
27
27
|
end
|
28
28
|
|
29
29
|
test "destination_path shoudle be 'app/controller/foo_controller.rb' with controller, foo" do
|
@@ -62,6 +62,8 @@ class TestGenerate < Test::Unit::TestCase
|
|
62
62
|
assert_equal "app/foo.rb", @generator.destination_path
|
63
63
|
end
|
64
64
|
|
65
|
+
# It will fail becuse sample codes was included.
|
66
|
+
=begin
|
65
67
|
# --- context
|
66
68
|
test "check model file context" do
|
67
69
|
ARGV.replace %w(generate model foo)
|
@@ -133,6 +135,7 @@ end
|
|
133
135
|
EOF
|
134
136
|
assert_equal expected, @generator.context
|
135
137
|
end
|
138
|
+
=end
|
136
139
|
|
137
140
|
# --- spec context
|
138
141
|
test "check model spec file context" do
|
@@ -145,6 +148,21 @@ describe Foo do
|
|
145
148
|
true.should == true
|
146
149
|
end
|
147
150
|
|
151
|
+
end
|
152
|
+
EOF
|
153
|
+
assert_equal expected, @generator.spec_context
|
154
|
+
end
|
155
|
+
|
156
|
+
test "check view controller spec file context" do
|
157
|
+
ARGV.replace %w(generate view_controller foo)
|
158
|
+
expected = <<-EOF
|
159
|
+
# -*- coding: utf-8 -*-
|
160
|
+
describe FooViewController do
|
161
|
+
|
162
|
+
it "should be successful" do
|
163
|
+
true.should == true
|
164
|
+
end
|
165
|
+
|
148
166
|
end
|
149
167
|
EOF
|
150
168
|
assert_equal expected, @generator.spec_context
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: motion-util
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-07-13 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: It generate class and spec files.
|
15
15
|
email:
|