Class: IB::Project
- Inherits:
-
Object
- Object
- IB::Project
- Defined in:
- lib/ib/project.rb
Constant Summary collapse
- IB_PROJECT_NAME =
'ib.xcodeproj'- DEFAULT_FRAMEWORKS =
%W{QuartzCore CoreGraphics CoreData}- RESOURCE_EXTENSIONS =
%W{xcdatamodeld png jpg jpeg storyboard xib lproj}
Instance Attribute Summary collapse
-
#platform ⇒ Object
Returns the value of attribute platform.
-
#project_path ⇒ Object
Returns the value of attribute project_path.
Instance Method Summary collapse
- #add_frameworks ⇒ Object
- #add_pods ⇒ Object
- #add_resources ⇒ Object
- #app_files ⇒ Object
- #detect_platform ⇒ Object
- #generate_stub_files ⇒ Object
- #generator ⇒ Object
- #ib_project_path ⇒ Object
-
#initialize(options = {}) ⇒ Project
constructor
A new instance of Project.
- #pods ⇒ Object
- #project ⇒ Object
- #resources ⇒ Object
- #setup_paths ⇒ Object
- #support_files ⇒ Object
- #target ⇒ Object
-
#write ⇒ Object
Writes a new ib.xcodeproj to the provided ‘#project_path`.
Constructor Details
#initialize(options = {}) ⇒ Project
Returns a new instance of Project.
10 11 12 13 |
# File 'lib/ib/project.rb', line 10 def initialize ={} @platform = [:platform] || detect_platform @project_path = [:project_path] || Dir.pwd end |
Instance Attribute Details
#platform ⇒ Object
Returns the value of attribute platform.
3 4 5 |
# File 'lib/ib/project.rb', line 3 def platform @platform end |
#project_path ⇒ Object
Returns the value of attribute project_path.
4 5 6 |
# File 'lib/ib/project.rb', line 4 def project_path @project_path end |
Instance Method Details
#add_frameworks ⇒ Object
102 103 104 105 106 |
# File 'lib/ib/project.rb', line 102 def add_frameworks DEFAULT_FRAMEWORKS.each do |framework| target.add_system_framework framework end end |
#add_pods ⇒ Object
96 97 98 99 100 |
# File 'lib/ib/project.rb', line 96 def add_pods Dir.glob("#{pods.path}/**/*.h") do |file| pods.new_reference(file) end end |
#add_resources ⇒ Object
90 91 92 93 94 |
# File 'lib/ib/project.rb', line 90 def add_resources Dir.glob("#{resources.path}/**/*.{#{RESOURCE_EXTENSIONS.join(",")}}") do |file| resources.new_reference(file) end end |
#app_files ⇒ Object
70 71 72 73 74 |
# File 'lib/ib/project.rb', line 70 def app_files Motion::Project::App.config.files.select do |file| file =~ /^(\.\/)?app\// end end |
#detect_platform ⇒ Object
60 61 62 63 64 65 66 67 68 |
# File 'lib/ib/project.rb', line 60 def detect_platform # TODO: find a better way to detect platform if defined?(Motion::Project::Config) if Motion::Project::App.config.respond_to?(:platforms) return Motion::Project::App.config.platforms[0] == 'MacOSX' ? :osx : :ios end end return :ios end |
#generate_stub_files ⇒ Object
82 83 84 85 86 87 88 |
# File 'lib/ib/project.rb', line 82 def generate_stub_files generator.write(app_files, ib_project_path) support_files.new_file File.join(ib_project_path, 'Stubs.h') file = support_files.new_file File.join(ib_project_path, 'Stubs.m') target.add_file_references([ file ]) end |
#generator ⇒ Object
44 45 46 |
# File 'lib/ib/project.rb', line 44 def generator @generator ||= IB::Generator.new(detect_platform) end |
#ib_project_path ⇒ Object
108 109 110 |
# File 'lib/ib/project.rb', line 108 def ib_project_path File.join(project_path, IB_PROJECT_NAME) end |
#pods ⇒ Object
56 57 58 |
# File 'lib/ib/project.rb', line 56 def pods @pods ||= project.new_group("Pods") end |
#project ⇒ Object
36 37 38 |
# File 'lib/ib/project.rb', line 36 def project @project ||= Xcodeproj::Project.new(ib_project_path) end |
#resources ⇒ Object
48 49 50 |
# File 'lib/ib/project.rb', line 48 def resources @resources ||= project.new_group("Resources") end |
#setup_paths ⇒ Object
76 77 78 79 80 |
# File 'lib/ib/project.rb', line 76 def setup_paths resources.path = File.join(project_path, 'resources') support_files.path = File.join(project_path, IB_PROJECT_NAME) pods.path = File.join(project_path, 'vendor/Pods/Headers') end |
#support_files ⇒ Object
52 53 54 |
# File 'lib/ib/project.rb', line 52 def support_files @support_files ||= project.new_group("Supporting Files") end |
#target ⇒ Object
40 41 42 |
# File 'lib/ib/project.rb', line 40 def target @target ||= project.new_target(:static_library, 'ib', platform) end |
#write ⇒ Object
Writes a new ib.xcodeproj to the provided ‘#project_path`. The following steps will occur
-
‘setup_paths` - This step sets up the paths to your project’s ‘resources’, ‘pods’ and ‘supporting files’.
-
‘generate_stub_files` - generates stub files and adds it to the build
-
‘add_resources` - Adds all resources from your RubyMotion project
-
‘add_pods` - Adds pods (if any) to ib.xcodeproj
-
‘add_frameworks` - Adds standard frameworks to your project
-
project will then be saved
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/ib/project.rb', line 25 def write setup_paths generate_stub_files add_resources add_pods add_frameworks project.save end |