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 CHANGED
@@ -15,3 +15,4 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ ui.xcodeproj
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:UIButton \
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
- ## define ib outlets
83
+ ## ib outlets
84
84
  ib_outlet :scroller, UIScrollView
85
- ib_outlet :btn_hello, UIButton
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
- ## define ib action
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} * #{name};" }.join("\n")}
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
- src.scan /^\s+ib_outlet\s+:([a-zA-Z][_a-zA-Z0-9]*)\s*?,\s*['"]?([a-zA-Z][_a-zA-Z0-9]+)/
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
@@ -1,3 +1,3 @@
1
1
  module IB
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -4,6 +4,8 @@ class CustomView < UIView
4
4
  ib_outlet :greenLabel, UIGreenLabel
5
5
  ib_outlet :redLabel, "UILabel"
6
6
 
7
+ ib_outlet :untyped_label
8
+
7
9
  ib_action :someAction
8
10
 
9
11
  end
@@ -1,2 +1,3 @@
1
1
  class SimpleClass
2
+
2
3
  end
@@ -11,6 +11,7 @@ describe IB::Generator do
11
11
 
12
12
  @property IBOutlet UIGreenLabel * greenLabel;
13
13
  @property IBOutlet UILabel * redLabel;
14
+ @property IBOutlet id untyped_label;
14
15
 
15
16
  -(IBAction) someAction:(id) sender;
16
17
 
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
 
@@ -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
- ## define ib outlets
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
- ## define ib action
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.0
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-15 00:00:00.000000000 Z
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: 1976209642130019168
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: 1976209642130019168
120
+ hash: -1108691186505808116
121
121
  requirements: []
122
122
  rubyforge_project:
123
123
  rubygems_version: 1.8.24