diff --git a/CHANGELOG.md b/CHANGELOG.md index ea3a48e5d..4387b27f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/xcodeproj/project/object/group.rb b/lib/xcodeproj/project/object/group.rb index 33a6da89a..f9b906c9b 100644 --- a/lib/xcodeproj/project/object/group.rb +++ b/lib/xcodeproj/project/object/group.rb @@ -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. # diff --git a/spec/project/object/group_spec.rb b/spec/project/object/group_spec.rb index a8b272585..7a9bd7d60 100644 --- a/spec/project/object/group_spec.rb +++ b/spec/project/object/group_spec.rb @@ -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 == '' + 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.path.should == 'localized_resources' + end + end + #-------------------------------------------------------------------------# it 'removes groups and files recursively' do