Skip to content

Commit

Permalink
Use project name in file header when multiple targets are specified
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandre-pod committed Feb 21, 2025
1 parent 5db2539 commit 3a1a158
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
19 changes: 15 additions & 4 deletions lib/ccios/file_creator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ def pf_new_group(associate_path_to_group:, name:, path:)
end
end

class Xcodeproj::Project

def project_name_from_path
File.basename(@path, File.extname(@path))
end
end

class FileCreator

def self.logger
Expand All @@ -25,12 +32,16 @@ def logger
FileCreator.logger
end

def templater_options(target)
def templater_options(targets, project)
defaults = {
project_name: target.display_name,
full_username: git_username,
date: DateTime.now.strftime("%d/%m/%Y"),
}
if targets.count == 1
defaults["project_name"] = targets[0].display_name
else
defaults["project_name"] = project.project_name_from_path
end
defaults
end

Expand All @@ -44,15 +55,15 @@ def get_unknown_template_tags_for(template_path)
tags
end

def create_file_using_template_path(template_path, generated_filename, group, targets, context)
def create_file_using_template_path(template_path, generated_filename, group, targets, project, context)
file_path = File.join(group.real_path, generated_filename)

raise "File #{file_path} already exists" if File.exist?(file_path)
dirname = File.dirname(file_path)
FileUtils.mkdir_p dirname unless File.directory?(dirname)
file = File.new(file_path, 'w')

context = context.merge(templater_options(targets[0]))
context = context.merge(templater_options(targets, project))
file_content = CodeTemplater.new.render_file_content_from_template(template_path, generated_filename, context)

file.puts(file_content)
Expand Down
1 change: 1 addition & 0 deletions lib/ccios/file_template_definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ def generate(parser, project, context, template_definition, config)
generated_filename,
group,
targets,
project,
context
)
end
Expand Down

0 comments on commit 3a1a158

Please sign in to comment.