Class: IB::Project

Inherits:
Object
  • Object
show all
Defined in:
lib/ib/project.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Project

Returns a new instance of Project.



4
5
6
7
8
9
# File 'lib/ib/project.rb', line 4

def initialize options={}
  @platform          = options[:platform] || detect_platform || :ios
  @app_path          = options[:app_path] || "app"
  @resources_path    = options[:resources_path] || "resources"
  @pods_headers_path = options[:pods_headers_path] || "vendor/Pods/Headers"
end

Instance Attribute Details

#app_pathObject

Returns the value of attribute app_path.



2
3
4
# File 'lib/ib/project.rb', line 2

def app_path
  @app_path
end

#platformObject

Returns the value of attribute platform.



2
3
4
# File 'lib/ib/project.rb', line 2

def platform
  @platform
end

#pods_headers_pathObject

Returns the value of attribute pods_headers_path.



2
3
4
# File 'lib/ib/project.rb', line 2

def pods_headers_path
  @pods_headers_path
end

#resources_pathObject

Returns the value of attribute resources_path.



2
3
4
# File 'lib/ib/project.rb', line 2

def resources_path
  @resources_path
end

Instance Method Details

#detect_platformObject



11
12
13
14
15
16
17
18
# File 'lib/ib/project.rb', line 11

def detect_platform
  # TODO: find a better way to detect platform
  if defined?(Motion::Project::Config)
    if Motion::Project::App.config.respond_to?(:platforms)
      Motion::Project::App.config.platforms[0] == 'MacOSX' ? :osx : :ios
    end
  end
end

#writeObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/ib/project.rb', line 20

def write
  project = Xcodeproj::Project.new
  target = project.new_target(:static_library, 'ib', platform)

  resources = project.new_group("Resources")
  resources.path = resources_path

  support   = project.new_group("Supporting Files")
  support.path = "ib.xcodeproj"

  pods      = project.new_group("Pods")
  pods.path = pods_headers_path

  IB::Generator.new.write(Motion::Project::App.config.files, "ib.xcodeproj")

  support.new_file "ib.xcodeproj/Stubs.h"
  file = support.new_file "ib.xcodeproj/Stubs.m"
  target.add_file_references([ file ])

  resource_exts = %W{xcdatamodeld png jpg jpeg storyboard xib lproj}
  Dir.glob("#{resources_path}/**/*.{#{resource_exts.join(",")}}") do |file|
    if file.end_with? ".xcdatamodeld"
      relative_file_path = file.split("/").last
      obj = resources.new_xcdatamodel_group(relative_file_path)
      internal_file = obj.files.first
      internal_file.path = relative_file_path.gsub(/xcdatamodeld$/, 'xcdatamodel')
      internal_file.source_tree = "<group>"
      resources.children << obj
    else
      resources.new_file(file)
    end
  end

  Dir.glob("#{pods_headers_path}/**/*.h") do |file|
    pods.new_file(file)
  end

  %W{QuartzCore CoreGraphics CoreData}.each do |framework|
    project.add_system_framework framework, target
  end

  project.save_as("ib.xcodeproj")
end