ib 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 +4 -4
- data/lib/ib/generator.rb +8 -2
- data/lib/ib/outlets.rb +17 -0
- data/lib/ib/parser.rb +22 -15
- data/lib/ib/version.rb +1 -1
- data/spec/fixtures/custom_view.rb +13 -3
- data/spec/generator_spec.rb +10 -2
- data/spec/parser_spec.rb +20 -3
- data/template/controller.erb +2 -2
- metadata +4 -4
data/README.md
CHANGED
@@ -48,8 +48,8 @@ class HelloController < UIViewController
|
|
48
48
|
extend IB
|
49
49
|
|
50
50
|
# define ib outlet
|
51
|
-
|
52
|
-
|
51
|
+
outlet :title, UILabel # IBOutlet UILabel * title;
|
52
|
+
outlet :untyped_label # IBOutlet id untyped_label;
|
53
53
|
|
54
54
|
# define ib action
|
55
55
|
def someAction sender
|
@@ -95,8 +95,8 @@ class HelloController < UIViewController
|
|
95
95
|
attr_accessor :data_source
|
96
96
|
|
97
97
|
## ib outlets
|
98
|
-
|
99
|
-
|
98
|
+
outlet :scroller, UIScrollView
|
99
|
+
outlet :btn_hello
|
100
100
|
|
101
101
|
def say_hello(sender)
|
102
102
|
# TODO Implement action here
|
data/lib/ib/generator.rb
CHANGED
@@ -37,7 +37,9 @@ OBJC
|
|
37
37
|
|
38
38
|
#{info[:outlets].map {|name, type| "@property IBOutlet #{generate_type(type)} #{name};" }.join("\n")}
|
39
39
|
|
40
|
-
#{info[:
|
40
|
+
#{info[:outlet_collections].map {|name, type| "@property IBOutletCollection(#{type}) NSArray * #{name};" }.join("\n")}
|
41
|
+
|
42
|
+
#{info[:actions].map {|action| "-(IBAction) #{generate_action(action)};" }.join("\n")}
|
41
43
|
|
42
44
|
@end
|
43
45
|
OBJC
|
@@ -57,4 +59,8 @@ OBJC
|
|
57
59
|
def generate_type type
|
58
60
|
type == "id" ? type : "#{type} *"
|
59
61
|
end
|
60
|
-
|
62
|
+
|
63
|
+
def generate_action action
|
64
|
+
action[1] ? "#{action[0]}:(id) #{action[1]}" : "#{action[0]}"
|
65
|
+
end
|
66
|
+
end
|
data/lib/ib/outlets.rb
CHANGED
@@ -4,6 +4,23 @@ module IB
|
|
4
4
|
end
|
5
5
|
|
6
6
|
def outlet_accessor name, type = "id"
|
7
|
+
puts "Depricated: use `outlet` instead of `outlet_accessor`"
|
8
|
+
attr_accessor name
|
9
|
+
end
|
10
|
+
|
11
|
+
def outlet name, type = "id"
|
12
|
+
attr_accessor name
|
13
|
+
end
|
14
|
+
|
15
|
+
def ib_outlet_collection name, type = "id"
|
16
|
+
end
|
17
|
+
|
18
|
+
def outlet_collection_accessor name, type = "id"
|
19
|
+
puts "Depricated: use `outlet_collection` instead of `outlet_collection_accessor`"
|
20
|
+
attr_accessor name
|
21
|
+
end
|
22
|
+
|
23
|
+
def outlet_collection name, type = "id"
|
7
24
|
attr_accessor name
|
8
25
|
end
|
9
26
|
|
data/lib/ib/parser.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
class IB::Parser
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
2
|
+
NAME_REGEX = /[a-zA-Z][_a-zA-Z0-9]*/
|
3
|
+
CLASS_REGEX = /^[ \t]*class[ \t]+(#{NAME_REGEX})[ \t]*<[ \t]*(#{NAME_REGEX})/
|
4
|
+
OUTLET_REGEX = /^[ \t]+(ib_)?outlet(_accessor)?[ \t]+:(#{NAME_REGEX})[ \t]*?(,[ \t]*['"]?(#{NAME_REGEX}))?/
|
5
|
+
OUTLET_COLLECTION_REGEX = /^[ \t]+(ib_)?outlet_collection(_accessor)?[ \t]+:(#{NAME_REGEX})[ \t]*?(,[ \t]*['"]?(#{NAME_REGEX}))?/
|
6
|
+
METHOD_REF_REGEX = /^[ \t]+(ib_action)[ \t]:(#{NAME_REGEX})/
|
7
|
+
METHOD_DEF_REGEX = /^[ \t]+(def)[ \t](#{NAME_REGEX})([ \t(]+)?(#{NAME_REGEX})?([ \t)]*)(#.*)?$/
|
6
8
|
ACTION_REGEX = Regexp.union METHOD_DEF_REGEX, METHOD_REF_REGEX
|
7
9
|
|
8
10
|
def find_all(dir)
|
@@ -22,6 +24,7 @@ class IB::Parser
|
|
22
24
|
return false if info[:class].length == 0
|
23
25
|
|
24
26
|
info[:outlets] = find_outlets(src)
|
27
|
+
info[:outlet_collections] = find_outlet_collections(src)
|
25
28
|
info[:actions] = find_actions(src)
|
26
29
|
|
27
30
|
info[:path] = path
|
@@ -34,22 +37,26 @@ class IB::Parser
|
|
34
37
|
end
|
35
38
|
|
36
39
|
def find_outlets src
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
+
src.scan(OUTLET_REGEX).map do |groups|
|
41
|
+
[groups[2], groups[4] || "id"]
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def find_outlet_collections src
|
46
|
+
src.scan(OUTLET_COLLECTION_REGEX).map do |groups|
|
47
|
+
[groups[2], groups[4] || "id"]
|
40
48
|
end
|
41
|
-
outlets
|
42
49
|
end
|
43
50
|
|
44
51
|
def find_actions src
|
45
|
-
|
46
|
-
src.scan ACTION_REGEX do |groups|
|
52
|
+
src.scan(ACTION_REGEX).map do |groups|
|
47
53
|
if groups[0] == "def"
|
48
|
-
|
54
|
+
[groups[1], groups[3]]
|
49
55
|
elsif groups[6] == "ib_action"
|
50
|
-
|
56
|
+
[groups[7], 'sender']
|
57
|
+
else
|
58
|
+
nil
|
51
59
|
end
|
52
|
-
end
|
53
|
-
actions.uniq
|
60
|
+
end.compact.uniq {|action| action[0]}
|
54
61
|
end
|
55
|
-
end
|
62
|
+
end
|
data/lib/ib/version.rb
CHANGED
@@ -6,7 +6,14 @@ class CustomView < UIView
|
|
6
6
|
|
7
7
|
ib_outlet :untyped_label
|
8
8
|
|
9
|
-
|
9
|
+
outlet :yellowLabel
|
10
|
+
|
11
|
+
ib_outlet_collection :greenLabelCollection, UIGreenLabel
|
12
|
+
ib_outlet_collection :redLabelCollection, "UILabel"
|
13
|
+
|
14
|
+
ib_outlet_collection :untyped_label_collection
|
15
|
+
|
16
|
+
outlet_collection :yellowLabelCollection
|
10
17
|
|
11
18
|
ib_action :someAction
|
12
19
|
|
@@ -21,5 +28,8 @@ class CustomView < UIView
|
|
21
28
|
|
22
29
|
def notAction with, toArgs
|
23
30
|
end
|
24
|
-
|
25
|
-
|
31
|
+
|
32
|
+
def actionWithoutArgs
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
data/spec/generator_spec.rb
CHANGED
@@ -14,10 +14,16 @@ describe IB::Generator do
|
|
14
14
|
@property IBOutlet id untyped_label;
|
15
15
|
@property IBOutlet id yellowLabel;
|
16
16
|
|
17
|
+
@property IBOutletCollection(UIGreenLabel) NSArray * greenLabelCollection;
|
18
|
+
@property IBOutletCollection(UILabel) NSArray * redLabelCollection;
|
19
|
+
@property IBOutletCollection(id) NSArray * untyped_label_collection;
|
20
|
+
@property IBOutletCollection(id) NSArray * yellowLabelCollection;
|
21
|
+
|
17
22
|
-(IBAction) someAction:(id) sender;
|
18
|
-
-(IBAction) anotherAction:(id)
|
23
|
+
-(IBAction) anotherAction:(id) button;
|
19
24
|
-(IBAction) actionWithComment:(id) sender;
|
20
25
|
-(IBAction) actionWithBrackets:(id) sender;
|
26
|
+
-(IBAction) actionWithoutArgs;
|
21
27
|
|
22
28
|
@end
|
23
29
|
|
@@ -28,7 +34,9 @@ describe IB::Generator do
|
|
28
34
|
|
29
35
|
|
30
36
|
|
37
|
+
|
38
|
+
|
31
39
|
@end
|
32
40
|
OBJC
|
33
41
|
end
|
34
|
-
end
|
42
|
+
end
|
data/spec/parser_spec.rb
CHANGED
@@ -6,8 +6,25 @@ 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 == [
|
10
|
-
|
9
|
+
info[:outlets].should == [
|
10
|
+
["greenLabel", "UIGreenLabel"],
|
11
|
+
["redLabel", "UILabel"],
|
12
|
+
["untyped_label", "id"],
|
13
|
+
["yellowLabel", "id"]
|
14
|
+
]
|
15
|
+
info[:outlet_collections].should == [
|
16
|
+
["greenLabelCollection", "UIGreenLabel"],
|
17
|
+
["redLabelCollection", "UILabel"],
|
18
|
+
["untyped_label_collection", "id"],
|
19
|
+
["yellowLabelCollection", "id"]
|
20
|
+
]
|
21
|
+
info[:actions].should == [
|
22
|
+
["someAction", "sender"],
|
23
|
+
["anotherAction", "button"],
|
24
|
+
["actionWithComment", "sender"],
|
25
|
+
["actionWithBrackets", "sender"],
|
26
|
+
["actionWithoutArgs", nil]
|
27
|
+
]
|
11
28
|
end
|
12
29
|
|
13
30
|
it "detects simple classes" do
|
@@ -17,4 +34,4 @@ describe IB::Parser do
|
|
17
34
|
it "finds all infos" do
|
18
35
|
puts IB::Parser.new.find_all("spec/fixtures").inspect
|
19
36
|
end
|
20
|
-
end
|
37
|
+
end
|
data/template/controller.erb
CHANGED
@@ -7,9 +7,9 @@ class <%= controller_name %> < <%= controller_type %>
|
|
7
7
|
## ib outlets
|
8
8
|
<% options[:outlets].each do |name, type| -%>
|
9
9
|
<% if type.empty? || type == "id" -%>
|
10
|
-
|
10
|
+
outlet :<%= name %>
|
11
11
|
<% else -%>
|
12
|
-
|
12
|
+
outlet :<%= name %>, <%= type %>
|
13
13
|
<% end -%>
|
14
14
|
<% end -%>
|
15
15
|
<% 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.4
|
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-08-
|
13
|
+
date: 2012-08-09 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: 1512499769767831646
|
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: 1512499769767831646
|
121
121
|
requirements: []
|
122
122
|
rubyforge_project:
|
123
123
|
rubygems_version: 1.8.24
|