motion-util 0.1.4 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -12,7 +12,7 @@ Installation
12
12
  Usage
13
13
  ===
14
14
 
15
- Generate class file.
15
+ ### Generate class file.
16
16
 
17
17
  motion-util generate model Foo
18
18
  motion-util generate controller Foo
@@ -26,7 +26,7 @@ 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.
29
+ ### Generate Objective-C header file for Interface Builder.
30
30
 
31
31
  motion-util ib_header
32
32
 
@@ -34,7 +34,8 @@ Generate Objective-C header file for Interface Builder.
34
34
  motion-util ibh
35
35
 
36
36
 
37
- Your ruby motion class:
37
+ Your ruby motion class:
38
+
38
39
  <pre>
39
40
  # app_delegate.rb
40
41
  class AppDelegate
@@ -47,19 +48,24 @@ class AppDelegate
47
48
  @window.makeKeyAndVisible
48
49
  true
49
50
  end
51
+
52
+ def showDialog sender # IBAction
53
+ end
54
+
50
55
  end
51
56
  </pre>
52
57
 
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.
58
+ @type_info is a marker to describe a class by Objective-C.
59
+ If it's not specified it will be id type.
60
+
61
+ After execution 'motion-util ibh', AppDelegate.h was generated in tmp/header directory like this.
57
62
 
58
63
  <pre>
59
64
  // AppDelegate.h
60
65
  @interface AppDelegate : NSObject
61
66
  @property (strong, nonatomic) IBOutlet UIWindow *window;
62
67
  @property (strong, nonatomic) IBOutlet UIViewController *controller;
68
+ - (IBAction)showDialog:(id)sender;
63
69
  @end
64
70
  </pre>
65
71
 
@@ -38,13 +38,13 @@ module Motion
38
38
 
39
39
  def context
40
40
  c = File.read File.join(@template_dir, "class", file_type + ".rb")
41
- c.gsub! /#\{class_name\}/, class_name
41
+ c.gsub! /#\{class_name\}/, objc_class_name
42
42
  c
43
43
  end
44
44
 
45
45
  def spec_context
46
46
  c = File.read File.join(@template_dir, "spec", "spec.rb")
47
- c.gsub! /#\{class_name\}/, class_name
47
+ c.gsub! /#\{class_name\}/, objc_class_name
48
48
  c.gsub! /#\{camelized_file_type\}/, camelized_file_type
49
49
  c
50
50
  end
@@ -103,6 +103,10 @@ module Motion
103
103
  @class_name
104
104
  end
105
105
 
106
+ def objc_class_name
107
+ class_name.split('_').collect{|e| e.capitalize}.join
108
+ end
109
+
106
110
  def camelized_file_type
107
111
  case file_type
108
112
  when "general", "model"
@@ -22,7 +22,7 @@ module Motion
22
22
 
23
23
  class IbHeader
24
24
 
25
- attr_reader :class_name, :super_name, :properties
25
+ attr_reader :class_name, :super_name, :properties, :actions
26
26
 
27
27
  def source= source
28
28
  @source = source
@@ -32,6 +32,7 @@ module Motion
32
32
  def context
33
33
  lines = []
34
34
  lines << "@interface #{@class_name} : #{@super_name || 'NSObject'}"
35
+
35
36
  properties.each do |k, v|
36
37
  if v[:readonly]
37
38
  lines << "@property (strong, nonatomic, readonly) IBOutlet #{type_name_of v[:type]}#{k};"
@@ -39,6 +40,11 @@ module Motion
39
40
  lines << "@property (strong, nonatomic) IBOutlet #{type_name_of v[:type]}#{k};"
40
41
  end
41
42
  end
43
+
44
+ actions.each do |a|
45
+ lines << "- (IBAction)#{a[0]}:(id)#{a[1]};"
46
+ end
47
+
42
48
  lines << "@end"
43
49
  lines << ""
44
50
  lines.join "\n"
@@ -59,14 +65,24 @@ module Motion
59
65
  @super_name = $3
60
66
 
61
67
  @properties = {}
68
+ @actions = []
62
69
  @source.split("\n").each do |l|
