ib 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/Gemfile +7 -0
- data/LICENSE +22 -0
- data/README.md +72 -0
- data/Rakefile +2 -0
- data/ib.gemspec +21 -0
- data/lib/ib/generator.rb +38 -0
- data/lib/ib/parser.rb +38 -0
- data/lib/ib/project.rb +23 -0
- data/lib/ib/tasks.rb +13 -0
- data/lib/ib/version.rb +3 -0
- data/lib/ib.rb +10 -0
- data/spec/fixtures/custom_view.rb +9 -0
- data/spec/fixtures/empty_view.rb +2 -0
- data/spec/fixtures/simple_class.rb +2 -0
- data/spec/generator_spec.rb +29 -0
- data/spec/parser_spec.rb +20 -0
- data/spec/project_spec.rb +9 -0
- data/spec/spec_helper.rb +11 -0
- metadata +110 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Yury Korolev
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
# IB
|
2
|
+
|
3
|
+
rubymotion interface builder support (yes, with outlets)
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'ib'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install ib
|
18
|
+
|
19
|
+
In your Rake file:
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
# -*- coding: utf-8 -*-
|
23
|
+
$:.unshift("/Library/RubyMotion/lib")
|
24
|
+
require 'motion/project'
|
25
|
+
|
26
|
+
# if you use bundler
|
27
|
+
require 'bundler/setup'
|
28
|
+
Bundler.setup
|
29
|
+
|
30
|
+
# require 'ib tasks'
|
31
|
+
require 'ib/tasks'
|
32
|
+
|
33
|
+
|
34
|
+
Motion::Project::App.setup do |app|
|
35
|
+
# ...
|
36
|
+
app.files.unshift IB::PATH # add ib module
|
37
|
+
end
|
38
|
+
|
39
|
+
```
|
40
|
+
|
41
|
+
## Usage
|
42
|
+
|
43
|
+
Extend your controllers with IB module:
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
class SuperController < UIViewController
|
47
|
+
|
48
|
+
# define attribute accessor
|
49
|
+
attr_accessor title
|
50
|
+
|
51
|
+
# define ib outlet
|
52
|
+
ib_outlet :title, UILabel
|
53
|
+
|
54
|
+
# define action method
|
55
|
+
def onclick UIButton * button
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
# define ib action
|
60
|
+
ib_action :onclick
|
61
|
+
end
|
62
|
+
```
|
63
|
+
|
64
|
+
Run `rake design` create Storyboard or nibs (put them in resources folder) and you will be able to bind outlets and actions to your ruby code.
|
65
|
+
|
66
|
+
## Contributing
|
67
|
+
|
68
|
+
1. Fork it
|
69
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
70
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
71
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
72
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/ib.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/ib/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Yury Korolev"]
|
6
|
+
gem.email = ["yury.korolev@gmail.com"]
|
7
|
+
gem.description = %q{Stupid rubymotion ib outlets support}
|
8
|
+
gem.summary = %q{Small portion of love to interface builder with rubymotion}
|
9
|
+
gem.homepage = ""
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "ib"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = IB::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency "xcodeproj", ">= 0.2.3"
|
19
|
+
|
20
|
+
gem.add_development_dependency "rspec", ">= 2.0"
|
21
|
+
end
|
data/lib/ib/generator.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'ib/version'
|
3
|
+
require 'ib/parser'
|
4
|
+
require 'xcodeproj'
|
5
|
+
|
6
|
+
class IB::Generator
|
7
|
+
def write src, dest
|
8
|
+
files = IB::Parser.new.find_all(src)
|
9
|
+
|
10
|
+
FileUtils.mkpath dest
|
11
|
+
|
12
|
+
File.open("#{dest}/stubs.h", 'w') do |f|
|
13
|
+
f.write <<-OBJC
|
14
|
+
// Generated by IB v#{IB::VERSION} gem. Do not edit it manually
|
15
|
+
// Run `rake design` to refresh
|
16
|
+
|
17
|
+
#import <UIKit/UIKit.h>
|
18
|
+
|
19
|
+
#{generate_objc(files)}
|
20
|
+
OBJC
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
def generate_objc files
|
26
|
+
src = files.map do |path, info|
|
27
|
+
<<-OBJC
|
28
|
+
@interface #{info[:class][0][0]} : #{info[:class][0][1]}
|
29
|
+
|
30
|
+
#{info[:outlets].map {|name, type| "@property IBOutlet #{type} * #{name};" }.join("\n")}
|
31
|
+
|
32
|
+
#{info[:actions].map {|action| "-(IBAction) #{action[0]}:(id) sender;" }.join("\n")}
|
33
|
+
|
34
|
+
@end
|
35
|
+
OBJC
|
36
|
+
end.join("\n" * 2)
|
37
|
+
end
|
38
|
+
end
|
data/lib/ib/parser.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
class IB::Parser
|
2
|
+
def find_all(dir)
|
3
|
+
all = {}
|
4
|
+
Dir.glob("#{dir}/**/*.rb") do |file|
|
5
|
+
if info = find(file)
|
6
|
+
all[file] = info
|
7
|
+
end
|
8
|
+
end
|
9
|
+
all
|
10
|
+
end
|
11
|
+
|
12
|
+
def find(path)
|
13
|
+
src = File.read(path)
|
14
|
+
info = {class: find_class(src)}
|
15
|
+
|
16
|
+
return false if info[:class].length == 0
|
17
|
+
|
18
|
+
info[:outlets] = find_outlets(src)
|
19
|
+
|
20
|
+
info[:actions] = find_actions(src)
|
21
|
+
|
22
|
+
info[:path] = path
|
23
|
+
|
24
|
+
info
|
25
|
+
end
|
26
|
+
|
27
|
+
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]+)/
|
29
|
+
end
|
30
|
+
|
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]+)/
|
33
|
+
end
|
34
|
+
|
35
|
+
def find_actions src
|
36
|
+
src.scan /^\s+ib_action\s+:([a-zA-Z][_a-zA-Z0-9]*)/
|
37
|
+
end
|
38
|
+
end
|
data/lib/ib/project.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'ib/parser'
|
3
|
+
require 'ib/generator'
|
4
|
+
require 'xcodeproj'
|
5
|
+
|
6
|
+
class IB::Project
|
7
|
+
def write app_path = "./app", resources_path = "./resources"
|
8
|
+
project = Xcodeproj::Project.new
|
9
|
+
target = project.targets.new_static_library(:ios, 'ui')
|
10
|
+
stubs = IB::Generator.new.write(app_path, "ui.xcodeproj")
|
11
|
+
stubs_path = Pathname.new("ui.xcodeproj/stubs.h")
|
12
|
+
files = [Xcodeproj::Project::PBXNativeTarget::SourceFileDescription.new(stubs_path, nil, nil)]
|
13
|
+
|
14
|
+
|
15
|
+
Dir.glob("#{resources_path}/**/*.{png,jpg,jpeg,storyboard,xib}") do |file|
|
16
|
+
files << Xcodeproj::Project::PBXNativeTarget::SourceFileDescription.new(Pathname.new(file), nil, nil)
|
17
|
+
end
|
18
|
+
|
19
|
+
target.add_source_files(files)
|
20
|
+
|
21
|
+
project.save_as("ui.xcodeproj")
|
22
|
+
end
|
23
|
+
end
|
data/lib/ib/tasks.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require "ib"
|
2
|
+
require "ib/project"
|
3
|
+
require "rake"
|
4
|
+
|
5
|
+
desc "Generates ui.xcodeproj and open it"
|
6
|
+
task "design" do
|
7
|
+
IB::Project.new.write
|
8
|
+
system "open ui.xcodeproj"
|
9
|
+
end
|
10
|
+
|
11
|
+
module IB
|
12
|
+
PATH = File.expand_path("../ib.rb", File.dirname(__FILE__))
|
13
|
+
end
|
data/lib/ib/version.rb
ADDED
data/lib/ib.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
require "ib/generator"
|
4
|
+
|
5
|
+
describe IB::Generator do
|
6
|
+
it "generates stubs" do
|
7
|
+
files = IB::Parser.new.find_all("spec/fixtures")
|
8
|
+
stubs = IB::Generator.new.generate_objc(files)
|
9
|
+
stubs.should == <<-OBJC
|
10
|
+
@interface CustomView : UIView
|
11
|
+
|
12
|
+
@property IBOutlet UIGreenLabel * greenLabel;
|
13
|
+
@property IBOutlet UILabel * redLabel;
|
14
|
+
|
15
|
+
-(IBAction) someAction:(id) sender;
|
16
|
+
|
17
|
+
@end
|
18
|
+
|
19
|
+
|
20
|
+
@interface EmptyView : UIView
|
21
|
+
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
@end
|
27
|
+
OBJC
|
28
|
+
end
|
29
|
+
end
|
data/spec/parser_spec.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
require "ib/parser"
|
4
|
+
|
5
|
+
describe IB::Parser do
|
6
|
+
it "finds outlets and actions" do
|
7
|
+
info = IB::Parser.new.find("spec/fixtures/custom_view.rb")
|
8
|
+
info[:class].should == [["CustomView", "UIView"]]
|
9
|
+
info[:outlets].should == [["greenLabel", "UIGreenLabel"], ["redLabel", "UILabel"]]
|
10
|
+
info[:actions].should == [["someAction"]]
|
11
|
+
end
|
12
|
+
|
13
|
+
it "detects simple classes" do
|
14
|
+
IB::Parser.new.find("spec/fixtures/simple_class.rb").should == false
|
15
|
+
end
|
16
|
+
|
17
|
+
it "finds all infos" do
|
18
|
+
puts IB::Parser.new.find_all("spec/fixtures").inspect
|
19
|
+
end
|
20
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper.rb"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
RSpec.configure do |config|
|
8
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
9
|
+
config.run_all_when_everything_filtered = true
|
10
|
+
config.filter_run :focus
|
11
|
+
end
|
metadata
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ib
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Yury Korolev
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-07-11 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: xcodeproj
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.2.3
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.2.3
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '2.0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '2.0'
|
46
|
+
description: Stupid rubymotion ib outlets support
|
47
|
+
email:
|
48
|
+
- yury.korolev@gmail.com
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- .gitignore
|
54
|
+
- .rspec
|
55
|
+
- Gemfile
|
56
|
+
- LICENSE
|
57
|
+
- README.md
|
58
|
+
- Rakefile
|
59
|
+
- ib.gemspec
|
60
|
+
- lib/ib.rb
|
61
|
+
- lib/ib/generator.rb
|
62
|
+
- lib/ib/parser.rb
|
63
|
+
- lib/ib/project.rb
|
64
|
+
- lib/ib/tasks.rb
|
65
|
+
- lib/ib/version.rb
|
66
|
+
- spec/fixtures/custom_view.rb
|
67
|
+
- spec/fixtures/empty_view.rb
|
68
|
+
- spec/fixtures/simple_class.rb
|
69
|
+
- spec/generator_spec.rb
|
70
|
+
- spec/parser_spec.rb
|
71
|
+
- spec/project_spec.rb
|
72
|
+
- spec/spec_helper.rb
|
73
|
+
homepage: ''
|
74
|
+
licenses: []
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
81
|
+
requirements:
|
82
|
+
- - ! '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
segments:
|
86
|
+
- 0
|
87
|
+
hash: 1859734477769846391
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
segments:
|
95
|
+
- 0
|
96
|
+
hash: 1859734477769846391
|
97
|
+
requirements: []
|
98
|
+
rubyforge_project:
|
99
|
+
rubygems_version: 1.8.24
|
100
|
+
signing_key:
|
101
|
+
specification_version: 3
|
102
|
+
summary: Small portion of love to interface builder with rubymotion
|
103
|
+
test_files:
|
104
|
+
- spec/fixtures/custom_view.rb
|
105
|
+
- spec/fixtures/empty_view.rb
|
106
|
+
- spec/fixtures/simple_class.rb
|
107
|
+
- spec/generator_spec.rb
|
108
|
+
- spec/parser_spec.rb
|
109
|
+
- spec/project_spec.rb
|
110
|
+
- spec/spec_helper.rb
|