ib 0.0.3 → 0.0.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 +26 -15
- data/bin/ib +63 -0
- data/ib.gemspec +3 -2
- data/lib/ib/project.rb +26 -8
- data/lib/ib/version.rb +1 -1
- data/template/controller.erb +24 -0
- data/template/controller_helper.erb +2 -0
- data/template/controller_spec.erb +8 -0
- metadata +28 -5
data/README.md
CHANGED
@@ -19,9 +19,9 @@ Or install it yourself as:
|
|
19
19
|
In your Rake file:
|
20
20
|
|
21
21
|
```ruby
|
22
|
-
|
23
|
-
$:.unshift("/Library/RubyMotion/lib")
|
24
|
-
require 'motion/project'
|
22
|
+
|
23
|
+
$:.unshift("/Library/RubyMotion/lib")
|
24
|
+
require 'motion/project'
|
25
25
|
|
26
26
|
# if you use bundler
|
27
27
|
require 'bundler'
|
@@ -39,26 +39,37 @@ end
|
|
39
39
|
|
40
40
|
## Usage
|
41
41
|
|
42
|
-
|
42
|
+
Generate controller with folllowing command:
|
43
43
|
|
44
|
-
```
|
45
|
-
|
44
|
+
```
|
45
|
+
ib c Hello UIViewController \
|
46
|
+
--outlets scroller:UIScrollView btn_hello:UIButton \
|
47
|
+
--actions say_hello \
|
48
|
+
--accessors data_source
|
49
|
+
```
|
46
50
|
|
51
|
+
The generated file:
|
52
|
+
|
53
|
+
#### /app/controllers/hello_controller.rb
|
54
|
+
```ruby
|
55
|
+
class HelloController < UIViewController
|
47
56
|
extend IB
|
48
57
|
|
49
|
-
|
50
|
-
attr_accessor
|
58
|
+
## define accessors
|
59
|
+
attr_accessor :data_source, :scroller, :htn_hello
|
51
60
|
|
52
|
-
|
53
|
-
ib_outlet :
|
61
|
+
## define ib outlets
|
62
|
+
ib_outlet :scroller, UIScrollView
|
63
|
+
ib_outlet :btn_hello, UIButton
|
54
64
|
|
55
|
-
|
56
|
-
def
|
57
|
-
|
65
|
+
## define actions
|
66
|
+
def say_hello(sender)
|
67
|
+
# TODO Implement action here
|
58
68
|
end
|
59
69
|
|
60
|
-
|
61
|
-
ib_action :
|
70
|
+
## define ib action
|
71
|
+
ib_action :say_hello
|
72
|
+
|
62
73
|
end
|
63
74
|
```
|
64
75
|
|
data/bin/ib
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require "rubygems"
|
3
|
+
|
4
|
+
require "thor"
|
5
|
+
require "thor/group"
|
6
|
+
require 'thor/rake_compat'
|
7
|
+
|
8
|
+
module IB
|
9
|
+
class ControllerGenerator < Thor
|
10
|
+
include Thor::Actions
|
11
|
+
include Thor::RakeCompat
|
12
|
+
|
13
|
+
map "c" => :controller
|
14
|
+
|
15
|
+
def self.source_root
|
16
|
+
File.dirname(__FILE__)
|
17
|
+
end
|
18
|
+
|
19
|
+
desc "controller", "generate controller"
|
20
|
+
argument :name, :type => :string, :desc => "Name of the controller"
|
21
|
+
argument :controller_type, :type => :string, :desc => "Type of the controller, default: UIViewController", :default => "UIViewController"
|
22
|
+
class_option :outlets, :type => :hash, :default => {}, :required => false, :desc => "IBOutlets of the controller"
|
23
|
+
class_option :actions, :type => :array, :default => [], :required => false, :desc => "IBAtions of the controller"
|
24
|
+
class_option :accessors, :type => :array, :default => [], :required => false, :desc => "Accessors of the controller"
|
25
|
+
def controller
|
26
|
+
create_controller_file
|
27
|
+
create_helper_file
|
28
|
+
create_spec_file
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
def create_controller_file
|
33
|
+
template('../template/controller.erb', "app/controllers/#{underscore(name)}_controller.rb")
|
34
|
+
end
|
35
|
+
|
36
|
+
def create_helper_file
|
37
|
+
template('../template/controller_helper.erb', "app/helpers/#{underscore(name)}_helper.rb")
|
38
|
+
end
|
39
|
+
|
40
|
+
def create_spec_file
|
41
|
+
template('../template/controller_spec.erb', "spec/controllers/#{underscore(name)}_controller_spec.rb")
|
42
|
+
end
|
43
|
+
|
44
|
+
def controller_name
|
45
|
+
camelize("#{name}Controller")
|
46
|
+
end
|
47
|
+
|
48
|
+
def underscore(string)
|
49
|
+
string.gsub(/::/, '/').
|
50
|
+
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
51
|
+
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
52
|
+
tr("-", "_").
|
53
|
+
downcase
|
54
|
+
end
|
55
|
+
|
56
|
+
def camelize(string)
|
57
|
+
return string if string !~ /_/ && string =~ /[A-Z]+.*/
|
58
|
+
string.split('_').map{|e| e.capitalize }.join
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
IB::ControllerGenerator.start
|
data/ib.gemspec
CHANGED
@@ -2,8 +2,8 @@
|
|
2
2
|
require File.expand_path('../lib/ib/version', __FILE__)
|
3
3
|
|
4
4
|
Gem::Specification.new do |gem|
|
5
|
-
gem.authors = ["Yury Korolev"]
|
6
|
-
gem.email = ["yury.korolev@gmail.com"]
|
5
|
+
gem.authors = ["Yury Korolev", "Francis Chong"]
|
6
|
+
gem.email = ["yury.korolev@gmail.com", "francis@ignition.hk"]
|
7
7
|
gem.description = %q{Stupid rubymotion ib outlets support}
|
8
8
|
gem.summary = %q{Small portion of love to interface builder with rubymotion}
|
9
9
|
gem.homepage = ""
|
@@ -16,6 +16,7 @@ Gem::Specification.new do |gem|
|
|
16
16
|
gem.version = IB::VERSION
|
17
17
|
|
18
18
|
gem.add_dependency "xcodeproj", ">= 0.2.3"
|
19
|
+
gem.add_dependency "thor", "~> 0.15.4"
|
19
20
|
|
20
21
|
gem.add_development_dependency "rspec", ">= 2.0"
|
21
22
|
end
|
data/lib/ib/project.rb
CHANGED
@@ -1,17 +1,35 @@
|
|
1
1
|
class IB::Project
|
2
|
-
def write app_path = "
|
2
|
+
def write app_path = "app", resources_path = "resources", pods_headers_path = "vendor/Pods/Headers"
|
3
3
|
project = Xcodeproj::Project.new
|
4
4
|
target = project.targets.new_static_library(:ios, 'ui')
|
5
|
-
stubs = IB::Generator.new.write(app_path, "ui.xcodeproj")
|
6
|
-
stubs_path = Pathname.new("ui.xcodeproj/stubs.h")
|
7
|
-
files = [Xcodeproj::Project::PBXNativeTarget::SourceFileDescription.new(stubs_path, nil, nil)]
|
8
|
-
|
9
5
|
|
10
|
-
|
11
|
-
|
6
|
+
resources = project.groups.new('path' => resources_path, 'name' => 'Resources')
|
7
|
+
support = project.groups.new('name' => 'Supporting Files')
|
8
|
+
pods = project.groups.new('name' => 'Pods')
|
9
|
+
|
10
|
+
stubs_path = "ui.xcodeproj/stubs.h"
|
11
|
+
IB::Generator.new.write(app_path, "ui.xcodeproj")
|
12
|
+
support.files.new 'path' => stubs_path
|
13
|
+
|
14
|
+
resource_exts = %W{xcdatamodeld png jpg jpeg storyboard xib lproj}
|
15
|
+
Dir.glob("#{resources_path}/**/*.{#{resource_exts.join(",")}}") do |file|
|
16
|
+
resources.files.new('path' => file)
|
17
|
+
end
|
18
|
+
|
19
|
+
Dir.glob("#{pods_headers_path}/**/*.h") do |file|
|
20
|
+
pods.files.new('path' => file)
|
21
|
+
end
|
22
|
+
|
23
|
+
# Add Basic System Frameworks
|
24
|
+
# frameworks = ["UIKit", "QuartzCore", "CoreGraphics", "CoreData"]
|
25
|
+
# doesn't work with UIKit
|
26
|
+
|
27
|
+
frameworks = ["QuartzCore", "CoreGraphics", "CoreData"]
|
28
|
+
frameworks.each do |framework|
|
29
|
+
file = project.add_system_framework framework
|
30
|
+
target.frameworks_build_phases.first << file
|
12
31
|
end
|
13
32
|
|
14
|
-
target.add_source_files(files)
|
15
33
|
|
16
34
|
project.save_as("ui.xcodeproj")
|
17
35
|
end
|
data/lib/ib/version.rb
CHANGED
@@ -0,0 +1,24 @@
|
|
1
|
+
class <%= controller_name %> < <%= controller_type %>
|
2
|
+
extend IB
|
3
|
+
|
4
|
+
## define accessors
|
5
|
+
attr_accessor <%= (options[:accessors] + options[:outlets].keys).collect{|acc| ":#{acc}"}.join(", ") %>
|
6
|
+
|
7
|
+
## define ib outlets
|
8
|
+
<% options[:outlets].each do |name, type| -%>
|
9
|
+
ib_outlet :<%= name %>, <%= type %>
|
10
|
+
<% end -%>
|
11
|
+
|
12
|
+
## define actions
|
13
|
+
<% options[:actions].each do |action| -%>
|
14
|
+
def <%= action %>(sender)
|
15
|
+
# TODO Implement action here
|
16
|
+
end
|
17
|
+
<% end -%>
|
18
|
+
|
19
|
+
## define ib action
|
20
|
+
<% options[:actions].each do |action| -%>
|
21
|
+
ib_action :<%= action %>
|
22
|
+
<% end -%>
|
23
|
+
|
24
|
+
end
|
metadata
CHANGED
@@ -1,15 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Yury Korolev
|
9
|
+
- Francis Chong
|
9
10
|
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
|
-
date: 2012-07-
|
13
|
+
date: 2012-07-13 00:00:00.000000000 Z
|
13
14
|
dependencies:
|
14
15
|
- !ruby/object:Gem::Dependency
|
15
16
|
name: xcodeproj
|
@@ -27,6 +28,22 @@ dependencies:
|
|
27
28
|
- - ! '>='
|
28
29
|
- !ruby/object:Gem::Version
|
29
30
|
version: 0.2.3
|
31
|
+
- !ruby/object:Gem::Dependency
|
32
|
+
name: thor
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
35
|
+
requirements:
|
36
|
+
- - ~>
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: 0.15.4
|
39
|
+
type: :runtime
|
40
|
+
prerelease: false
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ~>
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 0.15.4
|
30
47
|
- !ruby/object:Gem::Dependency
|
31
48
|
name: rspec
|
32
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -46,7 +63,9 @@ dependencies:
|
|
46
63
|
description: Stupid rubymotion ib outlets support
|
47
64
|
email:
|
48
65
|
- yury.korolev@gmail.com
|
49
|
-
|
66
|
+
- francis@ignition.hk
|
67
|
+
executables:
|
68
|
+
- ib
|
50
69
|
extensions: []
|
51
70
|
extra_rdoc_files: []
|
52
71
|
files:
|
@@ -56,6 +75,7 @@ files:
|
|
56
75
|
- LICENSE
|
57
76
|
- README.md
|
58
77
|
- Rakefile
|
78
|
+
- bin/ib
|
59
79
|
- ib.gemspec
|
60
80
|
- lib/ib.rb
|
61
81
|
- lib/ib/generator.rb
|
@@ -71,6 +91,9 @@ files:
|
|
71
91
|
- spec/parser_spec.rb
|
72
92
|
- spec/project_spec.rb
|
73
93
|
- spec/spec_helper.rb
|
94
|
+
- template/controller.erb
|
95
|
+
- template/controller_helper.erb
|
96
|
+
- template/controller_spec.erb
|
74
97
|
homepage: ''
|
75
98
|
licenses: []
|
76
99
|
post_install_message:
|
@@ -85,7 +108,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
85
108
|
version: '0'
|
86
109
|
segments:
|
87
110
|
- 0
|
88
|
-
hash: -
|
111
|
+
hash: -3368252777998978159
|
89
112
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
113
|
none: false
|
91
114
|
requirements:
|
@@ -94,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
94
117
|
version: '0'
|
95
118
|
segments:
|
96
119
|
- 0
|
97
|
-
hash: -
|
120
|
+
hash: -3368252777998978159
|
98
121
|
requirements: []
|
99
122
|
rubyforge_project:
|
100
123
|
rubygems_version: 1.8.24
|