Commit c6a0db36 authored by Tim Bodeit's avatar Tim Bodeit

[Project] Make variant groups for localized files in add_file_reference

When adding a file reference for a file in a *.lproj folder, use a
variant group to group it with corresponding files for other languages.

Grouping is done by the names without extensions of the files inside the
*.lproj folders.
For example: Base.lproj/Foo.storyboard and de.lproj/Foo.strings will
be put together in a variant group called Foo.
parent 71f65fff
...@@ -183,14 +183,7 @@ module Pod ...@@ -183,14 +183,7 @@ module Pod
raise ArgumentError, "Paths must be absolute #{absolute_path}" raise ArgumentError, "Paths must be absolute #{absolute_path}"
end end
if reflect_file_system_structure group = group_for_path_in_group(absolute_path, group, reflect_file_system_structure)
relative_path = file_path_name.relative_path_from(group.real_path)
relative_dir = relative_path.dirname
relative_dir.each_filename do|name|
next if name == '.'
group = group[name] || group.new_group(name, name)
end
end
if ref = reference_for_path(absolute_path) if ref = reference_for_path(absolute_path)
ref ref
...@@ -272,6 +265,55 @@ module Pod ...@@ -272,6 +265,55 @@ module Pod
# #
attr_reader :refs_by_absolute_path attr_reader :refs_by_absolute_path
# Returns the group for an absolute file path in another group.
# Creates subgroups to reflect the file system structure if
# reflect_file_system_structure is set to true.
# Makes a variant group if the path points to a localized file inside a
# *.lproj folder. The same variant group is returned for files with the
# same name, even if their file extensions differ.
#
# @param [Pathname] absolute_pathname
# The pathname of the file to get the group for.
#
# @param [PBXGroup] group
# The parent group used as the base of the relative path.
#
# @param [Bool] reflect_file_system_structure
# Whether group structure should reflect the file system structure.
# If yes, where needed, intermediate groups are created, similar to
# how mkdir -p operates.
#
# @return [PBXGroup] The appropriate group for the filepath.
# Can be PBXVariantGroup, if the file is localized.
#
def group_for_path_in_group(absolute_pathname, group, reflect_file_system_structure)
unless absolute_pathname.absolute?
raise ArgumentError, "Paths must be absolute #{absolute_path}"
end
relative_pathname = absolute_pathname.relative_path_from(group.real_path)
relative_dir = relative_pathname.dirname
lproj_regex = /\.lproj/
# Add subgroups for folders, but treat .lproj as a file
if reflect_file_system_structure
relative_dir.each_filename do|name|
break if name.to_s =~ lproj_regex
next if name == '.'
group = group[name] || group.new_group(name, name)
end
end
# Turn .lproj into a variant group
if relative_dir.basename.to_s =~ lproj_regex
filename = absolute_pathname.basename.sub_ext('').to_s
lproj_parent_dir = absolute_pathname.dirname.dirname
group = group[filename] || group.new_variant_group(filename, lproj_parent_dir)
end
group
end
#-------------------------------------------------------------------------# #-------------------------------------------------------------------------#
end end
end end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment