Skip to content

Commit

Permalink
Clean up.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jasper Blues authored and Jasper Blues committed Jan 31, 2013
1 parent 7300f7d commit 6590ed6
Show file tree
Hide file tree
Showing 12 changed files with 181 additions and 186 deletions.
60 changes: 0 additions & 60 deletions Source/Component/Builders/TyphoonDefinition+BlockBuilders.h

This file was deleted.

89 changes: 0 additions & 89 deletions Source/Component/Builders/TyphoonDefinition+BlockBuilders.m

This file was deleted.

43 changes: 43 additions & 0 deletions Source/Factory/Block/Component/TyphoonDefinition+BlockAssembly.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,51 @@
#import <Foundation/Foundation.h>
#import "TyphoonDefinition.h"

@class TyphoonInitializer;
@class TyphoonDefinition;


typedef void(^TyphoonInitializationBlock)(TyphoonInitializer* initializer);

typedef void(^TyphoonPropertyInjectionBlock)(TyphoonDefinition* propertyInjector);


@interface TyphoonDefinition (BlockAssembly)



/* ====================================================================================================================================== */
#pragma mark No injection

+ (TyphoonDefinition*)withClass:(Class)clazz;

+ (TyphoonDefinition*)withClass:(Class)clazz key:(NSString*)key;


/* ====================================================================================================================================== */
#pragma mark Anonymous keys

+ (TyphoonDefinition*)withClass:(Class)clazz initialization:(TyphoonInitializationBlock)initialization
properties:(TyphoonPropertyInjectionBlock)properties;

+ (TyphoonDefinition*)withClass:(Class)clazz initialization:(TyphoonInitializationBlock)initialization;


+ (TyphoonDefinition*)withClass:(Class)clazz properties:(TyphoonPropertyInjectionBlock)properties;


/* ====================================================================================================================================== */
#pragma mark - Explicit keys

+ (TyphoonDefinition*)withClass:(Class)clazz key:(NSString*)key initialization:(TyphoonInitializationBlock)initialization;

+ (TyphoonDefinition*)withClass:(Class)clazz key:(NSString*)key properties:(TyphoonPropertyInjectionBlock)properties;

+ (TyphoonDefinition*)withClass:(Class)clazz key:(NSString*)key initialization:(TyphoonInitializationBlock)initialization
properties:(TyphoonPropertyInjectionBlock)properties;


/* ====================================================================================================================================== */
- (void)injectProperty:(SEL)selector withDefinition:(TyphoonDefinition*)definition;

@end
72 changes: 72 additions & 0 deletions Source/Factory/Block/Component/TyphoonDefinition+BlockAssembly.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,82 @@


#import "TyphoonDefinition+BlockAssembly.h"
#import "TyphoonInitializer+BlockAssembly.h"


@implementation TyphoonDefinition (BlockAssembly)

/* ====================================================================================================================================== */
#pragma mark - No injection



+ (TyphoonDefinition*)withClass:(Class)clazz
{
return [[TyphoonDefinition alloc] initWithClass:clazz key:nil];
}

+ (TyphoonDefinition*)withClass:(Class)clazz key:(NSString*)key
{
return [[TyphoonDefinition alloc] initWithClass:clazz key:key];
}


/* ====================================================================================================================================== */
#pragma mark Anonymous keys

+ (TyphoonDefinition*)withClass:(Class)clazz initialization:(TyphoonInitializationBlock)initialization
{
return [TyphoonDefinition withClass:clazz key:nil initialization:initialization properties:nil];
}

+ (TyphoonDefinition*)withClass:(Class)clazz properties:(TyphoonPropertyInjectionBlock)properties
{
return [TyphoonDefinition withClass:clazz key:nil initialization:nil properties:properties];
}

+ (TyphoonDefinition*)withClass:(Class)clazz initialization:(TyphoonInitializationBlock)initialization
properties:(TyphoonPropertyInjectionBlock)properties
{
return [TyphoonDefinition withClass:clazz key:nil initialization:initialization properties:properties];
}


/* ====================================================================================================================================== */
#pragma mark Explicit keys
+ (TyphoonDefinition*)withClass:(Class)clazz key:(NSString*)key initialization:(TyphoonInitializationBlock)initialization
properties:(TyphoonPropertyInjectionBlock)properties
{

TyphoonDefinition* definition = [[TyphoonDefinition alloc] initWithClass:clazz key:key];
if (initialization)
{
TyphoonInitializer* componentInitializer = [[TyphoonInitializer alloc] init];
definition.initializer = componentInitializer;
__unsafe_unretained TyphoonInitializer* weakInitializer = componentInitializer;
initialization(weakInitializer);
}
if (properties)
{
__unsafe_unretained TyphoonDefinition* weakDefinition = definition;
properties(weakDefinition);
}
return definition;
}

