Class: MFXcode::Plugins::Addfile
- Inherits:
-
Object
- Object
- MFXcode::Plugins::Addfile
- Defined in:
- lib/mfxcode/plugins/addfile.rb
Overview
Adds files to a group in the Xcode project
Instance Method Summary collapse
-
#create_group_hierarchy_if_not_present(main_group, sub_groups) ⇒ Object
create a hierarchy of group if not present.
- #help ⇒ Object
- #run(args) ⇒ Object
Instance Method Details
#create_group_hierarchy_if_not_present(main_group, sub_groups) ⇒ Object
create a hierarchy of group if not present
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/mfxcode/plugins/addfile.rb', line 98 def create_group_hierarchy_if_not_present(main_group, sub_groups) g = sub_groups.shift if main_group[g].nil? main_group.new_group(g) if main_group.path.nil? main_group[g].path = g else main_group[g].path = main_group.path + "/" + g end end create_group_hierarchy_if_not_present(main_group[g], sub_groups) unless sub_groups.empty? end |
#help ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/mfxcode/plugins/addfile.rb', line 27 def help {:short => 'adds files to a group in Xcode project', :long => <<"END" } Usage: addfile project_path group file [file file ...] Adds files to a group, in the project at the given path. END end |
#run(args) ⇒ Object
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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/mfxcode/plugins/addfile.rb', line 36 def run(args) if args.count >= 3 project_path = args.shift group_name_arg = args.shift files = args project = Xcodeproj::Project.open(project_path) # filter files which are already included project_files = [] project.files.each { |f| project_files << f.path } files = files.select { |f| ! project_files.include? f } create_group_hierarchy_if_not_present(project.main_group, group_name_arg.split("/")) group = project[group_name_arg] main_target_name = project_path.split("/").last.split(".").first test_target_name = main_target_name + "Tests" #puts "Main target is #{main_target_name}. files will be added to this target." #puts "#{project.targets}" #puts "#{project.pretty_print}" main_target = project.targets.select {|t| t.name == main_target_name}.first test_target = project.targets.select {|t| t.name == test_target_name}.first files.each do |file| #puts "current file: #{file}" f = group.new_file(file,'SOURCE_ROOT') #puts "current file: #{f}" #puts "current file: #{f.name}" #puts "#{group_name_arg}" fext = f.name.split(".").last case fext when "h" when "pch" when "contents" when "m" #puts "Adding source file #{f.name}" main_target.add_file_references [f] test_target.add_file_references [f] else #puts "Adding ressource file #{f.name}" main_target.build_phases.select {|bp| bp.isa == 'PBXResourcesBuildPhase'}.first.add_file_reference f end end #puts "#{project_path}" project.save(project_path) else puts "Too few arguments" puts help[:long] exit 1 end end |