Skip to content

Commit

Permalink
Merge branch 'addTestsForExtraParams'
Browse files Browse the repository at this point in the history
* addTestsForExtraParams:
  Update to XCTest, add tests for extraParams, fix bug where extraParams were not updated for cached url
  Fixed spacing
  Adds extraParams to openUrl to allow more robust data passing through routing when a controller decides to open an url
  Fixed a type
  Mainly an accent change to use Objective-C style. fixes clayallsopp#26 Objective-C specific syntax fixes:   Verbose naming of methods, adhering to naming conventions   Passive return for nil values   No need to synthesize   Eliminate nil checks through ‘==‘   Eliminate more ‘new’ as allocation and initialization should be separated.   Use custom initialization for dictionaries and arrays for safer type   Separation of allocation and initialization: no more allocating memory when we don’t have to. Completely backward compatible Other caveats that came with idiomatic Objective-C   Safer setObject:forKey: by having early returns if there is no explicit format (to prevent crash)   Simplified logic in conditions   Simplified(?) loops through routes using faster enumeration with blocks   Add explicit factory class methods for constructions   Add default routerOptions Want to do (but didn't/haven't) to adhere to usual Objective-C style   Want to get rid of custom new (newRouter)   Want to have better error handling; no more exception throwing so we get verbose debugging info   Want to simplify controllerForRouterParams and routerParamsForUrl more   Want to get rid of register_name by defining selector macros   Want to replace property shouldOpenAsRootViewController in routerOptions into root’ with getter ‘isRoot’ to parallel modal   Not sure: routerOptions: want to not have wrappers around setters but users might want to keep DSL-style chaining.   Not sure: should I fix spacing more?   Not sure: should callback in options be overridden, ever? Functionality \todo: have both call back and ‘open’ in options. --
  [clayallsopp#24] Example App has essential buttons hidden under nav bar.
  • Loading branch information
sweetverbs committed Apr 22, 2015
2 parents 4a4bd8a + cb04399 commit a9dd82e
Show file tree
Hide file tree
Showing 5 changed files with 395 additions and 167 deletions.
17 changes: 7 additions & 10 deletions Routable.xcodeproj/project.pbxproj
Expand Up @@ -10,7 +10,6 @@
F86EF9C8170C3C7B00EB726A /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F86EF9C7170C3C7B00EB726A /* UIKit.framework */; };
F86EF9CA170C3C7B00EB726A /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F86EF9C9170C3C7B00EB726A /* Foundation.framework */; };
F86EF9CC170C3C7B00EB726A /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F86EF9CB170C3C7B00EB726A /* CoreGraphics.framework */; };
F86EF9E6170C3C7B00EB726A /* SenTestingKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F86EF9E5170C3C7B00EB726A /* SenTestingKit.framework */; };
F86EF9E7170C3C7B00EB726A /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F86EF9C7170C3C7B00EB726A /* UIKit.framework */; };
F86EF9E8170C3C7B00EB726A /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F86EF9C9170C3C7B00EB726A /* Foundation.framework */; };
F86EF9F0170C3C7B00EB726A /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = F86EF9EE170C3C7B00EB726A /* InfoPlist.strings */; };
Expand Down Expand Up @@ -38,8 +37,7 @@
F86EF9C7170C3C7B00EB726A /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
F86EF9C9170C3C7B00EB726A /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
F86EF9CB170C3C7B00EB726A /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; };
F86EF9E4170C3C7B00EB726A /* RoutableTests.octest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = RoutableTests.octest; sourceTree = BUILT_PRODUCTS_DIR; };
F86EF9E5170C3C7B00EB726A /* SenTestingKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SenTestingKit.framework; path = Library/Frameworks/SenTestingKit.framework; sourceTree = DEVELOPER_DIR; };
F86EF9E4170C3C7B00EB726A /* RoutableTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = RoutableTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
F86EF9ED170C3C7B00EB726A /* RoutableTests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "RoutableTests-Info.plist"; sourceTree = "<group>"; };
F86EF9EF170C3C7B00EB726A /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; };
F86EF9F1170C3C7B00EB726A /* RoutableTests.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RoutableTests.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -71,7 +69,6 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
F86EF9E6170C3C7B00EB726A /* SenTestingKit.framework in Frameworks */,
F86EF9E7170C3C7B00EB726A /* UIKit.framework in Frameworks */,
F86EF9E8170C3C7B00EB726A /* Foundation.framework in Frameworks */,
);
Expand All @@ -95,7 +92,7 @@
isa = PBXGroup;
children = (
F86EF9C4170C3C7B00EB726A /* Routable.app */,
F86EF9E4170C3C7B00EB726A /* RoutableTests.octest */,
F86EF9E4170C3C7B00EB726A /* RoutableTests.xctest */,
);
name = Products;
sourceTree = "<group>";
Expand All @@ -106,7 +103,6 @@
F86EF9C7170C3C7B00EB726A /* UIKit.framework */,
F86EF9C9170C3C7B00EB726A /* Foundation.framework */,
F86EF9CB170C3C7B00EB726A /* CoreGraphics.framework */,
F86EF9E5170C3C7B00EB726A /* SenTestingKit.framework */,
);
name = Frameworks;
sourceTree = "<group>";
Expand Down Expand Up @@ -199,8 +195,8 @@
);
name = RoutableTests;
productName = RoutableTests;
productReference = F86EF9E4170C3C7B00EB726A /* RoutableTests.octest */;
productType = "com.apple.product-type.bundle";
productReference = F86EF9E4170C3C7B00EB726A /* RoutableTests.xctest */;
productType = "com.apple.product-type.bundle.unit-test";
};
/* End PBXNativeTarget section */