+ (TyphoonDefinition*)withClass:(Class)clazz key:(NSString*)key initialization:(TyphoonInitializationBlock)initialization
{
return [TyphoonDefinition withClass:clazz key:key initialization:initialization properties:nil];
}

+ (TyphoonDefinition*)withClass:(Class)clazz key:(NSString*)key properties:(TyphoonPropertyInjectionBlock)properties
{
return [TyphoonDefinition withClass:clazz key:key initialization:nil properties:properties];
}



/* ====================================================================================================================================== */
- (void)injectProperty:(SEL)selector withDefinition:(TyphoonDefinition*)definition
{
[self injectProperty:selector withReference:definition.key];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@

+ (TyphoonPropertyPlaceholderConfigurer*)configurer;

+ (TyphoonPropertyPlaceholderConfigurer*)configurerWithResource:(id<TyphoonResource>)resource;

+ (TyphoonPropertyPlaceholderConfigurer*)configurerWithResources:(id<TyphoonResource>)first, ...NS_REQUIRES_NIL_TERMINATION;

- (id)initWithPrefix:(NSString*)prefix suffix:(NSString*)suffix;

- (void)usePropertyStyleResource:(id <TyphoonResource>)resource;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,30 @@ + (TyphoonPropertyPlaceholderConfigurer*)configurer
return [[[self class] alloc] init];
}

+ (TyphoonPropertyPlaceholderConfigurer*)configurerWithResource:(id <TyphoonResource>)resource
{
TyphoonPropertyPlaceholderConfigurer* configurer = [TyphoonPropertyPlaceholderConfigurer configurer];
[configurer usePropertyStyleResource:resource];
return configurer;
}

+ (TyphoonPropertyPlaceholderConfigurer*)configurerWithResources:(id <TyphoonResource>)first,...
{
TyphoonPropertyPlaceholderConfigurer* configurer = [TyphoonPropertyPlaceholderConfigurer configurer];
[configurer usePropertyStyleResource:first];

va_list resource_list;
va_start(resource_list, first);
id<TyphoonResource> resource;
while ((resource = va_arg( resource_list, id<TyphoonResource>)))
{
[configurer usePropertyStyleResource:resource];
}
va_end(resource_list);
return configurer;
}


/* ============================================================ Initializers ============================================================ */
- (id)initWithPrefix:(NSString*)prefix suffix:(NSString*)suffix
{
Expand All @@ -61,6 +85,7 @@ - (id)init
/* ========================================================== Interface Methods ========================================================= */
- (void)usePropertyStyleResource:(id <TyphoonResource>)resource
{
NSLog(@"$$$$$$$ here we go$$$$$$");
NSArray* lines = [[resource asString] componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];
for (NSString* line in lines)
{
Expand Down
2 changes: 1 addition & 1 deletion Source/Factory/TyphoonComponentFactory.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
#import "TyphoonComponentFactory.h"
#import "TyphoonDefinition.h"
#import "TyphoonComponentFactory+InstanceBuilder.h"
#import "TyphoonDefinition+BlockBuilders.h"
#import "TyphoonIntrospectionUtils.h"
#import "TyphoonDefinition+BlockAssembly.h"


@interface TyphoonDefinition (TyphoonComponentFactory)
Expand Down
1 change: 0 additions & 1 deletion Source/Factory/Xml/TyphoonXmlComponentFactory.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ - (id)initWithConfigFileNames:(NSString*)configFileName, ...
self = [super init];
if (self)
{

va_list xml_list;
_resourceNames = [NSMutableArray arrayWithObject:configFileName];

Expand Down
16 changes: 1 addition & 15 deletions Source/Typhoon.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
////////////////////////////////////////////////////////////////////////////////

#import "TyphoonDefinition.h"
#import "TyphoonDefinition+BlockBuilders.h"
#import "TyphoonInitializer.h"
#import "TyphoonPropertyPlaceholderConfigurer.h"
#import "TyphoonResource.h"
Expand All @@ -29,19 +28,6 @@
#import "TyphoonInitializer+BlockAssembly.h"
#import "TyphoonDefinition+BlockAssembly.h"

#define typhoon_autoWire(args...) \
+ (NSSet *)typhoonAutoInjectedProperties { \
NSMutableSet* autoInjectProperties = [NSMutableSet set]; \
SEL the_selectors[] = {args}; \
int argCount = (sizeof((SEL[]){args})/sizeof(SEL)); \
for (int i = 0; i < argCount; i++) { \
SEL selector = the_selectors[i]; \
[autoInjectProperties addObject:NSStringFromSelector(selector)]; \
} \
return TyphoonAutoWiredProperties(self, autoInjectProperties); \
}
#import "TyphoonAutowire.h"

#ifdef typhoon_shorthand
#define autoWire typhoon_autoWire
#endif

Loading

0 comments on commit 6590ed6

Please sign in to comment.