ib 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -47,17 +47,31 @@ extend your class with IB module
47
47
  class HelloController < UIViewController
48
48
  extend IB
49
49
 
50
- attr_accessor :title
51
-
52
50
  # define ib outlet
53
- ib_outlet :title, UILabel # IBOutlet UILabel * title;
54
- ib_outlet :untyped_label # IBOutlet id untyped_label;
51
+ outlet_accessor :title, UILabel # IBOutlet UILabel * title;
52
+ outlet_accessor :untyped_label # IBOutlet id untyped_label;
55
53
 
56
- def someAction
54
+ # define ib action
55
+ def someAction sender
57
56
  end
57
+ end
58
+ ```
58
59
 
59
- # define ib action
60
- ib_action :someAction
60
+ **NOTE:** If you include methods and attributes from module, you can use `ib_outlet` and `ib_action` to make them visible in designer
61
+
62
+ ```ruby
63
+ module TouchLogger
64
+ def controlTouched sender
65
+ puts "touched"
66
+ end
67
+ end
68
+
69
+ class LogController < UIViewController
70
+ extend IB
71
+
72
+ include TouchLogger
73
+
74
+ ib_action :controlTouched
61
75
  end
62
76
  ```
63
77
 
@@ -78,19 +92,16 @@ The generated file:
78
92
  class HelloController < UIViewController
79
93
  extend IB
80
94
 
81
- attr_accessor :data_source, :scroller, :htn_hello
95
+ attr_accessor :data_source
82
96
 
83
97
  ## ib outlets
84
- ib_outlet :scroller, UIScrollView
85
- ib_outlet :btn_hello
98
+ outlet_accessor :scroller, UIScrollView
99
+ outlet_accessor :btn_hello
86
100
 
87
101
  def say_hello(sender)
88
102
  # TODO Implement action here
89
103
  end
90
104
 
91
- ## ib action
92
- ib_action :say_hello
93
-
94
105
  end
95
106
  ```
96
107
 
data/ib.gemspec CHANGED
@@ -4,7 +4,7 @@ require File.expand_path('../lib/ib/version', __FILE__)
4
4
  Gem::Specification.new do |gem|
5
5
  gem.authors = ["Yury Korolev", "Francis Chong"]
6
6
  gem.email = ["yury.korolev@gmail.com", "francis@ignition.hk"]
7
- gem.description = %q{Stupid rubymotion ib outlets support}
7
+ gem.description = %q{Magic rubymotion ib outlets support}
8
8
  gem.summary = %q{Small portion of love to interface builder with rubymotion}
9
9
  gem.homepage = ""
10
10
 
data/lib/ib/outlets.rb CHANGED
@@ -1,7 +1,10 @@
1
1
  module IB
2
2
 
3
3
  def ib_outlet name, type = "id"
4
- # maybe call attr_accessor here?
4
+ end
5
+
6
+ def outlet_accessor name, type = "id"
7
+ attr_accessor name
5
8
  end
6
9
 
7
10
  def ib_action name
data/lib/ib/parser.rb CHANGED
@@ -1,4 +1,10 @@
1
1
  class IB::Parser