63
- /(attr_accessor|attr_reader)\s+([A-Za-z0-9:, ]+)(#\s*(@type_info\s+(\w+)?)?)?/ =~ l
64
- type = type_of $5
65
- $2.split(",").each do |p|
66
- p = eval(p.strip)
67
- @properties[p] = { type:type }
68
- @properties[p].merge!(readonly:true) if $1 == "attr_reader"
69
- end if $2
70
+
71
+ case l
72
+
73
+ # property
74
+ when /(attr_accessor|attr_reader)\s+([A-Za-z0-9:, ]+)(#\s*(@type_info\s+(\w+)?)?)?/
75
+ type = type_of $5
76
+ $2.split(",").each do |p|
77
+ p = eval(p.strip)
78
+ @properties[p] = { type:type }
79
+ @properties[p].merge!(readonly:true) if $1 == "attr_reader"
80
+ end if $2
81
+
82
+ # action
83
+ when /def\s+(.+)\s+(.+)\s+#\s*IBAction/
84
+ actions << [$1, $2]
85
+ end
70
86
  end
71
87
  end
72
88
 
@@ -1,6 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  module Motion
3
3
  module Util
4
- VERSION = "0.1.4"
4
+ VERSION = "0.1.6"
5
5
  end
6
6
  end
@@ -19,16 +19,40 @@ class #{class_name}NavigationController < UINavigationController
19
19
  end
20
20
  =end
21
21
 
22
+ =begin
23
+ def viewDidAppear animated
24
+ super
25
+ end
26
+ =end
27
+
22
28
  =begin
23
29
  def viewWillDisappear animated
24
30
  super
25
31
  end
26
32
  =end
27
33
 
34
+ =begin
35
+ def viewDidDisappear animated
36
+ super
37
+ end
38
+ =end
39
+
28
40
  =begin
29
41
  def shouldAutorotateToInterfaceOrientation interfaceOrientation
30
42
  interfaceOrientation == UIInterfaceOrientationPortrait
31
43
  end
32
44
  =end
33
45
 
46
+ =begin
47
+ def shouldAutorotate
48
+ true
49
+ end
50
+ =end
51
+
52
+ =begin
53
+ def supportedInterfaceOrientations
54
+ UIInterfaceOrientationMaskPortrait
55
+ end
56
+ =end
57
+
34
58
  end
@@ -19,17 +19,40 @@ class #{class_name}TabBarController < UITabBarController
19
19
  end
20
20
  =end
21
21
 
22
+ =begin
23
+ def viewDidAppear animated
24
+ super
25
+ end
26
+ =end
27
+
22
28
  =begin
23
29
  def viewWillDisappear animated
24
30
  super
25
31
  end
26
32
  =end
27
33
 
34
+ =begin
35
+ def viewDidDisappear animated
36
+ super
37
+ end
38
+ =end
39
+
28
40
  =begin
29
41
  def shouldAutorotateToInterfaceOrientation interfaceOrientation
30
42
  interfaceOrientation == UIInterfaceOrientationPortrait
31
43
  end
32
44
  =end
33
45
 
46
+ =begin
47
+ def shouldAutorotate
48
+ true
49
+ end
50
+ =end
51
+
52
+ =begin
53
+ def supportedInterfaceOrientations
54
+ UIInterfaceOrientationMaskPortrait
55
+ end
56
+ =end
34
57
 
35
58
  end
@@ -27,18 +27,42 @@ class #{class_name}TableViewController < UITableViewController
27
27
  end
28
28
  =end
29
29
 
30
+ =begin
31
+ def viewDidAppear animated
32
+ super
33
+ end
34
+ =end
35
+
30
36
  =begin
31
37
  def viewWillDisappear animated
32
38
  super
33
39
  end
34
40
  =end
35
41
 
42
+ =begin
43
+ def viewDidDisappear animated
44
+ super
45
+ end
46
+ =end
47
+
36
48
  =begin
37
49
  def shouldAutorotateToInterfaceOrientation interfaceOrientation
38
50
  interfaceOrientation == UIInterfaceOrientationPortrait
39
51
  end
40
52
  =end
41
53
 
54
+ =begin
55
+ def shouldAutorotate
56
+ true
57
+ end
58
+ =end
59
+
60
+ =begin
61
+ def supportedInterfaceOrientations
62
+ UIInterfaceOrientationMaskPortrait
63
+ end
64
+ =end
65
+
42
66
 
43
67
  =begin
44
68
  def numberOfSectionsInTableView tableView
@@ -52,21 +76,50 @@ class #{class_name}TableViewController < UITableViewController
52
76
  end
53
77
  =end
54
78
 
79
+ =begin
80
+ def tableView tableView, titleForHeaderInSection:section
81
+ nil
82
+ end
83
+ =end
84
+
55
85
  =begin
56
86
  CellIdentifier = "Cell"
57
87
  def tableView tableView, cellForRowAtIndexPath:indexPath
58
- cell = tableView.dequeueReusableCellWithIdentifier CellIdentifier
59
- cell ||= UITableViewCell.alloc.initWithStyle UITableViewCellStyleDefault, reuseIdentifier:CellIdentifier
88
+ cell = tableView.dequeueReusableCellWithIdentifier CellIdentifier, forIndexPath:indexPath
60
89
  cell.textLabel.text = "Ruby Motion"
61
90
  cell
62
91
  end
63
92
  =end
64
93
 
94
+ =begine
95
+ def tableView tableView, didSelectRowAtIndexPath:indexPath
96
+ tableView.deselectRowAtIndexPath indexPath, animated:true
97
+ end
98
+ =end
99
+
65
100
  =begin
66
101
  def tableView tableView, canEditRowAtIndexPath:indexPath
67
102
  true
68
103
  end
69
104
  =end
105
+
106
+ =begine
107
+ def tableView tableView, editingStyleForRowAtIndexPath:indexPath
108
+ UITableViewCellEditingStyleDelete
109
+ end
110
+ =end
111
+
112
+ =begin
113
+ def tableView tableView, canMoveRowAtIndexPath:indexPath
114
+ true
115
+ end
116
+ =end
117
+
118
+ =begin
119
+ def tableView tableView, moveRowAtIndexPath:fromIndexPath, toIndexPath:toIndexPath
120
+ toIndexPath
121
+ end
122
+ =end
70
123
 
71
124
  =begin
72
125
  def tableView tableView, commitEditingStyle:editingStyle, forRowAtIndexPath:indexPath
@@ -79,15 +132,4 @@ class #{class_name}TableViewController < UITableViewController
79
132
  end
80
133
  =end
81
134
 
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
-
93
135
  end
@@ -26,16 +26,40 @@ class #{class_name}ViewController < UIViewController
26
26
  end
27
27
  =end
28
28
 
29
+ =begin
30
+ def viewDidAppear animated
31
+ super
32
+ end
33
+ =end
34
+
29
35
  =begin
30
36
  def viewWillDisappear animated
31
37
  super
32
38
  end
33
39
  =end
34
40
 
41
+ =begin
42
+ def viewDidDisappear animated
43
+ super
44
+ end
45
+ =end
46
+
35
47
  =begin
36
48
  def shouldAutorotateToInterfaceOrientation interfaceOrientation
37
49
  interfaceOrientation == UIInterfaceOrientationPortrait
38
50
  end
39
51
  =end
40
52
 
53
+ =begin
54
+ def shouldAutorotate
55
+ true
56
+ end
57
+ =end
58
+
59
+ =begin
60
+ def supportedInterfaceOrientations
61
+ UIInterfaceOrientationMaskPortrait
62
+ end
63
+ =end
64
+
41
65
  end
@@ -4,6 +4,12 @@ require 'motion-util'
4
4
 
5
5
 
6
6
  include Motion::Util
7
+ class Generator
8
+ def get_objc_class_name
9
+ objc_class_name
10
+ end
11
+ end
12
+
7
13
 
8
14
  class TestGenerate < Test::Unit::TestCase
9
15
 
@@ -167,6 +173,10 @@ end
167
173
  EOF
168
174
  assert_equal expected, @generator.spec_context
169
175
  end
170
-
176
+
177
+ test "check objc class name" do
178
+ ARGV.replace %w(generate model foo_bar)
179
+ assert_equal "FooBar", @generator.get_objc_class_name
180
+ end
171
181
  end
172
182
 
@@ -56,6 +56,8 @@ class Foo
56
56
  attr_accessor :foo # no type
57
57
  attr_accessor :bar # @type_info UILabel
58
58
  attr_reader :hoge # @type_info UIView
59
+ def action sender # IBAction
60
+ end
59
61
  end
60
62
  EOF
61
63
 
@@ -64,6 +66,7 @@ end
64
66
  @property (strong, nonatomic) IBOutlet id foo;
65
67
  @property (strong, nonatomic) IBOutlet UILabel *bar;
66
68
  @property (strong, nonatomic, readonly) IBOutlet UIView *hoge;
69
+ - (IBAction)action:(id)sender;
67
70
  @end
68
71
  EOF
69
72
 
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
4
+ version: 0.1.6
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-07-13 00:00:00.000000000 Z
12
+ date: 2014-01-07 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: It generate class and spec files.
15
15
  email:
@@ -63,7 +63,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
63
63
  version: '0'
64
64
  requirements: []
65
65
  rubyforge_project: motion-util
66
- rubygems_version: 1.8.10
66
+ rubygems_version: 1.8.25
67
67
  signing_key:
68
68
  specification_version: 3
69
69
  summary: Convenient command set for Ruby Motion.