Skip to content

Commit

Permalink
Merge pull request #123 from rambler-ios/feature/task-118
Browse files Browse the repository at this point in the history
[RESOLVED] Added the possibility to add empty group to Xcode structure #118
  • Loading branch information
etolstoy authored Jul 21, 2016
2 parents 0cafe28 + 91389dd commit 53495ae
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 21 deletions.
20 changes: 15 additions & 5 deletions lib/generamba/helpers/xcodeproj_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def self.obtain_project(project_name)
#
# @return [void]
def self.add_file_to_project_and_targets(project, targets_name, group_path, file_path, file_type = nil)
module_group = self.retreive_group_or_create_if_needed(group_path, project, true)
module_group = self.retrieve_group_or_create_if_needed(group_path, project, true)
xcode_file = module_group.new_file(File.absolute_path(file_path))

file_name = File.basename(file_path)
Expand All @@ -40,6 +40,15 @@ def self.add_file_to_project_and_targets(project, targets_name, group_path, file
end
end
end

# Adds a provided directory to a specific Project
# @param project [Xcodeproj::Project] The target xcodeproj file
# @param group_path [Pathname] The Xcode group path for current directory
#
# @return [void]
def self.add_group_to_project(project, group_path)
self.retrieve_group_or_create_if_needed(group_path, project, true)
end

# Adds xcode file to target based on it's type
# @param target [Xcodeproj::AbstractTarget] xcode target to use
Expand Down Expand Up @@ -79,7 +88,7 @@ def self.is_bundle_resource?(resource_name)
#
# @return [Void]
def self.clear_group(project, targets_name, group_path)
module_group = self.retreive_group_or_create_if_needed(group_path, project, false)
module_group = self.retrieve_group_or_create_if_needed(group_path, project, false)
return unless module_group

files_path = self.files_path_from_group(module_group, project)
Expand All @@ -98,7 +107,7 @@ def self.clear_group(project, targets_name, group_path)
#
# @return [TrueClass or FalseClass]
def self.module_with_group_path_already_exists(project, group_path)
module_group = self.retreive_group_or_create_if_needed(group_path, project, false)
module_group = self.retrieve_group_or_create_if_needed(group_path, project, false)
return module_group == nil ? false : true
end

Expand All @@ -110,18 +119,19 @@ def self.module_with_group_path_already_exists(project, group_path)
# @param create_group_if_not_exists [TrueClass or FalseClass] If true notexistent group will be created
#
# @return [PBXGroup]
def self.retreive_group_or_create_if_needed(group_path, project, create_group_if_not_exists)
def self.retrieve_group_or_create_if_needed(group_path, project, create_group_if_not_exists)
group_names = path_names_from_path(group_path)

final_group = project

group_names.each do |group_name|
next_group = final_group[group_name]

unless next_group
unless create_group_if_not_exists
return nil
end

new_group_path = group_name
next_group = final_group.new_group(group_name, new_group_path)
end
Expand Down
39 changes: 23 additions & 16 deletions lib/generamba/module_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,23 +67,30 @@ def process_files_if_needed(files, name, code_module, template, project, targets

XcodeprojHelper.clear_group(project, targets, group_path)
files.each do |file|

file_group = File.dirname(file[TEMPLATE_NAME_KEY])

# Generating the content of the code file and it's name
file_name, file_content = ContentGenerator.create_file(file, code_module, template)
file_path = dir_path.join(file_group).join(file_name)

# Creating the file in the filesystem
FileUtils.mkdir_p File.dirname(file_path)
File.open(file_path, 'w+') do |f|
f.write(file_content)
end

file_type = file[TEMPLATE_FILE_FILETYPE_KEY]
unless file[TEMPLATE_FILE_PATH_KEY]
directory_name = file[TEMPLATE_NAME_KEY].gsub(/^\/|\/$/, '')
file_group = dir_path.join(directory_name)

FileUtils.mkdir_p file_group
XcodeprojHelper.add_group_to_project(project, file_group)
else
file_group = File.dirname(file[TEMPLATE_NAME_KEY])

# Generating the content of the code file and it's name
file_name, file_content = ContentGenerator.create_file(file, code_module, template)
file_path = dir_path.join(file_group).join(file_name)

# Creating the file in the Xcode project
XcodeprojHelper.add_file_to_project_and_targets(project, targets, group_path.join(file_group), file_path, file_type)
# Creating the file in the filesystem
FileUtils.mkdir_p File.dirname(file_path)
File.open(file_path, 'w+') do |f|
f.write(file_content)
end

file_type = file[TEMPLATE_FILE_FILETYPE_KEY]

# Creating the file in the Xcode project
XcodeprojHelper.add_file_to_project_and_targets(project, targets, group_path.join(file_group), file_path, file_type)
end
end
end
end
Expand Down

0 comments on commit 53495ae

Please sign in to comment.