2
+ CLASS_REGEX = /^\s*class\s+([a-zA-Z][_a-zA-Z0-9]+)\s*<\s*([a-zA-Z][_a-zA-Z0-9]+)/
3
+ OUTLET_REGEX = /^\s+(ib_outlet|outlet_accessor)\s+:([a-zA-Z][_a-zA-Z0-9]*)\s*?(,\s*['"]?([a-zA-Z][_a-zA-Z0-9]+))?/
4
+ METHOD_REF_REGEX = /^\s+(ib_action)\s+:([a-zA-Z][_a-zA-Z0-9]*)/
5
+ METHOD_DEF_REGEX = /^\s+(def)\s+([a-zA-Z][_a-zA-Z0-9]*)([\s(]+)([a-zA-Z][_a-zA-Z0-9]*)([\s)]*)(#.*)?$/
6
+ ACTION_REGEX = Regexp.union METHOD_DEF_REGEX, METHOD_REF_REGEX
7
+
2
8
  def find_all(dir)
3
9
  all = {}
4
10
  Dir.glob("#{dir}/**/*.rb") do |file|
@@ -12,11 +18,10 @@ class IB::Parser
12
18
  def find(path)
13
19
  src = File.read(path)
14
20
  info = {class: find_class(src)}
15
-
21
+
16
22
  return false if info[:class].length == 0
17
23
 
18
24
  info[:outlets] = find_outlets(src)
19
-
20
25
  info[:actions] = find_actions(src)
21
26
 
22
27
  info[:path] = path
@@ -25,18 +30,26 @@ class IB::Parser
25
30
  end
26
31
 
27
32
  def find_class src
28
- src.scan /^\s*class\s+([a-zA-Z][_a-zA-Z0-9]+)\s*<\s*([a-zA-Z][_a-zA-Z0-9]+)/
33
+ src.scan CLASS_REGEX
29
34
  end
30
35
 
31
36
  def find_outlets src
32
37
  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"]
38
+ src.scan OUTLET_REGEX do |groups|
39
+ outlets << [groups[1], groups[3] || "id"]
35
40
  end
36
41
  outlets
37
42
  end
38
43
 
39
44
  def find_actions src
40
- src.scan /^\s+ib_action\s+:([a-zA-Z][_a-zA-Z0-9]*)/
45
+ actions = []
46
+ src.scan ACTION_REGEX do |groups|
47
+ if groups[0] == "def"
48
+ actions << [groups[1]]
49
+ elsif groups[6] == "ib_action"
50
+ actions << [groups[7]]
51
+ end
52
+ end
53
+ actions.uniq
41
54
  end
42
55
  end
data/lib/ib/tasks.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'rake'
2
2
 
3
3
  desc "Generates ui.xcodeproj and open it"
4
- task "design" do
4
+ task :design do
5
5
  IB::Project.new.write
6
6
  system "open ui.xcodeproj"
7
7
  end
data/lib/ib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module IB
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -6,6 +6,20 @@ class CustomView < UIView
6
6
 
7
7
  ib_outlet :untyped_label
8
8
 
9
+ outlet_accessor :yellowLabel
10
+
9
11
  ib_action :someAction
12
+
13
+ def anotherAction button
14
+ end
15
+
16
+ def actionWithComment sender # test
17
+ end
18
+
19
+ def actionWithBrackets(sender)
20
+ end
21
+
22
+ def notAction with, toArgs
23
+ end
10
24
 
11
25
  end
@@ -12,8 +12,12 @@ describe IB::Generator do
12
12
  @property IBOutlet UIGreenLabel * greenLabel;
13
13
  @property IBOutlet UILabel * redLabel;
14
14
  @property IBOutlet id untyped_label;
15
+ @property IBOutlet id yellowLabel;
15
16
 
16
17
  -(IBAction) someAction:(id) sender;
18
+ -(IBAction) anotherAction:(id) sender;
19
+ -(IBAction) actionWithComment:(id) sender;
20
+ -(IBAction) actionWithBrackets:(id) sender;
17
21
 
18
22
  @end
19
23
 
data/spec/parser_spec.rb CHANGED
@@ -6,8 +6,8 @@ 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"], ["untyped_label", "id"]]
10
- info[:actions].should == [["someAction"]]
9
+ info[:outlets].should == [["greenLabel", "UIGreenLabel"], ["redLabel", "UILabel"], ["untyped_label", "id"], ["yellowLabel", "id"]]
10
+ info[:actions].should == [["someAction"], ["anotherAction"], ["actionWithComment"], ["actionWithBrackets"]]
11
11
  end
12
12
 
13
13
  it "detects simple classes" do
@@ -1,15 +1,15 @@
1
1
  class <%= controller_name %> < <%= controller_type %>
2
2
  extend IB
3
3
 
4
- attr_accessor <%= (options[:accessors] + options[:outlets].keys).collect{|acc| ":#{acc}"}.join(", ") %>
4
+ attr_accessor <%= options[:accessors].collect{|acc| ":#{acc}"}.join(", ") %>
5
5
 
6
6
  <% if options[:outlets].length > 0 %>
7
7
  ## ib outlets
8
8
  <% options[:outlets].each do |name, type| -%>
9
9
  <% if type.empty? || type == "id" -%>
10
- ib_outlet :<%= name %>
10
+ outlet_accessor :<%= name %>
11
11
  <% else -%>
12
- ib_outlet :<%= name %>, <%= type %>
12
+ outlet_accessor :<%= name %>, <%= type %>
13
13
  <% end -%>
14
14
  <% end -%>
15
15
  <% end -%>
@@ -21,10 +21,6 @@ class <%= controller_name %> < <%= controller_type %>
21
21
  end
22
22
  <% end -%>
23
23
 
24
- ## ib actions
25
- <% options[:actions].each do |action| -%>
26
- ib_action :<%= action %>
27
- <% end -%>
28
24
  <% end -%>
29
25
 
30
26
  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.2
4
+ version: 0.1.3
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-21 00:00:00.000000000 Z
13
+ date: 2012-08-08 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: xcodeproj
@@ -60,7 +60,7 @@ dependencies:
60
60
  - - ! '>='
61
61
  - !ruby/object:Gem::Version
62
62
  version: '2.0'
63
- description: Stupid rubymotion ib outlets support
63
+ description: Magic rubymotion ib outlets support
64
64
  email:
65
65
  - yury.korolev@gmail.com
66
66
  - francis@ignition.hk
@@ -108,7 +108,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
108
108
  version: '0'
109
109
  segments:
110
110
  - 0
111
- hash: 3972118293195904556
111
+ hash: 4072317502199486980
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: 3972118293195904556
120
+ hash: 4072317502199486980
121
121
  requirements: []
122
122
  rubyforge_project:
123
123
  rubygems_version: 1.8.24