Skip to content

Commit

Permalink
Merge pull request #315 from timbodeit/new-variant-group
Browse files Browse the repository at this point in the history
Add a method to create a new PBXVariantGroup in a group
  • Loading branch information
segiddins committed Oct 15, 2015
2 parents 472b9e8 + a140f9e commit 80739ff
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
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

0 comments on commit 80739ff

Please sign in to comment.