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 ttf otf }
Instance Attribute Summary collapse
-
#app_files ⇒ Object
Returns the value of attribute app_files.
-
#platform ⇒ Object
Returns the value of attribute platform.
-
#project_path ⇒ Object
Returns the value of attribute project_path.
-
#resource_directories ⇒ Object
Returns the value of attribute resource_directories.
Instance Method Summary collapse
- #add_extra_framework(framework) ⇒ Object
- #add_frameworks ⇒ Object
- #add_pods ⇒ Object
- #add_resources ⇒ Object
- #extra_frameworks ⇒ 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.
14 15 16 17 |
# File 'lib/ib/project.rb', line 14 def initialize(={}) @platform = [:platform] @project_path = [:project_path] || Dir.pwd end |
Instance Attribute Details
#app_files ⇒ Object
Returns the value of attribute app_files.
5 6 7 |
# File 'lib/ib/project.rb', line 5 def app_files @app_files end |
#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 |
#resource_directories ⇒ Object
Returns the value of attribute resource_directories.
6 7 8 |
# File 'lib/ib/project.rb', line 6 def resource_directories @resource_directories end |
Instance Method Details
#add_extra_framework(framework) ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/ib/project.rb', line 134 def add_extra_framework(framework) deployment_target = Motion::Project::App.config.deployment_target framework_name = framework.path.split('/').last framework_group = project.new_group(framework_name) framework_group.path = File.join(project_path, framework.path) framework_target = project.new_target( :framework, framework_name, platform, deployment_target) Dir.glob("#{framework.path}/**/*.{h,m}") do |file| file_ref = framework_group.new_file File.join(project_path, file) framework_target.add_file_references([file_ref]) end end |
#add_frameworks ⇒ Object
122 123 124 125 126 127 128 |
# File 'lib/ib/project.rb', line 122 def add_frameworks DEFAULT_FRAMEWORKS.each do |framework| target.add_system_framework framework end extra_frameworks.each { |framework| add_extra_framework framework } end |
#add_pods ⇒ Object
116 117 118 119 120 |
# File 'lib/ib/project.rb', line 116 def add_pods Dir.glob("#{pods.path}/**/*.h") do |file| pods.new_reference(file) end end |
#add_resources ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/ib/project.rb', line 96 def add_resources resource_directories.each do |dir| resourcespath = Pathname.new dir group = resources.new_group(File.basename(dir), dir) # First add reference to any asset catalogs. Dir.glob(File.join(dir, "**/*.xcassets")) do |file| group.new_reference(File.basename(file)) end # Add all other resources, ignoring files in existing asset catalogs Dir.glob(File.join(dir, "**/*.{#{RESOURCE_EXTENSIONS.join(",")}}")) .reject {|f| f[%r{.*\.xcassets/.*}] }.each do |file| filepath = Pathname.new file location = filepath.relative_path_from(resourcespath).to_s group.new_reference(location) end end end |
#extra_frameworks ⇒ Object
130 131 132 |
# File 'lib/ib/project.rb', line 130 def extra_frameworks Motion::Project::App.config.vendor_projects.select { |vp| vp.opts[:ib] } end |
#generate_stub_files ⇒ Object
88 89 90 91 92 93 94 |
# File 'lib/ib/project.rb', line 88 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
67 68 69 |
# File 'lib/ib/project.rb', line 67 def generator @generator ||= IB::Generator.new(platform) end |
#ib_project_path ⇒ Object
148 149 150 |
# File 'lib/ib/project.rb', line 148 def ib_project_path File.join(project_path, IB_PROJECT_NAME) end |
#pods ⇒ Object
79 80 81 |
# File 'lib/ib/project.rb', line 79 def pods @pods ||= project.new_group("Pods") end |
#project ⇒ Object
59 60 61 |
# File 'lib/ib/project.rb', line 59 def project @project ||= Xcodeproj::Project.new(ib_project_path) end |
#resources ⇒ Object
71 72 73 |
# File 'lib/ib/project.rb', line 71 def resources @resources ||= project.new_group("Resources") end |
#setup_paths ⇒ Object
83 84 85 86 |
# File 'lib/ib/project.rb', line 83 def setup_paths support_files.path = File.join(project_path, IB_PROJECT_NAME) pods.path = File.join(project_path, 'vendor/Pods/Headers') end |
#support_files ⇒ Object
75 76 77 |
# File 'lib/ib/project.rb', line 75 def support_files @support_files ||= project.new_group("Supporting Files") end |
#target ⇒ Object
63 64 65 |
# File 'lib/ib/project.rb', line 63 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
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/ib/project.rb', line 48 def write setup_paths generate_stub_files add_resources add_pods add_frameworks project.save end |