Expand All @@ -209,6 +205,7 @@
isa = PBXProject;
attributes = {
CLASSPREFIX = UP;
LastTestingUpgradeCheck = 0630;
LastUpgradeCheck = 0460;
ORGANIZATIONNAME = "TurboProp Inc";
};
Expand Down Expand Up @@ -397,14 +394,14 @@
FRAMEWORK_SEARCH_PATHS = (
"\"$(SDKROOT)/Developer/Library/Frameworks\"",
"\"$(DEVELOPER_LIBRARY_DIR)/Frameworks\"",
"$(inherited)",
);
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "RoutableExample/Routable-Prefix.pch";
INFOPLIST_FILE = "RoutableTests/RoutableTests-Info.plist";
PRODUCT_NAME = "$(TARGET_NAME)";
TARGETED_DEVICE_FAMILY = 1;
TEST_HOST = "$(BUNDLE_LOADER)";
WRAPPER_EXTENSION = octest;
};
name = Debug;
};
Expand All @@ -415,14 +412,14 @@
FRAMEWORK_SEARCH_PATHS = (
"\"$(SDKROOT)/Developer/Library/Frameworks\"",
"\"$(DEVELOPER_LIBRARY_DIR)/Frameworks\"",
"$(inherited)",
);
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "RoutableExample/Routable-Prefix.pch";
INFOPLIST_FILE = "RoutableTests/RoutableTests-Info.plist";
PRODUCT_NAME = "$(TARGET_NAME)";
TARGETED_DEVICE_FAMILY = 1;
TEST_HOST = "$(BUNDLE_LOADER)";
WRAPPER_EXTENSION = octest;
};
name = Release;
};
Expand Down
88 changes: 88 additions & 0 deletions Routable/Routable.h
Expand Up @@ -43,58 +43,127 @@ typedef void (^RouterOpenCallback)(NSDictionary *params);
```
UPRouterOptions *options = [[UPRouterOptions modal] withPresentationStyle: UIModalPresentationFormSheet];
```
Now, you can also use an Objective-C factory method to set everything at once
```
UPRouterOptions *options = [UPRouterOptions routerOptionsWithPresentationStyle: UIModalPresentationFormSheet
transitionStyle: UIModalTransitionFormSheet
defaultParams: nil
isRoot: NO
isModal: YES];
```
Or, for most properties taking the default value:
```
UPRouterOptions *options = [[UPRouterOptions alloc] init];
[options setTransitionStyle:UIModalTransitionStyleCoverVertical];
```
*/

