Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a method to create a new PBXVariantGroup in a group #315

Merged
merged 4 commits into from
Oct 15, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Xcodeproj Changelog

## Master

##### Enhancements

* Add method to create new variant groups (groups for localized versions of the same file)
[Tim Bodeit](https://github.com/timbodeit)
[Xcodeproj#315](https://github.com/CocoaPods/Xcodeproj/pull/315)


## 0.28.2 (2015-10-09)

##### Bug Fixes
Expand Down
28 changes: 28 additions & 0 deletions lib/xcodeproj/project/object/group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,34 @@ def new_group(name, path = nil, source_tree = :group)
group
end

# Creates a new variant group and adds it to the group
#
# @note @see new_group
#
# @param [#to_s] name
# the name of the new group.
#
# @param [#to_s] path
# The, preferably absolute, path of the variant group.
# Pass the path of the folder containing all the .lproj bundles,
# that contain files for the variant group.
# Do not pass the path of a specific bundle (such as en.lproj)
#
# @param [Symbol] source_tree
# The source tree key to use to configure the path (@see
# GroupableHelper::SOURCE_TREES_BY_KEY).
#
# @return [PBXVariantGroup] the new variant group.
#
def new_variant_group(name, path = nil, source_tree = :group)
group = project.new(PBXVariantGroup)
children << group
group.name = name
group.set_source_tree(source_tree)
group.set_path(path)
group
end

# Traverses the children groups and finds the group with the given
# path, if exists.
#
Expand Down
20 changes: 20 additions & 0 deletions spec/project/object/group_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,26 @@ module ProjectSpecs
end
end

describe '#new_variant_group' do
it 'creates a new variant group' do
group = @group.new_variant_group('LocalizedResource')
group.name.should == 'LocalizedResource'
group.parent.should == @group
group.should.is_a?(PBXVariantGroup)
end

it 'sets the source tree to group if not path is provided' do
group = @group.new_group('LocalizedResource')
group.source_tree.should == '<group>'
end

it 'sets the path according to the source tree if provided' do
group = @group.new_group('LocalizedResource', '/project_dir/localized_resources')
group.source_tree.should == '<group>'
group.path.should == 'localized_resources'
end
end

#-------------------------------------------------------------------------#

it 'removes groups and files recursively' do
Expand Down