diff --git a/Source/Configuration/ConfigPostProcessor/TyphoonConfigPostProcessor.h b/Source/Configuration/ConfigPostProcessor/TyphoonConfigPostProcessor.h index 69fcfbc92..92df57c52 100644 --- a/Source/Configuration/ConfigPostProcessor/TyphoonConfigPostProcessor.h +++ b/Source/Configuration/ConfigPostProcessor/TyphoonConfigPostProcessor.h @@ -28,6 +28,11 @@ */ + (instancetype)forResourceNamed:(NSString *)resourceName; +/** + * Returns a post processor for the bundle resource with the given name and bundle. + */ ++ (instancetype)forResourceNamed:(NSString *)resourceName inBundle:(NSBundle *)bundle; + /** * Returns a post processor for the resource at the specified path. */ @@ -47,6 +52,9 @@ /** Append resource found in main bundle by name */ - (void)useResourceWithName:(NSString *)name; +/** Append resource found by name and bundle */ +- (void)useResourceWithName:(NSString *)name bundle:(NSBundle *)bundle; + /** Append resource loaded from file at path */ - (void)useResourceAtPath:(NSString *)path; diff --git a/Source/Configuration/ConfigPostProcessor/TyphoonConfigPostProcessor.m b/Source/Configuration/ConfigPostProcessor/TyphoonConfigPostProcessor.m index 6ef2e8d9c..b78aa2d8b 100644 --- a/Source/Configuration/ConfigPostProcessor/TyphoonConfigPostProcessor.m +++ b/Source/Configuration/ConfigPostProcessor/TyphoonConfigPostProcessor.m @@ -48,6 +48,13 @@ + (TyphoonConfigPostProcessor *)forResourceNamed:(NSString *)resourceName return processor; } ++ (TyphoonConfigPostProcessor *)forResourceNamed:(NSString *)resourceName inBundle:(NSBundle *)bundle +{ + TyphoonConfigPostProcessor *processor = [[TyphoonConfigPostProcessor alloc] init]; + [processor useResourceWithName:resourceName bundle:bundle]; + return processor; +} + + (TyphoonConfigPostProcessor *)forResourceAtPath:(NSString *)path { TyphoonConfigPostProcessor *processor = [[TyphoonConfigPostProcessor alloc] init]; @@ -104,7 +111,12 @@ + (void)initialize - (void)useResourceWithName:(NSString *)name { - [self useResource:[TyphoonBundleResource withName:name inBundle:[NSBundle mainBundle]] + [self useResourceWithName:name bundle:[NSBundle mainBundle]]; +} + +- (void)useResourceWithName:(NSString *)name bundle:(NSBundle *)bundle +{ + [self useResource:[TyphoonBundleResource withName:name inBundle:bundle] withExtension:[name pathExtension]]; } diff --git a/Source/Definition/Internal/TyphoonDefinition+Infrastructure.h b/Source/Definition/Internal/TyphoonDefinition+Infrastructure.h index a3dcbd18a..737775a0d 100644 --- a/Source/Definition/Internal/TyphoonDefinition+Infrastructure.h +++ b/Source/Definition/Internal/TyphoonDefinition+Infrastructure.h @@ -59,12 +59,20 @@ Declares short-hand definition factory methods for infrastructure components. + (instancetype)withClass:(Class)clazz key:(NSString *)key; /** -Factory method for a TyphoonConfigPostProcessor. +Factory method for a TyphoonConfigPostProcessor. Don't use it in test targets! @param fileName The config filename to load. File should be placed in main bundle @return a definition. */ + (instancetype)configDefinitionWithName:(NSString *)fileName; +/** + Factory method for a TyphoonConfigPostProcessor. + @param fileName The config filename to load. + @param fileBundle The bundle, where the config file is placed + @return a definition. + */ ++ (instancetype)configDefinitionWithName:(NSString *)fileName bundle:(NSBundle *)fileBundle; + /** Factory method for a TyphoonConfigPostProcessor. @param filePath The path to config file to load. diff --git a/Source/Definition/Internal/TyphoonDefinition+Infrastructure.m b/Source/Definition/Internal/TyphoonDefinition+Infrastructure.m index a489307d4..d3266824e 100644 --- a/Source/Definition/Internal/TyphoonDefinition+Infrastructure.m +++ b/Source/Definition/Internal/TyphoonDefinition+Infrastructure.m @@ -45,6 +45,16 @@ + (instancetype)configDefinitionWithName:(NSString *)fileName }]; } ++ (instancetype)configDefinitionWithName:(NSString *)fileName bundle:(NSBundle *)fileBundle { + return [self withClass:[TyphoonConfigPostProcessor class] configuration:^(TyphoonDefinition *definition) { + [definition injectMethod:@selector(useResourceWithName:bundle:) parameters:^(TyphoonMethod *method) { + [method injectParameterWith:fileName]; + [method injectParameterWith:fileBundle]; + }]; + definition.key = [NSString stringWithFormat:@"%@-%@", NSStringFromClass(definition.class), fileName]; + }]; +} + + (instancetype)configDefinitionWithPath:(NSString *)filePath { return [self withClass:[TyphoonConfigPostProcessor class] configuration:^(TyphoonDefinition *definition) {