ib 0.3.4 → 0.3.5
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.
- checksums.yaml +4 -4
- data/ib.gemspec +2 -1
- data/lib/ib/generator.rb +22 -63
- data/lib/ib/generator/rendering_helper.rb +32 -0
- data/lib/ib/generator/templates/Stubs.h.erb +30 -0
- data/lib/ib/generator/templates/Stubs.m.erb +11 -0
- data/lib/ib/project.rb +2 -1
- data/lib/ib/version.rb +1 -1
- data/spec/generator_spec.rb +69 -8
- metadata +21 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1e9c82fc607ab9a37e14ad18ebf69c2fecc0e256
|
4
|
+
data.tar.gz: 153e219a271e45ee4a78fe841c57b6bb82d62c0f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 84f6f138dc29230e26161f3ca09439fd6936520ceae59e8e672890db37415c18b50ed2d69dae2a5b47d6641ab71304e66d355da176e035d52835ebaf6ea6b58c
|
7
|
+
data.tar.gz: 323138c6ef452527eb72c2f7260f0e844f1b5953aed1da529f9a2d8e19e2916e7ff70e542721794ef13e7263a5835bcc4dd2a0f4d328ba08fcb58c62b9cf3f8f
|
data/ib.gemspec
CHANGED
@@ -15,8 +15,9 @@ Gem::Specification.new do |gem|
|
|
15
15
|
gem.require_paths = ["lib"]
|
16
16
|
gem.version = IB::VERSION
|
17
17
|
|
18
|
-
gem.add_dependency "xcodeproj", ">= 0.11.
|
18
|
+
gem.add_dependency "xcodeproj", ">= 0.11.1"
|
19
19
|
gem.add_dependency "thor", ">= 0.15.4"
|
20
|
+
gem.add_dependency "tilt", ">= 1.4.1"
|
20
21
|
|
21
22
|
gem.add_development_dependency "rspec", ">= 2.0"
|
22
23
|
gem.add_development_dependency "rake"
|
data/lib/ib/generator.rb
CHANGED
@@ -1,76 +1,35 @@
|
|
1
|
+
require 'erb'
|
2
|
+
require 'tilt/erb'
|
3
|
+
require 'ib/generator/rendering_helper'
|
4
|
+
|
1
5
|
class IB::Generator
|
6
|
+
def initialize motion_template_type
|
7
|
+
# NOTE: motion_template_type equal to Motion::Project::App.template
|
8
|
+
# but, this class use its value for judging build platform.
|
9
|
+
@build_platform = motion_template_type
|
10
|
+
end
|
11
|
+
|
12
|
+
def absolute_template_path path
|
13
|
+
File.expand_path(File.join(File.dirname(__FILE__), path))
|
14
|
+
end
|
15
|
+
|
16
|
+
def render_stub_file path, files
|
17
|
+
template = Tilt::ERBTemplate.new(absolute_template_path(path), { :trim => '<>' })
|
18
|
+
template.render(RenderingHelper.new(@build_platform, files))
|
19
|
+
end
|
20
|
+
|
2
21
|
def write files, dest
|
3
22
|
files = IB::Parser.new.find_all(files)
|
4
|
-
|
23
|
+
|
5
24
|
FileUtils.mkpath dest
|
6
25
|
|
7
26
|
File.open("#{dest}/Stubs.h", 'w') do |f|
|
8
|
-
f.write
|
9
|
-
// Generated by IB v#{IB::VERSION} gem. Do not edit it manually
|
10
|
-
// Run `rake ib:open` to refresh
|
11
|
-
|
12
|
-
#import <Foundation/Foundation.h>
|
13
|
-
#import <CoreData/CoreData.h>
|
14
|
-
#import <UIKit/UIKit.h>
|
15
|
-
|
16
|
-
#{generate_objc(files)}
|
17
|
-
OBJC
|
27
|
+
f.write render_stub_file('generator/templates/Stubs.h.erb', files)
|
18
28
|
end
|
19
29
|
|
20
30
|
File.open("#{dest}/Stubs.m", 'w') do |f|
|
21
|
-
f.write
|
22
|
-
// Generated by IB v#{IB::VERSION} gem. Do not edit it manually
|
23
|
-
// Run `rake ib:open` to refresh
|
24
|
-
|
25
|
-
#import "Stubs.h"
|
26
|
-
|
27
|
-
#{generate_objc_impl(files)}
|
28
|
-
OBJC
|
31
|
+
f.write render_stub_file('generator/templates/Stubs.m.erb', files)
|
29
32
|
end
|
30
|
-
|
31
33
|
end
|
32
34
|
|
33
|
-
def generate_objc files
|
34
|
-
output = ""
|
35
|
-
files.map do |path, infos|
|
36
|
-
infos.each do |info|
|
37
|
-
output << <<-OBJC
|
38
|
-
@interface #{info[:class][0][0]}#{info[:class][0][1] ? ": #{info[:class][0][1]}" : ""}
|
39
|
-
|
40
|
-
#{info[:outlets].map {|name, type| "@property IBOutlet #{generate_type(type)} #{name};" }.join("\n")}
|
41
|
-
|
42
|
-
#{info[:outlet_collections].map {|name, type| "@property IBOutletCollection(#{type}) NSArray * #{name};" }.join("\n")}
|
43
|
-
|
44
|
-
#{info[:actions].map {|action| "-(IBAction) #{generate_action(action)};" }.join("\n")}
|
45
|
-
|
46
|
-
@end
|
47
|
-
OBJC
|
48
|
-
output << "\n\n"
|
49
|
-
end
|
50
|
-
end
|
51
|
-
output
|
52
|
-
end
|
53
|
-
|
54
|
-
def generate_objc_impl files
|
55
|
-
output = ""
|
56
|
-
files.map do |path, infos|
|
57
|
-
infos.each do |info|
|
58
|
-
output << <<-OBJC
|
59
|
-
@implementation #{info[:class][0][0]}
|
60
|
-
|
61
|
-
@end
|
62
|
-
OBJC
|
63
|
-
output << "\n\n"
|
64
|
-
end
|
65
|
-
end
|
66
|
-
output
|
67
|
-
end
|
68
|
-
|
69
|
-
def generate_type type
|
70
|
-
type == "id" ? type : "#{type} *"
|
71
|
-
end
|
72
|
-
|
73
|
-
def generate_action action
|
74
|
-
action[1] ? "#{action[0]}:(#{action[2] ? "#{action[2]}*" : 'id'}) #{action[1]}" : "#{action[0]}"
|
75
|
-
end
|
76
35
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module IB
|
2
|
+
class Generator
|
3
|
+
class RenderingHelper
|
4
|
+
|
5
|
+
def initialize(build_platform, files)
|
6
|
+
@build_platform = build_platform
|
7
|
+
@files = files
|
8
|
+
end
|
9
|
+
|
10
|
+
def ib_version
|
11
|
+
IB::VERSION
|
12
|
+
end
|
13
|
+
|
14
|
+
def ios_project?
|
15
|
+
@build_platform == :ios
|
16
|
+
end
|
17
|
+
|
18
|
+
def osx_project?
|
19
|
+
@build_platform == :osx
|
20
|
+
end
|
21
|
+
|
22
|
+
def generate_type type
|
23
|
+
type == "id" ? type : "#{type} *"
|
24
|
+
end
|
25
|
+
|
26
|
+
def generate_action action
|
27
|
+
action[1] ? "#{action[0]}:(#{action[2] ? "#{action[2]}*" : 'id'}) #{action[1]}" : "#{action[0]}"
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
// Generated by IB v<%= ib_version %> gem. Do not edit it manually
|
2
|
+
// Run `rake ib:open` to refresh
|
3
|
+
|
4
|
+
#import <Foundation/Foundation.h>
|
5
|
+
#import <CoreData/CoreData.h>
|
6
|
+
<% if ios_project? %>
|
7
|
+
#import <UIKit/UIKit.h>
|
8
|
+
<% elsif osx_project? %>
|
9
|
+
#import <Cocoa/Cocoa.h>
|
10
|
+
<% end %>
|
11
|
+
|
12
|
+
<% @files.map do |path, infos| %>
|
13
|
+
<% infos.each do |info| %>
|
14
|
+
@interface <%= info[:class][0][0] + (info[:class][0][1] ? ": #{info[:class][0][1]}" : "")%>
|
15
|
+
<% unless info[:outlets].empty? %><%= "\n"%><% end %>
|
16
|
+
<% info[:outlets].map do |name, type| %>
|
17
|
+
@property IBOutlet <%= generate_type(type)%> <%= name %>;
|
18
|
+
<% end %>
|
19
|
+
<% unless info[:outlets].empty? %><%= "\n"%><% end %>
|
20
|
+
<% info[:outlet_collections].map do|name, type| %>
|
21
|
+
@property IBOutletCollection(<%= type %>) NSArray * <%= name %>;
|
22
|
+
<% end %>
|
23
|
+
<% unless info[:outlet_collections].empty? %><%= "\n"%><% end %>
|
24
|
+
<% info[:actions].map do |action| %>
|
25
|
+
-(IBAction) <%= generate_action(action) %>;
|
26
|
+
<% end %>
|
27
|
+
<% unless info[:actions].empty? %><%= "\n"%><% end %>
|
28
|
+
@end
|
29
|
+
|
30
|
+
<% end; end %>
|
@@ -0,0 +1,11 @@
|
|
1
|
+
// Generated by IB v<%= ib_version %> gem. Do not edit it manually
|
2
|
+
// Run `rake ib:open` to refresh
|
3
|
+
|
4
|
+
#import "Stubs.h"
|
5
|
+
|
6
|
+
<% @files.map do |path, infos| %>
|
7
|
+
<% infos.each do |info| %>
|
8
|
+
@implementation <%= info[:class][0][0] %>
|
9
|
+
@end
|
10
|
+
|
11
|
+
<% end; end; %>
|
data/lib/ib/project.rb
CHANGED
@@ -31,7 +31,8 @@ class IB::Project
|
|
31
31
|
pods = project.new_group("Pods")
|
32
32
|
pods.path = pods_headers_path
|
33
33
|
|
34
|
-
IB::Generator.new
|
34
|
+
generator = IB::Generator.new(detect_platform)
|
35
|
+
generator.write(Motion::Project::App.config.files, ib_project)
|
35
36
|
|
36
37
|
support.new_file "ib.xcodeproj/Stubs.h"
|
37
38
|
file = support.new_file "ib.xcodeproj/Stubs.m"
|
data/lib/ib/version.rb
CHANGED
data/spec/generator_spec.rb
CHANGED
@@ -3,22 +3,25 @@ require "spec_helper"
|
|
3
3
|
require "ib/generator"
|
4
4
|
|
5
5
|
describe IB::Generator do
|
6
|
-
it "generates stubs" do
|
6
|
+
it "generates stubs header with ios platform" do
|
7
7
|
files = IB::Parser.new.find_all("spec/fixtures")
|
8
|
-
stubs = IB::Generator.new.
|
8
|
+
stubs = IB::Generator.new(:ios).render_stub_file('generator/templates/Stubs.h.erb', files)
|
9
|
+
|
9
10
|
stubs.should == <<-OBJC
|
11
|
+
// Generated by IB v#{IB::VERSION} gem. Do not edit it manually
|
12
|
+
// Run `rake ib:open` to refresh
|
13
|
+
|
14
|
+
#import <Foundation/Foundation.h>
|
15
|
+
#import <CoreData/CoreData.h>
|
16
|
+
#import <UIKit/UIKit.h>
|
17
|
+
|
10
18
|
@interface AppDelegate
|
11
19
|
|
12
20
|
@property IBOutlet UIWindow * window;
|
13
21
|
@property IBOutlet UINavigationController * navigationController;
|
14
22
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
23
|
@end
|
20
24
|
|
21
|
-
|
22
25
|
@interface CustomView: UIView
|
23
26
|
|
24
27
|
@property IBOutlet UIGreenLabel * greenLabel;
|
@@ -41,28 +44,86 @@ describe IB::Generator do
|
|
41
44
|
|
42
45
|
@end
|
43
46
|
|
44
|
-
|
45
47
|
@interface EmptyView: UIView
|
48
|
+
@end
|
49
|
+
|
50
|
+
@interface AnotherView: EmptyView
|
51
|
+
@end
|
46
52
|
|
53
|
+
OBJC
|
54
|
+
end
|
55
|
+
|
56
|
+
it "generates stubs header with osx platform" do
|
57
|
+
files = IB::Parser.new.find_all("spec/fixtures")
|
58
|
+
stubs = IB::Generator.new(:osx).render_stub_file('generator/templates/Stubs.h.erb', files)
|
59
|
+
|
60
|
+
stubs.should == <<-OBJC
|
61
|
+
// Generated by IB v#{IB::VERSION} gem. Do not edit it manually
|
62
|
+
// Run `rake ib:open` to refresh
|
63
|
+
|
64
|
+
#import <Foundation/Foundation.h>
|
65
|
+
#import <CoreData/CoreData.h>
|
66
|
+
#import <Cocoa/Cocoa.h>
|
47
67
|
|
68
|
+
@interface AppDelegate
|
69
|
+
|
70
|
+
@property IBOutlet UIWindow * window;
|
71
|
+
@property IBOutlet UINavigationController * navigationController;
|
72
|
+
|
73
|
+
@end
|
48
74
|
|
75
|
+
@interface CustomView: UIView
|
49
76
|
|
77
|
+
@property IBOutlet UIGreenLabel * greenLabel;
|
78
|
+
@property IBOutlet UILabel * redLabel;
|
79
|
+
@property IBOutlet id untyped_label;
|
80
|
+
@property IBOutlet id yellowLabel;
|
50
81
|
|
82
|
+
@property IBOutletCollection(UIGreenLabel) NSArray * greenLabelCollection;
|
83
|
+
@property IBOutletCollection(UILabel) NSArray * redLabelCollection;
|
84
|
+
@property IBOutletCollection(id) NSArray * untyped_label_collection;
|
85
|
+
@property IBOutletCollection(id) NSArray * yellowLabelCollection;
|
51
86
|
|
87
|
+
-(IBAction) someAction:(id) sender;
|
88
|
+
-(IBAction) segueAction:(UIStoryboardSegue*) sender;
|
89
|
+
-(IBAction) anotherAction:(id) button;
|
90
|
+
-(IBAction) actionWithComment:(id) sender;
|
91
|
+
-(IBAction) actionWithBrackets:(id) sender;
|
92
|
+
-(IBAction) actionWithoutArgs;
|
93
|
+
-(IBAction) actionWithDefaultedArgs:(id) sender;
|
52
94
|
|
53
95
|
@end
|
54
96
|
|
97
|
+
@interface EmptyView: UIView
|
98
|
+
@end
|
55
99
|
|
56
100
|
@interface AnotherView: EmptyView
|
101
|
+
@end
|
57
102
|
|
103
|
+
OBJC
|
104
|
+
end
|
58
105
|
|
106
|
+
it "generates stubs implement" do
|
107
|
+
files = IB::Parser.new.find_all("spec/fixtures")
|
108
|
+
stubs = IB::Generator.new(:ios).render_stub_file('generator/templates/Stubs.m.erb', files)
|
59
109
|
|
110
|
+
stubs.should == <<-OBJC
|
111
|
+
// Generated by IB v#{IB::VERSION} gem. Do not edit it manually
|
112
|
+
// Run `rake ib:open` to refresh
|
60
113
|
|
114
|
+
#import "Stubs.h"
|
61
115
|
|
116
|
+
@implementation AppDelegate
|
117
|
+
@end
|
62
118
|
|
119
|
+
@implementation CustomView
|
120
|
+
@end
|
63
121
|
|
122
|
+
@implementation EmptyView
|
64
123
|
@end
|
65
124
|
|
125
|
+
@implementation AnotherView
|
126
|
+
@end
|
66
127
|
|
67
128
|
OBJC
|
68
129
|
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.3.
|
4
|
+
version: 0.3.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yury Korolev
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-10-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: xcodeproj
|
@@ -17,14 +17,14 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - '>='
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: 0.11.
|
20
|
+
version: 0.11.1
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
25
|
- - '>='
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version: 0.11.
|
27
|
+
version: 0.11.1
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: thor
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
@@ -39,6 +39,20 @@ dependencies:
|
|
39
39
|
- - '>='
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
version: 0.15.4
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: tilt
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: 1.4.1
|
49
|
+
type: :runtime
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 1.4.1
|
42
56
|
- !ruby/object:Gem::Dependency
|
43
57
|
name: rspec
|
44
58
|
requirement: !ruby/object:Gem::Requirement
|
@@ -86,6 +100,9 @@ files:
|
|
86
100
|
- ib.gemspec
|
87
101
|
- lib/ib.rb
|
88
102
|
- lib/ib/generator.rb
|
103
|
+
- lib/ib/generator/rendering_helper.rb
|
104
|
+
- lib/ib/generator/templates/Stubs.h.erb
|
105
|
+
- lib/ib/generator/templates/Stubs.m.erb
|
89
106
|
- lib/ib/outlets.rb
|
90
107
|
- lib/ib/parser.rb
|
91
108
|
- lib/ib/project.rb
|