ib 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/README.md +6 -7
- data/lib/ib/generator.rb +5 -1
- data/lib/ib/parser.rb +5 -1
- data/lib/ib/version.rb +1 -1
- data/spec/fixtures/custom_view.rb +2 -0
- data/spec/fixtures/simple_class.rb +1 -0
- data/spec/generator_spec.rb +1 -0
- data/spec/parser_spec.rb +1 -1
- data/template/controller.erb +10 -4
- metadata +4 -4
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -50,7 +50,8 @@ class HelloController < UIViewController
|
|
50
50
|
attr_accessor :title
|
51
51
|
|
52
52
|
# define ib outlet
|
53
|
-
ib_outlet :title, UILabel
|
53
|
+
ib_outlet :title, UILabel # IBOutlet UILabel * title;
|
54
|
+
ib_outlet :untyped_label # IBOutlet id untyped_label;
|
54
55
|
|
55
56
|
def someAction
|
56
57
|
end
|
@@ -65,7 +66,7 @@ Generate controller with folllowing command:
|
|
65
66
|
|
66
67
|
```
|
67
68
|
ib c Hello UIViewController \
|
68
|
-
--outlets scroller:UIScrollView btn_hello:
|
69
|
+
--outlets scroller:UIScrollView btn_hello: \
|
69
70
|
--actions say_hello \
|
70
71
|
--accessors data_source
|
71
72
|
```
|
@@ -77,19 +78,17 @@ The generated file:
|
|
77
78
|
class HelloController < UIViewController
|
78
79
|
extend IB
|
79
80
|
|
80
|
-
## define accessors
|
81
81
|
attr_accessor :data_source, :scroller, :htn_hello
|
82
82
|
|
83
|
-
##
|
83
|
+
## ib outlets
|
84
84
|
ib_outlet :scroller, UIScrollView
|
85
|
-
ib_outlet :btn_hello
|
85
|
+
ib_outlet :btn_hello
|
86
86
|
|
87
|
-
## define actions
|
88
87
|
def say_hello(sender)
|
89
88
|
# TODO Implement action here
|
90
89
|
end
|
91
90
|
|
92
|
-
##
|
91
|
+
## ib action
|
93
92
|
ib_action :say_hello
|
94
93
|
|
95
94
|
end
|
data/lib/ib/generator.rb
CHANGED
@@ -35,7 +35,7 @@ OBJC
|
|
35
35
|
<<-OBJC
|
36
36
|
@interface #{info[:class][0][0]} : #{info[:class][0][1]}
|
37
37
|
|
38
|
-
#{info[:outlets].map {|name, type| "@property IBOutlet #{type}
|
38
|
+
#{info[:outlets].map {|name, type| "@property IBOutlet #{generate_type(type)} #{name};" }.join("\n")}
|
39
39
|
|
40
40
|
#{info[:actions].map {|action| "-(IBAction) #{action[0]}:(id) sender;" }.join("\n")}
|
41
41
|
|
@@ -53,4 +53,8 @@ OBJC
|
|
53
53
|
OBJC
|
54
54
|
end.join("\n" * 2)
|
55
55
|
end
|
56
|
+
|
57
|
+
def generate_type type
|
58
|
+
type == "id" ? type : "#{type} *"
|
59
|
+
end
|
56
60
|
end
|
data/lib/ib/parser.rb
CHANGED
@@ -29,7 +29,11 @@ class IB::Parser
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def find_outlets src
|
32
|
-
|
32
|
+
outlets = []
|
33
|
+
src.scan /^\s+ib_outlet\s+:([a-zA-Z][_a-zA-Z0-9]*)\s*?(,\s*['"]?([a-zA-Z][_a-zA-Z0-9]+))?/ do |groups|
|
34
|
+
outlets << [groups[0], groups[2] || "id"]
|
35
|
+
end
|
36
|
+
outlets
|
33
37
|
end
|
34
38
|
|
35
39
|
def find_actions src
|
data/lib/ib/version.rb
CHANGED
data/spec/generator_spec.rb
CHANGED
data/spec/parser_spec.rb
CHANGED
@@ -6,7 +6,7 @@ describe IB::Parser do
|
|
6
6
|
it "finds outlets and actions" do
|
7
7
|
info = IB::Parser.new.find("spec/fixtures/custom_view.rb")
|
8
8
|
info[:class].should == [["CustomView", "UIView"]]
|
9
|
-
info[:outlets].should == [["greenLabel", "UIGreenLabel"], ["redLabel", "UILabel"]]
|
9
|
+
info[:outlets].should == [["greenLabel", "UIGreenLabel"], ["redLabel", "UILabel"], ["untyped_label", "id"]]
|
10
10
|
info[:actions].should == [["someAction"]]
|
11
11
|
end
|
12
12
|
|
data/template/controller.erb
CHANGED
@@ -1,24 +1,30 @@
|
|
1
1
|
class <%= controller_name %> < <%= controller_type %>
|
2
2
|
extend IB
|
3
3
|
|
4
|
-
## define accessors
|
5
4
|
attr_accessor <%= (options[:accessors] + options[:outlets].keys).collect{|acc| ":#{acc}"}.join(", ") %>
|
6
5
|
|
7
|
-
|
6
|
+
<% if options[:outlets].length > 0 %>
|
7
|
+
## ib outlets
|
8
8
|
<% options[:outlets].each do |name, type| -%>
|
9
|
+
<% if type.empty? || type == "id" -%>
|
10
|
+
ib_outlet :<%= name %>
|
11
|
+
<% else -%>
|
9
12
|
ib_outlet :<%= name %>, <%= type %>
|
10
13
|
<% end -%>
|
14
|
+
<% end -%>
|
15
|
+
<% end -%>
|
16
|
+
<% if options[:actions].length > 0 %>
|
11
17
|
|
12
|
-
## define actions
|
13
18
|
<% options[:actions].each do |action| -%>
|
14
19
|
def <%= action %>(sender)
|
15
20
|
# TODO Implement action here
|
16
21
|
end
|
17
22
|
<% end -%>
|
18
23
|
|
19
|
-
##
|
24
|
+
## ib actions
|
20
25
|
<% options[:actions].each do |action| -%>
|
21
26
|
ib_action :<%= action %>
|
22
27
|
<% end -%>
|
28
|
+
<% end -%>
|
23
29
|
|
24
30
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-07-
|
13
|
+
date: 2012-07-18 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: xcodeproj
|
@@ -108,7 +108,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
108
108
|
version: '0'
|
109
109
|
segments:
|
110
110
|
- 0
|
111
|
-
hash:
|
111
|
+
hash: -1108691186505808116
|
112
112
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
113
|
none: false
|
114
114
|
requirements:
|
@@ -117,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
117
117
|
version: '0'
|
118
118
|
segments:
|
119
119
|
- 0
|
120
|
-
hash:
|
120
|
+
hash: -1108691186505808116
|
121
121
|
requirements: []
|
122
122
|
rubyforge_project:
|
123
123
|
rubygems_version: 1.8.24
|