@interface UPRouterOptions : NSObject

/**
@return A new instance of `UPRouterOptions` with its properties explicitly set
@param presentationStyle The `UIModalPresentationStyle` attached to the mapped `UIViewController`
@param transitionStyle The `UIModalTransitionStyle` attached to the mapped `UIViewController`
@param defaultParams The default parameters which are passed when opening the URL
@param isRoot The boolean `shouldOpenAsRootViewController` property is set to
@param isModal The boolean that sets a modal presentation format
*/
+ (instancetype)routerOptionsWithPresentationStyle: (UIModalPresentationStyle)presentationStyle
transitionStyle: (UIModalTransitionStyle)transitionStyle
defaultParams: (NSDictionary *)defaultParams
isRoot: (BOOL)isRoot
isModal: (BOOL)isModal;
/**
@return A new instance of `UPRouterOptions` with its properties set to default
*/
+ (instancetype)routerOptions;

///-------------------------------
/// @name Options DSL
///-------------------------------
/**
@return A new instance of `UPRouterOptions`, setting a modal presentation format.
*/
+ (instancetype)routerOptionsAsModal;
/**
@return A new instance of `UPRouterOptions`, setting a `UIModalPresentationStyle` style.
@param style The `UIModalPresentationStyle` attached to the mapped `UIViewController`
*/
+ (instancetype)routerOptionsWithPresentationStyle:(UIModalPresentationStyle)style;
/**
@return A new instance of `UPRouterOptions`, setting a `UIModalTransitionStyle` style.
@param style The `UIModalTransitionStyle` attached to the mapped `UIViewController`
*/
+ (instancetype)routerOptionsWithTransitionStyle:(UIModalTransitionStyle)style;
/**
@return A new instance of `UPRouterOptions`, setting the defaultParams
@param defaultParams The default parameters which are passed when opening the URL
*/
+ (instancetype)routerOptionsForDefaultParams:(NSDictionary *)defaultParams;
/**
@return A new instance of `UPRouterOptions`, setting the `shouldOpenAsRootViewController` property to `YES`
*/
+ (instancetype)routerOptionsAsRoot;

//previously supported
/**
@remarks not idiomatic objective-c naming for allocation and initialization, see +routerOptionsAsModal
@return A new instance of `UPRouterOptions`, setting a modal presentation format.
*/
+ (instancetype)modal;
/**
@remarks not idiomatic objective-c naming for allocation and initialization, see + routerOptionsWithPresentationStyle:
@return A new instance of `UPRouterOptions`, setting a `UIModalPresentationStyle` style.
@param style The `UIModalPresentationStyle` attached to the mapped `UIViewController`
*/
+ (instancetype)withPresentationStyle:(UIModalPresentationStyle)style;
/**
@remarks not idiomatic objective-c naming for allocation and initialization see +routerOptionsWithTransitionStyle:
@return A new instance of `UPRouterOptions`, setting a `UIModalTransitionStyle` style.
@param style The `UIModalTransitionStyle` attached to the mapped `UIViewController`
*/
+ (instancetype)withTransitionStyle:(UIModalTransitionStyle)style;
/**
@remarks not idiomatic objective-c naming for allocation and initialization, see +routerOptionsForDefaultParams:
@return A new instance of `UPRouterOptions`, setting the defaultParams
@param defaultParams The default parameters which are passed when opening the URL
*/
+ (instancetype)forDefaultParams:(NSDictionary *)defaultParams;
/**
@remarks not idiomatic objective-c naming for allocation and initialization, see +routerOptionsAsRoot
@return A new instance of `UPRouterOptions`, setting the `shouldOpenAsRootViewController` property to `YES`
*/
+ (instancetype)root;

