-
Notifications
You must be signed in to change notification settings - Fork 268
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added nib resolver for view controllers
- Loading branch information
Erik Sundin
committed
Sep 14, 2013
1 parent
27943e6
commit b32e214
Showing
14 changed files
with
12,808 additions
and
3,383 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
Source/ios/Factory/Config/Resolver/TyphoonViewControllerNibResolver.h
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,29 @@ | ||
//////////////////////////////////////////////////////////////////////////////// | ||
// | ||
// TYPHOON FRAMEWORK | ||
// Copyright 2013, Jasper Blues & Contributors | ||
// All Rights Reserved. | ||
// | ||
// NOTICE: The authors permit you to use, modify, and distribute this file | ||
// in accordance with the terms of the license agreement accompanying it. | ||
// | ||
//////////////////////////////////////////////////////////////////////////////// | ||
|
||
#import <Foundation/Foundation.h> | ||
#import "TyphoonComponentFactoryPostProcessor.h" | ||
|
||
/** | ||
Post-Processor that completes the initializer of definitions with type UIViewController. | ||
If the definition already has a TyphoonIntializer set, the processor will ignore the component. | ||
*/ | ||
@interface TyphoonViewControllerNibResolver : NSObject<TyphoonComponentFactoryPostProcessor> | ||
|
||
/** | ||
Resolves the nib name for a view controller class. | ||
Defaults to the same name as the class by NSStringFromClass. | ||
@param viewControllerClass The class. | ||
@return The nib name. | ||
*/ | ||
- (NSString *)resolveNibNameForClass:(Class)viewControllerClass; | ||
|
||
@end |
57 changes: 57 additions & 0 deletions
57
Source/ios/Factory/Config/Resolver/TyphoonViewControllerNibResolver.m
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,57 @@ | ||
//////////////////////////////////////////////////////////////////////////////// | ||
// | ||
// TYPHOON FRAMEWORK | ||
// Copyright 2013, Jasper Blues & Contributors | ||
// All Rights Reserved. | ||
// | ||
// NOTICE: The authors permit you to use, modify, and distribute this file | ||
// in accordance with the terms of the license agreement accompanying it. | ||
// | ||
//////////////////////////////////////////////////////////////////////////////// | ||
|
||
#import "TyphoonViewControllerNibResolver.h" | ||
#import "TyphoonDefinition.h" | ||
#import "TyphoonComponentFactory.h" | ||
#import "TyphoonInitializer.h" | ||
#import "TyphoonInitializer+InstanceBuilder.h" | ||
#import <UIKit/UIKit.h> | ||
|
||
@implementation TyphoonViewControllerNibResolver | ||
|
||
#pragma mark - Protocol methods | ||
|
||
- (void)postProcessComponentFactory:(TyphoonComponentFactory *)factory | ||
{ | ||
for (TyphoonDefinition *definition in [factory registry]) | ||
{ | ||
if ([self shouldProcessDefinition:definition]) | ||
{ | ||
[self processViewControllerDefinition:definition]; | ||
} | ||
} | ||
} | ||
|
||
#pragma mark - Interface methods | ||
|
||
- (NSString *)resolveNibNameForClass:(Class)viewControllerClass | ||
{ | ||
return NSStringFromClass(viewControllerClass); | ||
} | ||
|
||
/* ====================================================================================================================================== */ | ||
#pragma mark - Private Methods | ||
|
||
- (void)processViewControllerDefinition:(TyphoonDefinition *)definition | ||
{ | ||
TyphoonInitializer *initializer = [[TyphoonInitializer alloc] initWithSelector:@selector(initWithNibName:bundle:)]; | ||
[initializer injectWithValueAsText:[self resolveNibNameForClass:definition.type] requiredTypeOrNil:[NSString class]]; | ||
[initializer injectWithObject:[NSBundle mainBundle]]; | ||
definition.initializer = initializer; | ||
} | ||
|
||
- (BOOL)shouldProcessDefinition:(TyphoonDefinition *)definition | ||
{ | ||
return [definition.type isSubclassOfClass:[UIViewController class]] && definition.initializer == nil; | ||
} | ||
|
||
@end |
Empty file.
71 changes: 71 additions & 0 deletions
71
Tests/Factory/Config/Resolver/TyphoonViewControllerNibResolverTests.m
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,71 @@ | ||
//////////////////////////////////////////////////////////////////////////////// | ||
// | ||
// TYPHOON FRAMEWORK | ||
// Copyright 2013, Jasper Blues & Contributors | ||
// All Rights Reserved. | ||
// | ||
// NOTICE: The authors permit you to use, modify, and distribute this file | ||
// in accordance with the terms of the license agreement accompanying it. | ||
// | ||
//////////////////////////////////////////////////////////////////////////////// | ||
|
||
#import <SenTestingKit/SenTestingKit.h> | ||
#import <TyphoonViewControllerNibResolver.h> | ||
#import <UIKit/UIKit.h> | ||
#import <TyphoonDefinition.h> | ||
#import <TyphoonDefinition+InstanceBuilder.h> | ||
#import <TyphoonComponentFactory.h> | ||
#import <TyphoonInitializer.h> | ||
#import <TyphoonInitializer+InstanceBuilder.h> | ||
|
||
@interface TyphoonViewControllerNibResolverTests : SenTestCase | ||
{ | ||
TyphoonViewControllerNibResolver *_nibResolver; | ||
} | ||
|
||
@end | ||
|
||
@implementation TyphoonViewControllerNibResolverTests | ||
|
||
- (void)setUp { | ||
[super setUp]; | ||
_nibResolver = [[TyphoonViewControllerNibResolver alloc] init]; | ||
} | ||
|
||
- (void)test_process_view_controller_without_initializer | ||
{ | ||
TyphoonDefinition *definition = [TyphoonDefinition withClass:[UIViewController class]]; | ||
TyphoonComponentFactory *factory = mock([TyphoonComponentFactory class]); | ||
[given([factory registry]) willReturn:@[definition]]; | ||
|
||
[_nibResolver postProcessComponentFactory:factory]; | ||
|
||
assertThat(definition.initializer, notNilValue()); | ||
assertThat(NSStringFromSelector(definition.initializer.selector), equalTo(NSStringFromSelector(@selector(initWithNibName:bundle:)))); | ||
assertThatInt([[definition.initializer injectedParameters] count], equalToInt(2)); | ||
|
||
} | ||
|
||
- (void)test_skips_view_controller_with_initializer | ||
{ | ||
TyphoonDefinition *definition = [TyphoonDefinition withClass:[UIViewController class]]; | ||
TyphoonInitializer *initializer = [[TyphoonInitializer alloc] init]; | ||
definition.initializer = initializer; | ||
|
||
TyphoonComponentFactory *factory = mock([TyphoonComponentFactory class]); | ||
[given([factory registry]) willReturn:@[definition]]; | ||
|
||
[_nibResolver postProcessComponentFactory:factory]; | ||
assertThat(NSStringFromSelector(initializer.selector), equalTo(NSStringFromSelector(@selector(init)))); | ||
assertThat(definition.initializer, equalTo(initializer)); | ||
} | ||
|
||
|
||
- (void)test_resolves_nib_name_from_class | ||
{ | ||
Class clazz = [UIViewController class]; | ||
NSString *nibName = [_nibResolver resolveNibNameForClass:clazz]; | ||
assertThat(nibName, equalTo(NSStringFromClass(clazz))); | ||
} | ||
|
||
@end |
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
1 change: 1 addition & 0 deletions
1
Tests/Pods/BuildHeaders/Typhoon/TyphoonViewControllerNibResolver.h
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.