-
-
Notifications
You must be signed in to change notification settings - Fork 294
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add variant groups for localization
- Loading branch information
1 parent
0719478
commit 48cd983
Showing
7 changed files
with
82 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from pbxproj.PBXGenericObject import * | ||
from pbxproj.pbxsections.PBXFileReference import * | ||
|
||
|
||
class PBXVariantGroup(PBXGenericObject): | ||
@classmethod | ||
def create(cls, name, children=None, source_tree=u'<group>'): | ||
return cls().parse({ | ||
u'_id': cls._generate_id(), | ||
u'isa': cls.__name__, | ||
u'children': children if children else [], | ||
u'name': name, | ||
u'sourceTree': source_tree | ||
}) | ||
|
||
def add_variant(self, file_ref): | ||
if not isinstance(file_ref, PBXFileReference): | ||
return False | ||
|
||
self.children.append(file_ref.get_id()) | ||
return True | ||
|
||
def remove_variant(self, file_ref): | ||
if not isinstance(file_ref, PBXFileReference): | ||
return False | ||
|
||
self.children.remove(file_ref.get_id()) | ||
del self.get_parent()[file_ref.get_id()] | ||
|
||
return True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import unittest | ||
from pbxproj.pbxsections.PBXVariantGroup import * | ||
from pbxproj.PBXObjects import * | ||
|
||
|
||
class PBXVariantGroupTest(unittest.TestCase): | ||
def testAddVariantInvalidFileRef(self): | ||
variant = PBXVariantGroup.create(u'texts') | ||
self.assertFalse(variant.add_variant(PBXGenericObject().parse({u'isa': ''}))) | ||
|
||
def testAddVariantValidFileRef(self): | ||
variant = PBXVariantGroup.create(u'texts') | ||
self.assertTrue(variant.add_variant(PBXFileReference().parse({u'_id': '1', u'isa': 'PBXFileReference'}))) | ||
self.assertIn('1', variant.children) | ||
|
||
def testRemoveVariantInvalidFileRef(self): | ||
variant = PBXVariantGroup.create(u'texts') | ||
self.assertFalse(variant.remove_variant(PBXGenericObject().parse({u'isa': ''}))) | ||
|
||
def testRemoveVariantValidFileRef(self): | ||
objs = objects().parse({u'1': {u'isa': 'PBXFileReference'}}) | ||
file_ref = objs['1'] | ||
|
||
variant = PBXVariantGroup.create(u'texts') | ||
objs[variant.get_id()] = variant | ||
|
||
variant.add_variant(file_ref) | ||
|
||
self.assertTrue(variant.remove_variant(file_ref)) | ||
self.assertNotIn('1', variant.children) |