ib 0.3.5 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1e9c82fc607ab9a37e14ad18ebf69c2fecc0e256
4
- data.tar.gz: 153e219a271e45ee4a78fe841c57b6bb82d62c0f
3
+ metadata.gz: 1eea4e011091e08436b55716cc61bb6f9bb6fa1b
4
+ data.tar.gz: 5295da9a7c934346ec69f3af30cfcab2fd81b70c
5
5
  SHA512:
6
- metadata.gz: 84f6f138dc29230e26161f3ca09439fd6936520ceae59e8e672890db37415c18b50ed2d69dae2a5b47d6641ab71304e66d355da176e035d52835ebaf6ea6b58c
7
- data.tar.gz: 323138c6ef452527eb72c2f7260f0e844f1b5953aed1da529f9a2d8e19e2916e7ff70e542721794ef13e7263a5835bcc4dd2a0f4d328ba08fcb58c62b9cf3f8f
6
+ metadata.gz: a1c760308f730307b0be44476244016190da663eacac8d5811cb64e351b7dc1ced20cfd85f86c3c2de7a54972548072eff7726cab9d0defe67b5bca5359cfbf6
7
+ data.tar.gz: 74d07a792b9a2ae8d3ea8a4e672604598048206c64e28112173e81c89fc2923c37ac63cc040dd1060a8be44212c70e63bfb54d223eb04970a1fb870868883841
@@ -0,0 +1,7 @@
1
+ # cite from https://github.com/CocoaPods/Xcodeproj/blob/master/.travis.yml
2
+ language: objective-c
3
+ env:
4
+ - RVM_RUBY_VERSION=ruby-1.9.3-p392 NOEXEC_DISABLE=1 CI=true RUBY_VERSION_SPECIFIC='sudo ln -s /usr/bin/llvm-gcc-4.2 /usr/bin/gcc-4.2 && curl http://curl.haxx.se/ca/cacert.pem -o /usr/local/share/cacert.pem' SSL_CERT_FILE=/usr/local/share/cacert.pem
5
+ before_install: source ~/.rvm/scripts/rvm && rvm use $RVM_RUBY_VERSION
6
+ install: eval $RUBY_VERSION_SPECIFIC && rake bootstrap[use_bundle_dir]
7
+ script: bundle exec rake spec
data/README.md CHANGED
@@ -3,6 +3,7 @@
3
3
  RubyMotion interface builder support (yes, with outlets)
4
4
 
5
5
  <a href='http://spellhub.com/projects/project/7'><img src="http://spellhub.com/projects/status/7" height="18"></a>