/**
@remarks not idiomatic objective-c naming; overrides getter to wrap around setter
@return The same instance of `UPRouterOptions`, setting a modal presentation format.
*/
- (UPRouterOptions *)modal;
/**
@remarks not idiomatic objective-c naming; wraps around setter
@return The same instance of `UPRouterOptions`, setting a `UIModalPresentationStyle` style.
@param style The `UIModalPresentationStyle` attached to the mapped `UIViewController`
*/
- (UPRouterOptions *)withPresentationStyle:(UIModalPresentationStyle)style;
/**
@remarks not idiomatic objective-c naming; wraps around setter
@return The same instance of `UPRouterOptions`, setting a `UIModalTransitionStyle` style.
@param style The `UIModalTransitionStyle` attached to the mapped `UIViewController`
*/
- (UPRouterOptions *)withTransitionStyle:(UIModalTransitionStyle)style;
/**
@remarks not idiomatic objective-c naming; wraps around setter
@return The same instance of `UPRouterOptions`, setting the defaultParams
@param defaultParams The default parameters which are passed when opening the URL
*/
- (UPRouterOptions *)forDefaultParams:(NSDictionary *)defaultParams;
/**
@remarks not idiomatic objective-c naming; wraps around setter
@return A new instance of `UPRouterOptions`, setting the `shouldOpenAsRootViewController` property to `YES`
*/
- (UPRouterOptions *)root;
Expand Down Expand Up @@ -190,6 +259,13 @@ typedef void (^RouterOpenCallback)(NSDictionary *params);
Pop to the last `UIViewController` mapped with the router; this will either dismiss the presented `UIViewController` (i.e. modal) or pop the top view controller in the navigationController.
@param animated Whether or not the transition is animated;
*/

- (void)popViewControllerFromRouterAnimated:(BOOL)animated;
/**
Pop to the last `UIViewController` mapped with the router; this will either dismiss the presented `UIViewController` (i.e. modal) or pop the top view controller in the navigationController.
@param animated Whether or not the transition is animated;
@remarks not idiomatic objective-c naming
*/
- (void)pop:(BOOL)animated;

///-------------------------------
Expand Down Expand Up @@ -257,6 +333,17 @@ typedef void (^RouterOpenCallback)(NSDictionary *params);
*/
- (void)open:(NSString *)url animated:(BOOL)animated;

/**
Triggers the appropriate functionality for a mapped URL, such as an anonymous function or opening a `UIViewController`
@param url The URL being opened (i.e. "users/16")
@param animated Whether or not `UIViewController` transitions are animated.
@param extraParams more paramters to pass in while opening a `UIViewController`; take priority over route-specific default parameters
@exception RouteNotFoundException Thrown if url does not have a valid mapping
@exception NavigationControllerNotProvided Thrown if url opens a `UIViewController` and navigationController has not been assigned
@exception RoutableInitializerNotFound Thrown if the mapped `UIViewController` instance does not implement -initWithRouterParams: or +allocWithRouterParams:
*/
- (void)open:(NSString *)url animated:(BOOL)animated extraParams:(NSDictionary *)extraParams;

/**
Get params of a given URL, simply return the params dictionary NOT using a block
@param url The URL being detected (i.e. "users/16")
Expand All @@ -276,6 +363,7 @@ typedef void (^RouterOpenCallback)(NSDictionary *params);

/**
A new instance of `UPRouter`, in case you want to use multiple routers in your app.
@remarks Unnecessary method; can use [[Routable alloc] init] instead
@return A new instance of `UPRouter`.
*/
+ (instancetype)newRouter;
Expand Down

0 comments on commit a9dd82e

Please sign in to comment.