6
+ [![Build Status](https://travis-ci.org/yury/ib.png)](https://travis-ci.org/yury/ib)
6
7
 
7
8
  [**Change Log**](https://github.com/yury/ib/wiki/Change-Log)
8
9
 
data/Rakefile CHANGED
@@ -1,2 +1,30 @@
1
1
  #!/usr/bin/env rake
2
2
  require "bundler/gem_tasks"
3
+
4
+ # Travis support
5
+ # cite from https://github.com/CocoaPods/Xcodeproj/blob/master/Rakefile
6
+ def on_rvm?
7
+ `which ruby`.strip.include?('.rvm')
8
+ end
9
+
10
+ def rvm_ruby_dir
11
+ @rvm_ruby_dir ||= File.expand_path('../..', `which ruby`.strip)
12
+ end
13
+
14
+ desc 'Install dependencies'
15
+ task :bootstrap, :use_bundle_dir? do |t, args|
16
+ options = []
17
+ options << "--without=documentation"
18
+ options << "--path ./travis_bundle_dir" if args[:use_bundle_dir?]
19
+ sh "bundle install #{options * ' '}"
20
+ end
21
+
22
+ begin
23
+ require 'rspec/core/rake_task'
24
+
25
+ RSpec::Core::RakeTask.new(:spec) do |spec|
26
+ spec.pattern = 'spec/**/*_spec.rb'
27
+ spec.rspec_opts = ['-cfs']
28
+ end
29
+ rescue LoadError => e
30
+ end
@@ -0,0 +1,83 @@
1
+ require 'tsort'
2
+
3
+ module IB
4
+ class DependencyResolver
5
+
6
+ class TSortHash < ::Hash
7
+ include TSort
8
+
9
+ alias tsort_each_node each_key
10
+
11
+ def tsort_each_child(node, &block)
12
+ fetch(node).each(&block)
13
+ end
14
+ end
15
+
16
+ attr_reader :class_nodes, :files
17
+
18
+ def initialize(files)
19
+ @files = files
20
+ @class_nodes = struct_class_node
21
+ end
22
+
23
+ def sort_classes
24
+ @class_nodes.tsort
25
+ end
26
+
27
+ def sort_files
28
+ sort_classes.map do |klass|
29
+ files.select do |file, class_definitions|
30
+ has_class_in_file?(klass, class_definitions)
31
+ end.first
32
+ end.map do |file, _|
33
+ file
34
+ end.uniq.compact
35
+ end
36
+
37
+ def sort
38
+ sorted_files = {}
39
+ sort_files.each do |file|
40
+ sorted_files.store(file, @files[file])
41
+ end
42
+ sorted_files
43
+ end
44
+
45
+ private
46
+ def has_class_in_file?(klass, class_definitions)
47
+ !class_definitions.select do |x|
48
+ x[:class][0][0] == klass
49
+ end.empty?
50
+ end
51
+
52
+ def has_super_class?(class_definition)
53
+ class_definition[:class][0].size == 2
54
+ end
55
+
56
+ def struct_class_node
57
+ list_of_hash = @files.map do |file, class_definitions|
58
+ class_definitions.map do |class_definition| create_node(class_definition) end
59
+ end.flatten
60
+
61
+ list_of_hash.inject(TSortHash.new) do |sum, x|
62
+ sum.merge!(x)
63
+ end
64
+ end
65
+
66
+ def create_node(class_definition)
67
+ has_super_class?(class_definition) ?
68
+ node_with_super_class(class_definition):
69
+ node_without_super_class(class_definition)
70
+ end
71
+
72
+ def node_with_super_class(class_definition)
73
+ {
74
+ class_definition[:class][0][0] => [class_definition[:class][0][1]],
75
+ class_definition[:class][0][1] => [],
76
+ }
77
+ end
78
+
79
+ def node_without_super_class(class_definition)
80
+ { class_definition[:class][0][0] => [] }
81
+ end
82
+ end
83
+ end
@@ -1,3 +1,5 @@
1
+ require 'ib/dependency_resolver'
2
+
1
3
  class IB::Parser
2
4
  NAME_REGEX = /[a-zA-Z][_a-zA-Z0-9]*/
3
5
  CLASS_REGEX = /^[ \t]*class[ \t]+(#{NAME_REGEX})([ \t]*<[ \t]*(#{NAME_REGEX}))?/
@@ -23,7 +25,8 @@ class IB::Parser
23
25
  all[file] = infos
24
26
  end
25
27
  end
26
- all
28
+
29
+ IB::DependencyResolver.new(all).sort
27
30
  end
28
31
 
29
32
  def find(path)
@@ -17,6 +17,12 @@ class IB::Project
17
17
  end
18
18
  end
19
19
 
20
+ def app_files
21
+ Motion::Project::App.config.files.select do |file|
22
+ file =~ /^(\.\/)?app\//
23
+ end
24
+ end
25
+
20
26
  def write
21
27
  ib_project = "ib.xcodeproj"
22
28
  project = Xcodeproj::Project.new(ib_project)
@@ -32,7 +38,7 @@ class IB::Project
32
38
  pods.path = pods_headers_path
33
39
 
34
40
  generator = IB::Generator.new(detect_platform)
35
- generator.write(Motion::Project::App.config.files, ib_project)
41
+ generator.write(app_files, ib_project)
36
42
 
37
43
  support.new_file "ib.xcodeproj/Stubs.h"
38
44
  file = support.new_file "ib.xcodeproj/Stubs.m"
@@ -1,3 +1,3 @@
1
1
  module IB
2
- VERSION = '0.3.5'
2
+ VERSION = '0.4.0'
3
3
  end
@@ -0,0 +1,2 @@
1
+ class SubClass1 < SubClass2
2
+ end
@@ -0,0 +1,2 @@
1
+ class SubClass2 < SuperClass
2
+ end
@@ -0,0 +1,2 @@
1
+ class SuperClass < UIViewController
2
+ end
@@ -0,0 +1,113 @@
1
+ require 'spec_helper'
2
+ require 'ib/dependency_resolver'
3
+
4
+ describe IB::DependencyResolver do
5
+ context 'init with simple dependency' do
6
+ before do
7
+ @files = {
8
+ 'aaa.rb' => [{
9
+ class: [['SubClass1', 'SubClass2']],
10
+ }],
11
+ 'bbb.rb' => [{
12
+ class: [['SubClass2', 'SuperClass']],
13
+ }],
14
+ 'ccc.rb' => [{
15
+ class: [['SuperClass', 'UIViewController']],
16
+ }],
17
+ }
18
+ end
19
+
20
+ describe 'new' do
21
+ it 'create a instance IB::DependencyResolver' do
22
+ resolver = IB::DependencyResolver.new(@files)
23
+ expect(
24
+ resolver.class_nodes.kind_of?(IB::DependencyResolver::TSortHash)
25
+ ).to be_true
26
+ end
27
+ end
28
+
29
+ describe 'sort_classes' do
30
+ it 'create a instance IB::DependencyResolver' do
31
+ resolver = IB::DependencyResolver.new(@files)
32
+ expect(
33
+ resolver.sort_classes
34
+ ).to eq(['UIViewController', 'SuperClass', 'SubClass2', 'SubClass1'])
35
+ end
36
+ end
37
+
38
+ describe 'sort_files' do
39
+ it 'create a instance IB::DependencyResolver' do
40
+ resolver = IB::DependencyResolver.new(@files)
41
+ expect(
42
+ resolver.sort_files
43
+ ).to eq(['ccc.rb', 'bbb.rb', 'aaa.rb'])
44
+ end
45
+ end
46
+ end
47
+
48
+ context 'init with no dependencies' do
49
+ before do
50
+ @files = {
51
+ 'aaa.rb' => [{
52
+ class: [['SubClass1']],
53
+ }],
54
+ 'bbb.rb' => [{
55
+ class: [['SubClass2']],
56
+ }],
57
+ 'ccc.rb' => [{
58
+ class: [['SuperClass']],
59
+ }],
60
+ }
61
+ end
62
+
63
+ describe 'sort_classes' do
64
+ it 'create a instance IB::DependencyResolver' do
65
+ resolver = IB::DependencyResolver.new(@files)
66
+ expect(
67
+ resolver.sort_classes
68
+ ).to eq(['SubClass1', 'SubClass2', 'SuperClass'])
69
+ end
70
+ end
71
+
72
+ describe 'sort_files' do
73
+ it 'create a instance IB::DependencyResolver' do
74
+ resolver = IB::DependencyResolver.new(@files)
75
+ expect(
76
+ resolver.sort_files
77
+ ).to eq(['aaa.rb', 'bbb.rb', 'ccc.rb'])
78
+ end
79
+ end
80
+ end
81
+
82
+ context 'init with dependency in one file' do
83
+ before do
84
+ @files = {
85
+ 'aaa.rb' => [{
86
+ class: [['SubClass1', 'SubClass2']],
87
+ },{
88
+ class: [['SubClass2', 'SuperClass']],
89
+ },{
90
+ class: [['SuperClass']],
91
+ }]
92
+ }
93
+ end
94
+
95
+ describe 'sort_classes' do
96
+ it 'create a instance IB::DependencyResolver' do
97
+ resolver = IB::DependencyResolver.new(@files)
98
+ expect(
99
+ resolver.sort_classes
100
+ ).to eq(['SuperClass', 'SubClass2', 'SubClass1'])
101
+ end
102
+ end
103
+
104
+ describe 'sort_files' do
105
+ it 'create a instance IB::DependencyResolver' do
106
+ resolver = IB::DependencyResolver.new(@files)
107
+ expect(
108
+ resolver.sort_files
109
+ ).to eq(['aaa.rb'])
110
+ end
111
+ end
112
+ end
113
+ end
@@ -4,7 +4,7 @@ require "ib/generator"
4
4
 
5
5
  describe IB::Generator do
6
6
  it "generates stubs header with ios platform" do
7
- files = IB::Parser.new.find_all("spec/fixtures")
7
+ files = IB::Parser.new.find_all("spec/fixtures/common")
8
8
  stubs = IB::Generator.new(:ios).render_stub_file('generator/templates/Stubs.h.erb', files)
9
9
 
10
10
  stubs.should == <<-OBJC
@@ -54,7 +54,7 @@ OBJC
54
54
  end
55
55
 
56
56
  it "generates stubs header with osx platform" do
57
- files = IB::Parser.new.find_all("spec/fixtures")
57
+ files = IB::Parser.new.find_all("spec/fixtures/common")
58
58
  stubs = IB::Generator.new(:osx).render_stub_file('generator/templates/Stubs.h.erb', files)
59
59
 
60
60
  stubs.should == <<-OBJC
@@ -104,7 +104,8 @@ OBJC
104
104
  end
105
105
 
106
106
  it "generates stubs implement" do
107
- files = IB::Parser.new.find_all("spec/fixtures")
107
+ files = IB::Parser.new.find_all("spec/fixtures/common")
108
+
108
109
  stubs = IB::Generator.new(:ios).render_stub_file('generator/templates/Stubs.m.erb', files)
109
110
 
110
111
  stubs.should == <<-OBJC
@@ -4,7 +4,7 @@ require "ib/parser"
4
4
 
5
5
  describe IB::Parser do
6
6
  it "finds outlets and actions" do
7
- info = IB::Parser.new.find("spec/fixtures/custom_view.rb").first
7
+ info = IB::Parser.new.find("spec/fixtures/common/custom_view.rb").first
8
8
  info[:class].should == [["CustomView", "UIView"]]
9
9
  info[:outlets].should == [
10
10
  ["greenLabel", "UIGreenLabel"],
@@ -30,10 +30,16 @@ describe IB::Parser do
30
30
  end
31
31
 
32
32
  it "detects simple classes" do
33
- IB::Parser.new.find("spec/fixtures/simple_class.rb").length.should == 0
33
+ IB::Parser.new.find("spec/fixtures/common/simple_class.rb").length.should == 0
34
34
  end
35
35
 
36
36
  it "finds all infos" do
37
- puts IB::Parser.new.find_all("spec/fixtures").inspect
37
+ infos = IB::Parser.new.find_all("spec/fixtures/dependency_test")
38
+ expect(infos.size).to eq 3
39
+ end
40
+
41
+ it "finds all sorted infos" do
42
+ infos = IB::Parser.new.find_all("spec/fixtures/dependency_test")
43
+ expect(infos.size).to eq 3
38
44
  end
39
45
  end
@@ -0,0 +1,23 @@
1
+ require "spec_helper"
2
+
3
+ require "ib/project"
4
+
5
+ describe IB::Project do
6
+ it "generates xcode project" do
7
+ IB::Project.new(app_path:"spec/fixtures/common").write()
8
+ end
9
+
10
+ it "app_files" do
11
+ Motion::Project::App.config.stub('files').and_return(
12
+ [
13
+ '/usr/local/xxx/gems/xxx/lib/xxxx.rb',
14
+ 'User/xxx/gems/xxx/lib/motion/xxxx.rb',
15
+ './app/aaa.rb',
16
+ './app/controllers/bbb.rb',
17
+ ]
18
+ )
19
+ expect(IB::Project.new(app_path:"spec/fixtures/common").app_files).to eq(
20
+ ['./app/aaa.rb', './app/controllers/bbb.rb',]
21
+ )
22
+ end
23
+ 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.5
4
+ version: 0.4.0
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-10-01 00:00:00.000000000 Z
12
+ date: 2013-10-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: xcodeproj
@@ -92,6 +92,7 @@ extra_rdoc_files: []
92
92
  files:
93
93
  - .gitignore
94
94
  - .rspec
95
+ - .travis.yml
95
96
  - Gemfile
96
97
  - LICENSE
97
98
  - README.md
@@ -99,6 +100,7 @@ files:
99
100
  - bin/ib
100
101
  - ib.gemspec
101
102
  - lib/ib.rb
103
+ - lib/ib/dependency_resolver.rb
102
104
  - lib/ib/generator.rb
103
105
  - lib/ib/generator/rendering_helper.rb
104
106
  - lib/ib/generator/templates/Stubs.h.erb
@@ -108,13 +110,17 @@ files:
108
110
  - lib/ib/project.rb
109
111
  - lib/ib/tasks.rb
110
112
  - lib/ib/version.rb
111
- - spec/fixtures/app_delegate.rb
112
- - spec/fixtures/custom_view.rb
113
- - spec/fixtures/empty_view.rb
114
- - spec/fixtures/simple_class.rb
115
- - spec/generator_spec.rb
116
- - spec/parser_spec.rb
117
- - spec/project_spec.rb
113
+ - spec/fixtures/common/app_delegate.rb
114
+ - spec/fixtures/common/custom_view.rb
115
+ - spec/fixtures/common/empty_view.rb
116
+ - spec/fixtures/common/simple_class.rb
117
+ - spec/fixtures/dependency_test/sub_class_1.rb
118
+ - spec/fixtures/dependency_test/sub_class_2.rb
119
+ - spec/fixtures/dependency_test/super_class.rb
120
+ - spec/lib/ib/dependency_resolver_spec.rb
121
+ - spec/lib/ib/generator_spec.rb
122
+ - spec/lib/ib/parser_spec.rb
123
+ - spec/lib/ib/project_spec.rb
118
124
  - spec/spec_helper.rb
119
125
  - template/controller.erb
120
126
  - template/controller_helper.erb
@@ -143,11 +149,15 @@ signing_key:
143
149
  specification_version: 4
144
150
  summary: Small portion of love to interface builder with rubymotion
145
151
  test_files:
146
- - spec/fixtures/app_delegate.rb
147
- - spec/fixtures/custom_view.rb
148
- - spec/fixtures/empty_view.rb
149
- - spec/fixtures/simple_class.rb
150
- - spec/generator_spec.rb
151
- - spec/parser_spec.rb
152
- - spec/project_spec.rb
152
+ - spec/fixtures/common/app_delegate.rb
153
+ - spec/fixtures/common/custom_view.rb
154
+ - spec/fixtures/common/empty_view.rb
155
+ - spec/fixtures/common/simple_class.rb
156
+ - spec/fixtures/dependency_test/sub_class_1.rb
157
+ - spec/fixtures/dependency_test/sub_class_2.rb
158
+ - spec/fixtures/dependency_test/super_class.rb
159
+ - spec/lib/ib/dependency_resolver_spec.rb
160
+ - spec/lib/ib/generator_spec.rb
161
+ - spec/lib/ib/parser_spec.rb
162
+ - spec/lib/ib/project_spec.rb
153
163
  - spec/spec_helper.rb
@@ -1,9 +0,0 @@
1
- require "spec_helper"
2
-
3
- require "ib/project"
4
-
5
- describe IB::Project do
6
- it "generates xcode project" do
7
- IB::Project.new(app_path:"spec/fixtures").write()
8
- end
9
- end