From 350a5fcb1964bf16f8ceee669b7a6706020b8376 Mon Sep 17 00:00:00 2001 From: PhilZhang Date: Wed, 4 Mar 2015 19:26:06 +0800 Subject: [PATCH 1/9] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=AF=B9UIView=E4=BB=BB?= =?UTF-8?q?=E6=84=8F=E5=9C=86=E8=A7=92=E8=AE=BE=E7=BD=AE=E7=9A=84=E6=94=AF?= =?UTF-8?q?=E6=8C=81,=E5=BF=85=E9=A1=BB=E9=85=8D=E5=90=88=E8=AE=BE?= =?UTF-8?q?=E7=BD=AEborder-radius=E6=89=8D=E6=9C=89=E6=95=88=20=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E6=96=B9=E5=BC=8F=E5=A6=82=E4=B8=8B:=20#test=20=20=20?= =?UTF-8?q?=20=20=20=20=20=20{=20=20=20=20=20=20=20=20=20=20=20=20=20borde?= =?UTF-8?q?r-radius:10px;=20=20=20=20=20=20=20=20=20=20=20=20=20corners:TR?= =?UTF-8?q?;=20=20=20=20=20=20=20=20=20}?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 注: 这里corners支持的值为: TR --- UIRectCornerTopRight TL ---- UIRectCornerTopLeft BR --- UIRectCornerBottomRight BL --- UIRectCornerBottomLeft 可以任意组合,中间减号连接,组合方式如下 TR-TL-BR --- framework/mvc/view/css/Bee_UIStyleParser.h | 3 ++ framework/mvc/view/css/Bee_UIStyleParser.m | 42 +++++++++++++++++++ .../view/css/extension/UIView+BeeUIStyle.m | 27 +++++++++++- .../view/dom-capability/Bee_UICapability.h | 1 + .../view/dom-capability/Bee_UICapability.m | 5 +++ .../view/dom-layout/Bee_UILayoutBuilder_v1.m | 1 + 6 files changed, 78 insertions(+), 1 deletion(-) diff --git a/framework/mvc/view/css/Bee_UIStyleParser.h b/framework/mvc/view/css/Bee_UIStyleParser.h index 759f172..cffb452 100644 --- a/framework/mvc/view/css/Bee_UIStyleParser.h +++ b/framework/mvc/view/css/Bee_UIStyleParser.h @@ -131,6 +131,9 @@ - (UITextBorderStyle)parseTextBorderStyleWithKeys:(NSArray *)keys; - (UITextBorderStyle)parseTextBorderStyleWithKeys:(NSArray *)keys defaultValue:(UITextBorderStyle)defaultValue; +- (UIRectCorner)parseViewCornersStyleWithKeys:(NSArray *)keys; +- (UIRectCorner)parseViewCornersStyleWithKeys:(NSArray *)keys defaultValue:(UIRectCorner)defaultValue; + @end #endif // #if (TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR) diff --git a/framework/mvc/view/css/Bee_UIStyleParser.m b/framework/mvc/view/css/Bee_UIStyleParser.m index 1651d21..500db2b 100644 --- a/framework/mvc/view/css/Bee_UIStyleParser.m +++ b/framework/mvc/view/css/Bee_UIStyleParser.m @@ -824,6 +824,48 @@ - (UITextBorderStyle)parseTextBorderStyleWithKeys:(NSArray *)keys defaultValue:( return UITextBorderStyleNone; } +- (UIRectCorner)parseViewCornersStyleWithKeys:(NSArray *)keys +{ + return [self parseViewCornersStyleWithKeys:keys defaultValue:UIRectCornerAllCorners]; +} + +- (UIRectCorner)parseViewCornersStyleWithKeys:(NSArray *)keys defaultValue:(UIRectCorner)defaultValue +{ + NSString * value = [self parseStringWithKeys:keys]; + if ( nil == value ) + { + return defaultValue; + } + + NSMutableArray *values = [NSMutableArray arrayWithArray:[value componentsSeparatedByString:@"-"]]; + UIRectCorner corners = [self parseCornerByString:[values safeObjectAtIndex:0]]; + [values removeObjectAtIndex:0]; + for (NSString * str in values) { + corners = corners | [self parseCornerByString:str]; + } + return corners; +} + +- (UIRectCorner)parseCornerByString:(NSString *)str +{ + UIRectCorner corners; + if ( NSOrderedSame == [str compare:@"BL" options:NSCaseInsensitiveSearch] ) { + corners = UIRectCornerBottomLeft; + }else if (NSOrderedSame == [str compare:@"BR" options:NSCaseInsensitiveSearch]) + { + corners = UIRectCornerBottomRight; + }else if (NSOrderedSame == [str compare:@"TR" options:NSCaseInsensitiveSearch]) + { + corners = UIRectCornerTopRight; + }else if (NSOrderedSame == [str compare:@"TL" options:NSCaseInsensitiveSearch]){ + corners = UIRectCornerTopLeft; + }else + { + corners = UIRectCornerAllCorners; + } + return corners; +} + @end #endif // #if (TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR) diff --git a/framework/mvc/view/css/extension/UIView+BeeUIStyle.m b/framework/mvc/view/css/extension/UIView+BeeUIStyle.m index 5a44370..73859d3 100644 --- a/framework/mvc/view/css/extension/UIView+BeeUIStyle.m +++ b/framework/mvc/view/css/extension/UIView+BeeUIStyle.m @@ -649,13 +649,31 @@ - (void)applyViewBorder:(NSMutableDictionary *)properties self.layer.borderColor = [properties parseColorWithKeys:@[@"border-color"] defaultValue:[UIColor clearColor]].CGColor; self.layer.borderWidth = [properties parseFloatWithKeys:@[@"border-width"] defaultValue:0.0f]; self.layer.cornerRadius = [properties parseFloatWithKeys:@[@"border-radius", @"corner-radius"] defaultValue:0.0f]; - + if ( self.layer.cornerRadius > 0.0f ) { self.layer.masksToBounds = YES; } } +- (void)applyViewCorners:(NSMutableDictionary *)properties +{ + float cornerRadius = [properties parseFloatWithKeys:@[@"border-radius", @"corner-radius"] defaultValue:0.0f]; + if ( cornerRadius > 0.0f ) + { + self.layer.cornerRadius = 0; + self.layer.mask = nil; + UIRectCorner corners = [properties parseViewCornersStyleWithKeys:@[@"corners"]]; + UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds + byRoundingCorners:corners + cornerRadii:CGSizeMake(cornerRadius, 0.0)]; + CAShapeLayer *maskLayer = [CAShapeLayer layer]; + maskLayer.frame = self.bounds; + maskLayer.path = maskPath.CGPath; + self.layer.mask = maskLayer; + } +} + - (void)applyViewContent:(NSMutableDictionary *)properties { self.tag = [properties parseIntegerWithKeys:@[@"tag"] defaultValue:self.tag]; @@ -733,6 +751,13 @@ - (void)applyUIStyling:(NSDictionary *)properties [super applyUIStyling:propertiesCopy]; } +- (void)applyUICorners:(NSDictionary *)properties +{ + NSMutableDictionary * propertiesCopy = [NSMutableDictionary dictionaryWithDictionary:properties]; + + [self applyViewCorners:propertiesCopy]; +} + @end #endif // #if (TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR) diff --git a/framework/mvc/view/dom-capability/Bee_UICapability.h b/framework/mvc/view/dom-capability/Bee_UICapability.h index 0584271..c8482e4 100644 --- a/framework/mvc/view/dom-capability/Bee_UICapability.h +++ b/framework/mvc/view/dom-capability/Bee_UICapability.h @@ -113,6 +113,7 @@ - (BOOL)supportForUIStyling; - (void)applyUIStyling:(NSDictionary *)properties; +- (void)applyUICorners:(NSDictionary *)properties; // resource loading? diff --git a/framework/mvc/view/dom-capability/Bee_UICapability.m b/framework/mvc/view/dom-capability/Bee_UICapability.m index de5ee84..516aa8e 100644 --- a/framework/mvc/view/dom-capability/Bee_UICapability.m +++ b/framework/mvc/view/dom-capability/Bee_UICapability.m @@ -112,6 +112,11 @@ - (void)applyUIStyling:(NSDictionary *)properties // WARN( @"unrecognized styles for '%@':\n%@", [[self class] description], properties ); } +- (void)applyUICorners:(NSDictionary *)properties +{ + +} + + (BOOL)supportForUIResourceLoading { return NO; diff --git a/framework/mvc/view/dom-layout/Bee_UILayoutBuilder_v1.m b/framework/mvc/view/dom-layout/Bee_UILayoutBuilder_v1.m index 6a38373..22b51cd 100644 --- a/framework/mvc/view/dom-layout/Bee_UILayoutBuilder_v1.m +++ b/framework/mvc/view/dom-layout/Bee_UILayoutBuilder_v1.m @@ -831,6 +831,7 @@ - (void)layoutTree:(CGRect)bound // viewFrame.size.width, viewFrame.size.height ); view.frame = viewFrame; + [view applyUICorners:view.UIStyle.properties]; } } From ced45c6f8c200e5b0debbe93df034410eb6c7348 Mon Sep 17 00:00:00 2001 From: PhilZhang Date: Thu, 5 Mar 2015 10:44:04 +0800 Subject: [PATCH 2/9] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E5=88=B7=E6=96=B0?= =?UTF-8?q?=E5=AF=BC=E8=87=B4Corners=E6=A0=B7=E5=BC=8F=E5=A4=B1=E6=95=88?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- framework/mvc/view/css/extension/UIView+BeeUIStyle.m | 6 ++++++ framework/mvc/view/dom-query/extension/BeeUIQuery+CSS.m | 1 + .../example/view_iPhone/templates/TeamBoardCell_iPhone.xml | 5 ++++- projects/scaffold/scaffold/SchemaGenerator.m | 2 +- 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/framework/mvc/view/css/extension/UIView+BeeUIStyle.m b/framework/mvc/view/css/extension/UIView+BeeUIStyle.m index 73859d3..ce0c299 100644 --- a/framework/mvc/view/css/extension/UIView+BeeUIStyle.m +++ b/framework/mvc/view/css/extension/UIView+BeeUIStyle.m @@ -648,6 +648,9 @@ - (void)applyViewBorder:(NSMutableDictionary *)properties self.layer.borderColor = [properties parseColorWithKeys:@[@"border-color"] defaultValue:[UIColor clearColor]].CGColor; self.layer.borderWidth = [properties parseFloatWithKeys:@[@"border-width"] defaultValue:0.0f]; + if ([properties stringOfAny:@[@"corners"] removeAll:false] != nil) { + return; + } self.layer.cornerRadius = [properties parseFloatWithKeys:@[@"border-radius", @"corner-radius"] defaultValue:0.0f]; if ( self.layer.cornerRadius > 0.0f ) @@ -658,6 +661,9 @@ - (void)applyViewBorder:(NSMutableDictionary *)properties - (void)applyViewCorners:(NSMutableDictionary *)properties { + if ([properties stringOfAny:@[@"corners"] removeAll:false] == nil) { + return; + } float cornerRadius = [properties parseFloatWithKeys:@[@"border-radius", @"corner-radius"] defaultValue:0.0f]; if ( cornerRadius > 0.0f ) { diff --git a/framework/mvc/view/dom-query/extension/BeeUIQuery+CSS.m b/framework/mvc/view/dom-query/extension/BeeUIQuery+CSS.m index 07a47db..86532a3 100644 --- a/framework/mvc/view/dom-query/extension/BeeUIQuery+CSS.m +++ b/framework/mvc/view/dom-query/extension/BeeUIQuery+CSS.m @@ -109,6 +109,7 @@ - (BeeUIQueryObjectBlockSS)ATTR [v addStyleProperties:properties]; [v mergeStyle]; [v applyStyle]; + [v applyUICorners:v.UIStyle.properties]; } } diff --git a/projects/example/example/view_iPhone/templates/TeamBoardCell_iPhone.xml b/projects/example/example/view_iPhone/templates/TeamBoardCell_iPhone.xml index 6b17112..0a4c1ee 100644 --- a/projects/example/example/view_iPhone/templates/TeamBoardCell_iPhone.xml +++ b/projects/example/example/view_iPhone/templates/TeamBoardCell_iPhone.xml @@ -301,7 +301,10 @@ Love coding, also skilled in HTML, CSS and JS. margin-top: 2px; margin-left: 10px; background-color: #999; - border-radius: 8px; + border-radius: 20px; + border-color:#000; + border-width:2px; + corners:BL-BR-TL; } .profile-right-wrapper { diff --git a/projects/scaffold/scaffold/SchemaGenerator.m b/projects/scaffold/scaffold/SchemaGenerator.m index 081f91d..0e7b037 100644 --- a/projects/scaffold/scaffold/SchemaGenerator.m +++ b/projects/scaffold/scaffold/SchemaGenerator.m @@ -2282,7 +2282,7 @@ - (NSString *)mm } } } - code.LINE( @" self.HTTP_%@( requestURI ).PARAM(@\"json\", [self.req objectToDictionary] )%@;", [self.method uppercaseString], fileListParam ); + code.LINE( @" self.HTTP_%@( requestURI ).PARAM( [self.req objectToDictionary] )%@;", [self.method uppercaseString], fileListParam ); } } else From 83f3e852ab28eab3782a1864b7c7d8f8b431ae41 Mon Sep 17 00:00:00 2001 From: PhilZhang Date: Thu, 5 Mar 2015 10:51:10 +0800 Subject: [PATCH 3/9] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- framework/mvc/view/css/extension/UIView+BeeUIStyle.m | 1 + framework/mvc/view/dom-query/extension/BeeUIQuery+CSS.m | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/mvc/view/css/extension/UIView+BeeUIStyle.m b/framework/mvc/view/css/extension/UIView+BeeUIStyle.m index ce0c299..cf5991a 100644 --- a/framework/mvc/view/css/extension/UIView+BeeUIStyle.m +++ b/framework/mvc/view/css/extension/UIView+BeeUIStyle.m @@ -430,6 +430,7 @@ - (void)applyStyle if ( self.UIStyle ) { [self applyUIStyling:self.UIStyle.properties]; + [self applyUICorners:self.UIStyle.properties]; } } diff --git a/framework/mvc/view/dom-query/extension/BeeUIQuery+CSS.m b/framework/mvc/view/dom-query/extension/BeeUIQuery+CSS.m index 86532a3..07a47db 100644 --- a/framework/mvc/view/dom-query/extension/BeeUIQuery+CSS.m +++ b/framework/mvc/view/dom-query/extension/BeeUIQuery+CSS.m @@ -109,7 +109,6 @@ - (BeeUIQueryObjectBlockSS)ATTR [v addStyleProperties:properties]; [v mergeStyle]; [v applyStyle]; - [v applyUICorners:v.UIStyle.properties]; } } From 1519110628bfafbfb1b3e3cfe2920d7282912103 Mon Sep 17 00:00:00 2001 From: PhilZhang Date: Fri, 6 Mar 2015 12:52:29 +0800 Subject: [PATCH 4/9] no message --- projects/scaffold/scaffold/SchemaGenerator.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/scaffold/scaffold/SchemaGenerator.m b/projects/scaffold/scaffold/SchemaGenerator.m index 0e7b037..57d3052 100644 --- a/projects/scaffold/scaffold/SchemaGenerator.m +++ b/projects/scaffold/scaffold/SchemaGenerator.m @@ -2282,7 +2282,7 @@ - (NSString *)mm } } } - code.LINE( @" self.HTTP_%@( requestURI ).PARAM( [self.req objectToDictionary] )%@;", [self.method uppercaseString], fileListParam ); + code.LINE( @" self.HTTP_%@( requestURI ).PARAM(@\"json\", [self.req objectToDictionary] )%@;", [self.method uppercaseString], fileListParam ); } } else From 119613e1c519ddac70992a174981e9db08046653 Mon Sep 17 00:00:00 2001 From: PhilZhang Date: Mon, 9 Mar 2015 11:05:33 +0800 Subject: [PATCH 5/9] =?UTF-8?q?corners=E6=94=AF=E6=8C=81=E7=BC=A9=E5=86=99?= =?UTF-8?q?=E5=92=8C=E5=85=A8=E7=A7=B0=E4=B8=A4=E7=A7=8D=20BL=20BottomLeft?= =?UTF-8?q?=20BR=20BottomRight=20TL=20TopLeft=20TR=20TopRight?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- framework/mvc/view/css/Bee_UIStyleParser.m | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/framework/mvc/view/css/Bee_UIStyleParser.m b/framework/mvc/view/css/Bee_UIStyleParser.m index 500db2b..28a374b 100644 --- a/framework/mvc/view/css/Bee_UIStyleParser.m +++ b/framework/mvc/view/css/Bee_UIStyleParser.m @@ -849,15 +849,15 @@ - (UIRectCorner)parseViewCornersStyleWithKeys:(NSArray *)keys defaultValue:(UIRe - (UIRectCorner)parseCornerByString:(NSString *)str { UIRectCorner corners; - if ( NSOrderedSame == [str compare:@"BL" options:NSCaseInsensitiveSearch] ) { + if ( [str matchAnyOf:@[@"BL", @"BottomLeft"]] ) { corners = UIRectCornerBottomLeft; - }else if (NSOrderedSame == [str compare:@"BR" options:NSCaseInsensitiveSearch]) + }else if ( [str matchAnyOf:@[@"BR", @"BottomRight"]] ) { corners = UIRectCornerBottomRight; - }else if (NSOrderedSame == [str compare:@"TR" options:NSCaseInsensitiveSearch]) + }else if ( [str matchAnyOf:@[@"TR", @"TopRight"]] ) { corners = UIRectCornerTopRight; - }else if (NSOrderedSame == [str compare:@"TL" options:NSCaseInsensitiveSearch]){ + }else if ( [str matchAnyOf:@[@"TL", @"TopLeft"]] ){ corners = UIRectCornerTopLeft; }else { From 1f6980557b4fe75ca75fe3cb8fc7741bef6006f6 Mon Sep 17 00:00:00 2001 From: PhilZhang Date: Mon, 9 Mar 2015 11:13:52 +0800 Subject: [PATCH 6/9] no message --- .../view/css/extension/UIView+BeeUIStyle.m | 40 ++++++++----------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/framework/mvc/view/css/extension/UIView+BeeUIStyle.m b/framework/mvc/view/css/extension/UIView+BeeUIStyle.m index cf5991a..ad4a3b4 100644 --- a/framework/mvc/view/css/extension/UIView+BeeUIStyle.m +++ b/framework/mvc/view/css/extension/UIView+BeeUIStyle.m @@ -660,27 +660,6 @@ - (void)applyViewBorder:(NSMutableDictionary *)properties } } -- (void)applyViewCorners:(NSMutableDictionary *)properties -{ - if ([properties stringOfAny:@[@"corners"] removeAll:false] == nil) { - return; - } - float cornerRadius = [properties parseFloatWithKeys:@[@"border-radius", @"corner-radius"] defaultValue:0.0f]; - if ( cornerRadius > 0.0f ) - { - self.layer.cornerRadius = 0; - self.layer.mask = nil; - UIRectCorner corners = [properties parseViewCornersStyleWithKeys:@[@"corners"]]; - UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds - byRoundingCorners:corners - cornerRadii:CGSizeMake(cornerRadius, 0.0)]; - CAShapeLayer *maskLayer = [CAShapeLayer layer]; - maskLayer.frame = self.bounds; - maskLayer.path = maskPath.CGPath; - self.layer.mask = maskLayer; - } -} - - (void)applyViewContent:(NSMutableDictionary *)properties { self.tag = [properties parseIntegerWithKeys:@[@"tag"] defaultValue:self.tag]; @@ -740,7 +719,6 @@ - (void)applyViewShadow:(NSMutableDictionary *)properties self.layer.shadowOffset = [properties parseSizeWithKeys:@[@"shadow-offset"] defaultValue:CGSizeZero]; self.layer.shadowOpacity = [properties parseFloatWithKeys:@[@"shadow-opacity"] defaultValue:1.0f]; self.layer.shadowRadius = [properties parseFloatWithKeys:@[@"shadow-radius"] defaultValue:1.0f]; -// self.layer.shadowPath = [UIBezierPath bezierPathWithRect:self.bounds].CGPath; } - (void)applyUIStyling:(NSDictionary *)properties @@ -762,7 +740,23 @@ - (void)applyUICorners:(NSDictionary *)properties { NSMutableDictionary * propertiesCopy = [NSMutableDictionary dictionaryWithDictionary:properties]; - [self applyViewCorners:propertiesCopy]; + if ([propertiesCopy stringOfAny:@[@"corners"] removeAll:false] == nil) { + return; + } + float cornerRadius = [propertiesCopy parseFloatWithKeys:@[@"border-radius", @"corner-radius"] defaultValue:0.0f]; + if ( cornerRadius > 0.0f ) + { + self.layer.cornerRadius = 0; + self.layer.mask = nil; + UIRectCorner corners = [propertiesCopy parseViewCornersStyleWithKeys:@[@"corners"]]; + UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds + byRoundingCorners:corners + cornerRadii:CGSizeMake(cornerRadius, 0.0)]; + CAShapeLayer *maskLayer = [CAShapeLayer layer]; + maskLayer.frame = self.bounds; + maskLayer.path = maskPath.CGPath; + self.layer.mask = maskLayer; + } } @end From 69165b3c5673a18284cc6ee6fbada439e01928b5 Mon Sep 17 00:00:00 2001 From: PhilZhang Date: Wed, 11 Mar 2015 14:27:35 +0800 Subject: [PATCH 7/9] =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=BB=E6=84=8F?= =?UTF-8?q?=E5=A4=9A=E4=B8=AAserver=20url?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- projects/scaffold/scaffold/SchemaGenerator.m | 134 +++++++++++-------- 1 file changed, 80 insertions(+), 54 deletions(-) diff --git a/projects/scaffold/scaffold/SchemaGenerator.m b/projects/scaffold/scaffold/SchemaGenerator.m index 57d3052..5f48019 100644 --- a/projects/scaffold/scaffold/SchemaGenerator.m +++ b/projects/scaffold/scaffold/SchemaGenerator.m @@ -3024,18 +3024,25 @@ - (NSString *)h code.LINE( [NSString stringWithFormat:@"AS_SINGLETON( %@ServerConfig )", prefix] ); code.LINE( nil ); - code.LINE( @"AS_INT( CONFIG_DEVELOPMENT )" ); - code.LINE( @"AS_INT( CONFIG_TEST )" ); - code.LINE( @"AS_INT( CONFIG_PRODUCTION )" ); + for (NSString *key in self.server) { + code.LINE( [NSString stringWithFormat:@"AS_STRING( CONFIG_%@ )", [key uppercaseString] ] ); + } + +// code.LINE( @"AS_INT( CONFIG_DEVELOPMENT )" ); +// code.LINE( @"AS_INT( CONFIG_TEST )" ); +// code.LINE( @"AS_INT( CONFIG_PRODUCTION )" ); code.LINE( nil ); - code.LINE( @"@property (nonatomic, assign) NSUInteger config;" ); + code.LINE( @"@property (nonatomic, assign) NSString* config;" ); code.LINE( nil ); code.LINE( @"@property (nonatomic, readonly) NSString * url;" ); - code.LINE( @"@property (nonatomic, readonly) NSString * testUrl;" ); - code.LINE( @"@property (nonatomic, readonly) NSString * productionUrl;" ); - code.LINE( @"@property (nonatomic, readonly) NSString * developmentUrl;" ); + for (NSString *key in self.server) { + code.LINE( [NSString stringWithFormat:@"@property (nonatomic, readonly) NSString * %@Url;", key ] ); + } +// code.LINE( @"@property (nonatomic, readonly) NSString * testUrl;" ); +// code.LINE( @"@property (nonatomic, readonly) NSString * productionUrl;" ); +// code.LINE( @"@property (nonatomic, readonly) NSString * developmentUrl;" ); code.LINE( nil ); code.LINE( @"@end" ); @@ -3070,10 +3077,6 @@ - (NSString *)mm code.LINE( [controller mm] ); } - NSString * dev = [self.server objectForKey:@"development"]; - NSString * tst = [self.server objectForKey:@"test"]; - NSString * pro = [self.server objectForKey:@"production"]; - code.LINE( @"#pragma mark - config" ); code.LINE( nil ); @@ -3083,61 +3086,84 @@ - (NSString *)mm code.LINE( [NSString stringWithFormat:@"DEF_SINGLETON( %@ServerConfig )", prefix] ); code.LINE( nil ); - code.LINE( @"DEF_INT( CONFIG_DEVELOPMENT, 0 )" ); - code.LINE( @"DEF_INT( CONFIG_TEST, 1 )" ); - code.LINE( @"DEF_INT( CONFIG_PRODUCTION, 2 )" ); + for (NSString *key in self.server) { + code.LINE( [NSString stringWithFormat:@"DEF_STRING( CONFIG_%@, @\"%@\" )", [key uppercaseString], key ] ); + } +// code.LINE( @"DEF_INT( CONFIG_DEVELOPMENT, 0 )" ); +// code.LINE( @"DEF_INT( CONFIG_TEST, 1 )" ); +// code.LINE( @"DEF_INT( CONFIG_PRODUCTION, 2 )" ); code.LINE( nil ); code.LINE( @"@synthesize config = _config;" ); - code.LINE( @"@dynamic url;" ); - code.LINE( @"@dynamic testUrl;" ); - code.LINE( @"@dynamic productionUrl;" ); - code.LINE( @"@dynamic developmentUrl;" ); + code.LINE( @"@dynamic url;" ); + for (NSString *key in self.server) { + code.LINE( [NSString stringWithFormat:@"@dynamic %@Url;", key] ); + } + +// code.LINE( @"@dynamic testUrl;" ); +// code.LINE( @"@dynamic productionUrl;" ); +// code.LINE( @"@dynamic developmentUrl;" ); code.LINE( nil ); code.LINE( @"- (NSString *)url" ); code.LINE( @"{" ); code.LINE( @" NSString * host = nil;" ); code.LINE( nil ); - code.LINE( @" if ( self.CONFIG_DEVELOPMENT == self.config )" ); - code.LINE( @" {" ); - code.LINE( @" host = self.developmentUrl;" ); - code.LINE( @" }" ); - code.LINE( @" else if ( self.CONFIG_TEST == self.config )" ); - code.LINE( @" {" ); - code.LINE( @" host = self.testUrl;" ); - code.LINE( @" }" ); - code.LINE( @" else" ); - code.LINE( @" {" ); - code.LINE( @" host = self.productionUrl;" ); - code.LINE( @" }" ); - code.LINE( nil ); - code.LINE( @" if ( NO == [host hasPrefix:@\"http://\"] && NO == [host hasPrefix:@\"https://\"] )" ); - code.LINE( @" {" ); - code.LINE( @" host = [@\"http://\" stringByAppendingString:host];" ); - code.LINE( @" }" ); - code.LINE( nil ); - code.LINE( @" return host;" ); +// code.LINE( @" if ( self.CONFIG_DEVELOPMENT == self.config )" ); +// code.LINE( @" {" ); +// code.LINE( @" host = self.developmentUrl;" ); +// code.LINE( @" }" ); +// code.LINE( @" else if ( self.CONFIG_TEST == self.config )" ); +// code.LINE( @" {" ); +// code.LINE( @" host = self.testUrl;" ); +// code.LINE( @" }" ); +// code.LINE( @" else" ); +// code.LINE( @" {" ); +// code.LINE( @" host = self.productionUrl;" ); +// code.LINE( @" }" ); + for (NSString *key in self.server) { + code.LINE( [NSString stringWithFormat:@" if ( self.CONFIG_%@ == self.config )", [key uppercaseString]] ); + code.LINE( @" {" ); + code.LINE( [NSString stringWithFormat:@" host = self.%@Url;", key] ); + code.LINE( nil ); + code.LINE( @" if ( NO == [host hasPrefix:@\"http://\"] && NO == [host hasPrefix:@\"https://\"] )" ); + code.LINE( @" {" ); + code.LINE( @" host = [@\"http://\" stringByAppendingString:host];" ); + code.LINE( @" }" ); + code.LINE( nil ); + code.LINE( @" return host;" ); + code.LINE( @" }" ); + } + code.LINE( @" return nil;" ); code.LINE( @"}" ); code.LINE( nil ); - code.LINE( @"- (NSString *)developmentUrl" ); - code.LINE( @"{" ); - code.LINE( [NSString stringWithFormat:@" return @\"%@\";", dev ? dev : @""] ); - code.LINE( @"}" ); - code.LINE( nil ); - - code.LINE( @"- (NSString *)testUrl" ); - code.LINE( @"{" ); - code.LINE( [NSString stringWithFormat:@" return @\"%@\";", tst ? tst : @""] ); - code.LINE( @"}" ); - code.LINE( nil ); - - code.LINE( @"- (NSString *)productionUrl" ); - code.LINE( @"{" ); - code.LINE( [NSString stringWithFormat:@" return @\"%@\";", pro ? pro : @""] ); - code.LINE( @"}" ); - code.LINE( nil ); + NSString *url = nil; + for (NSString *key in self.server) { + url = [self.server objectForKey:key]; + code.LINE( [NSString stringWithFormat:@"- (NSString *)%@Url", key] ); + code.LINE( @"{" ); + code.LINE( [NSString stringWithFormat:@" return @\"%@\";", url ? url : @""] ); + code.LINE( @"}" ); + code.LINE( nil ); + } +// code.LINE( @"- (NSString *)developmentUrl" ); +// code.LINE( @"{" ); +// code.LINE( [NSString stringWithFormat:@" return @\"%@\";", dev ? dev : @""] ); +// code.LINE( @"}" ); +// code.LINE( nil ); +// +// code.LINE( @"- (NSString *)testUrl" ); +// code.LINE( @"{" ); +// code.LINE( [NSString stringWithFormat:@" return @\"%@\";", tst ? tst : @""] ); +// code.LINE( @"}" ); +// code.LINE( nil ); +// +// code.LINE( @"- (NSString *)productionUrl" ); +// code.LINE( @"{" ); +// code.LINE( [NSString stringWithFormat:@" return @\"%@\";", pro ? pro : @""] ); +// code.LINE( @"}" ); +// code.LINE( nil ); code.LINE( @"@end" ); code.LINE( nil ); From 657dc3da371c83873994c94ac17ed0e64ee57717 Mon Sep 17 00:00:00 2001 From: PhilZhang Date: Fri, 27 Mar 2015 13:24:10 +0800 Subject: [PATCH 8/9] "server": { "development":"http://10.10.1.3", "production":"http://10.10.1.4", "developmentcn":"http://10.10.1.5", "file": { "develope":"http://10.10.1.1", "production":"http://10.10.1.2" } }, MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 对多种服务器url的支持 比如,正常的interface服务器,文件服务器 --- projects/scaffold/scaffold/SchemaGenerator.m | 197 ++++++++++++------- 1 file changed, 123 insertions(+), 74 deletions(-) diff --git a/projects/scaffold/scaffold/SchemaGenerator.m b/projects/scaffold/scaffold/SchemaGenerator.m index 5f48019..0278378 100644 --- a/projects/scaffold/scaffold/SchemaGenerator.m +++ b/projects/scaffold/scaffold/SchemaGenerator.m @@ -3024,26 +3024,33 @@ - (NSString *)h code.LINE( [NSString stringWithFormat:@"AS_SINGLETON( %@ServerConfig )", prefix] ); code.LINE( nil ); + NSMutableArray *urlNames = [[NSMutableArray alloc] init]; + for (NSString *key in self.server) { - code.LINE( [NSString stringWithFormat:@"AS_STRING( CONFIG_%@ )", [key uppercaseString] ] ); + id value = [self.server objectForKey:key]; + if ([value isKindOfClass:[NSDictionary class]]) { + [urlNames addObject:key]; + for (NSString *key1 in value) { + code.LINE( [NSString stringWithFormat:@"AS_STRING( %@_%@ )", [key uppercaseString], [key1 uppercaseString]]); + } + }else + { + code.LINE( [NSString stringWithFormat:@"AS_STRING( CONFIG_%@ )", [key uppercaseString]]); + } } - -// code.LINE( @"AS_INT( CONFIG_DEVELOPMENT )" ); -// code.LINE( @"AS_INT( CONFIG_TEST )" ); -// code.LINE( @"AS_INT( CONFIG_PRODUCTION )" ); - code.LINE( nil ); + code.LINE( nil ); - code.LINE( @"@property (nonatomic, assign) NSString* config;" ); - code.LINE( nil ); - - code.LINE( @"@property (nonatomic, readonly) NSString * url;" ); - for (NSString *key in self.server) { - code.LINE( [NSString stringWithFormat:@"@property (nonatomic, readonly) NSString * %@Url;", key ] ); + if (urlNames.count) { + for (int i = 0; i < urlNames.count; i ++) { + code.LINE( [NSString stringWithFormat:@"@property (nonatomic, assign) NSString * Config%@;", [urlNames safeObjectAtIndex:i]] ); + code.LINE( [NSString stringWithFormat:@"@property (nonatomic, readonly) NSString * Url%@;", [urlNames safeObjectAtIndex:i]] ); + code.LINE( nil ); + } } -// code.LINE( @"@property (nonatomic, readonly) NSString * testUrl;" ); -// code.LINE( @"@property (nonatomic, readonly) NSString * productionUrl;" ); -// code.LINE( @"@property (nonatomic, readonly) NSString * developmentUrl;" ); - code.LINE( nil ); + + code.LINE( @"@property (nonatomic, assign) NSString* config;" ); + code.LINE( @"@property (nonatomic, readonly) NSString * url;" ); + code.LINE( nil ); code.LINE( @"@end" ); code.LINE( nil ); @@ -3076,52 +3083,95 @@ - (NSString *)mm { code.LINE( [controller mm] ); } - - code.LINE( @"#pragma mark - config" ); - code.LINE( nil ); - + + code.LINE( @"#pragma mark - config" ); + code.LINE( @"@interface ServerConfig()" ); + code.LINE( nil ); + + NSMutableArray *urlNames = [[NSMutableArray alloc] init]; + + for (NSString *key in self.server) { + id value = [self.server objectForKey:key]; + if ([value isKindOfClass:[NSDictionary class]]) { + [urlNames addObject:key]; + for (NSString *key1 in value) { + code.LINE( [NSString stringWithFormat:@"@property (nonatomic, readonly) NSString * %@_%@_Url;", key, key1]); + } + }else + { + code.LINE( [NSString stringWithFormat:@"@property (nonatomic, readonly) NSString * %@Url;", key]); + } + } + code.LINE( nil ); + code.LINE( @"@end" ); + code.LINE( nil ); + + code.LINE( @"#pragma mark - config" ); + code.LINE( nil ); code.LINE( [NSString stringWithFormat:@"@implementation %@ServerConfig", prefix] ); code.LINE( nil ); code.LINE( [NSString stringWithFormat:@"DEF_SINGLETON( %@ServerConfig )", prefix] ); code.LINE( nil ); - + for (NSString *key in self.server) { - code.LINE( [NSString stringWithFormat:@"DEF_STRING( CONFIG_%@, @\"%@\" )", [key uppercaseString], key ] ); + id value = [self.server objectForKey:key]; + if ([value isKindOfClass:[NSDictionary class]]) { + for (NSString *key1 in value) { + code.LINE( [NSString stringWithFormat:@"DEF_STRING( %@_%@, @\"%@_%@\")", [key uppercaseString], [key1 uppercaseString], [key uppercaseString], [key1 uppercaseString]]); + } + }else + { + code.LINE( [NSString stringWithFormat:@"DEF_STRING( CONFIG_%@, @\"%@\" )", [key uppercaseString], [key uppercaseString]]); + } } -// code.LINE( @"DEF_INT( CONFIG_DEVELOPMENT, 0 )" ); -// code.LINE( @"DEF_INT( CONFIG_TEST, 1 )" ); -// code.LINE( @"DEF_INT( CONFIG_PRODUCTION, 2 )" ); + code.LINE( nil ); - code.LINE( @"@synthesize config = _config;" ); - code.LINE( @"@dynamic url;" ); - for (NSString *key in self.server) { - code.LINE( [NSString stringWithFormat:@"@dynamic %@Url;", key] ); + if (urlNames.count) { + for (int i = 0; i < urlNames.count; i ++) { + code.LINE( [NSString stringWithFormat:@"@synthesize Config%@ = _Config%@;", [urlNames safeObjectAtIndex:i], [urlNames safeObjectAtIndex:i] ] ); + code.LINE( [NSString stringWithFormat:@"@synthesize Url%@ = _Url%@;", [urlNames safeObjectAtIndex:i], [urlNames safeObjectAtIndex:i] ] ); + code.LINE( nil ); + } } + code.LINE( @"@synthesize config;" ); + code.LINE( @"@synthesize url;" ); + code.LINE( nil ); -// code.LINE( @"@dynamic testUrl;" ); -// code.LINE( @"@dynamic productionUrl;" ); -// code.LINE( @"@dynamic developmentUrl;" ); code.LINE( nil ); - code.LINE( @"- (NSString *)url" ); - code.LINE( @"{" ); - code.LINE( @" NSString * host = nil;" ); - code.LINE( nil ); -// code.LINE( @" if ( self.CONFIG_DEVELOPMENT == self.config )" ); -// code.LINE( @" {" ); -// code.LINE( @" host = self.developmentUrl;" ); -// code.LINE( @" }" ); -// code.LINE( @" else if ( self.CONFIG_TEST == self.config )" ); -// code.LINE( @" {" ); -// code.LINE( @" host = self.testUrl;" ); -// code.LINE( @" }" ); -// code.LINE( @" else" ); -// code.LINE( @" {" ); -// code.LINE( @" host = self.productionUrl;" ); -// code.LINE( @" }" ); + if (urlNames.count) { + for (int i = 0; i < urlNames.count; i ++) { + code.LINE( [NSString stringWithFormat:@"- (NSString *)Url%@", [urlNames safeObjectAtIndex:i]] ); + code.LINE( @"{" ); + code.LINE( @" NSString * host = nil;" ); + code.LINE( nil ); + id value = [self.server objectForKey:[urlNames safeObjectAtIndex:i]]; + for (NSString *key in value) { + code.LINE( [NSString stringWithFormat:@" if ( self.%@_%@ == self.Config%@ )", [[urlNames safeObjectAtIndex:i] uppercaseString], [key uppercaseString], [urlNames safeObjectAtIndex:i]] ); + code.LINE( @" {" ); + code.LINE( [NSString stringWithFormat:@" host = self.%@_%@_Url;", [urlNames safeObjectAtIndex:i], key] ); + code.LINE( @" }" ); + } + code.LINE( @" if ( NO == [host hasPrefix:@\"http://\"] && NO == [host hasPrefix:@\"https://\"] )" ); + code.LINE( @" {" ); + code.LINE( @" host = [@\"http://\" stringByAppendingString:host];" ); + code.LINE( @" }" ); + code.LINE( nil ); + code.LINE( @" return host;" ); + code.LINE( @"}" ); + } + } + code.LINE( nil ); + code.LINE( @"- (NSString *)url" ); + code.LINE( @"{" ); + code.LINE( @" NSString * host = nil;" ); + code.LINE( nil ); for (NSString *key in self.server) { + if ([[self.server objectForKey:key] isKindOfClass:[NSDictionary class]]) { + continue; + } code.LINE( [NSString stringWithFormat:@" if ( self.CONFIG_%@ == self.config )", [key uppercaseString]] ); code.LINE( @" {" ); code.LINE( [NSString stringWithFormat:@" host = self.%@Url;", key] ); @@ -3134,37 +3184,36 @@ - (NSString *)mm code.LINE( @" return host;" ); code.LINE( @" }" ); } - code.LINE( @" return nil;" ); - code.LINE( @"}" ); + code.LINE( @" return nil;" ); + code.LINE( @"}" ); + code.LINE( nil ); + + NSString *url = nil; for (NSString *key in self.server) { - url = [self.server objectForKey:key]; - code.LINE( [NSString stringWithFormat:@"- (NSString *)%@Url", key] ); - code.LINE( @"{" ); - code.LINE( [NSString stringWithFormat:@" return @\"%@\";", url ? url : @""] ); - code.LINE( @"}" ); - code.LINE( nil ); + id value = [self.server objectForKey:key]; + if ([value isKindOfClass:[NSDictionary class]]) { + for (NSString *key1 in value) { + url = [value objectForKey:key1]; + code.LINE( [NSString stringWithFormat:@"- (NSString *)%@_%@_Url", key, key1] ); + code.LINE( @"{" ); + code.LINE( [NSString stringWithFormat:@" return @\"%@\";", url ? url : @""] ); + code.LINE( @"}" ); + code.LINE( nil ); + } + }else + { + url = [self.server objectForKey:key]; + code.LINE( [NSString stringWithFormat:@"- (NSString *)%@Url", key] ); + code.LINE( @"{" ); + code.LINE( [NSString stringWithFormat:@" return @\"%@\";", url ? url : @""] ); + code.LINE( @"}" ); + code.LINE( nil ); + } } -// code.LINE( @"- (NSString *)developmentUrl" ); -// code.LINE( @"{" ); -// code.LINE( [NSString stringWithFormat:@" return @\"%@\";", dev ? dev : @""] ); -// code.LINE( @"}" ); -// code.LINE( nil ); -// -// code.LINE( @"- (NSString *)testUrl" ); -// code.LINE( @"{" ); -// code.LINE( [NSString stringWithFormat:@" return @\"%@\";", tst ? tst : @""] ); -// code.LINE( @"}" ); -// code.LINE( nil ); -// -// code.LINE( @"- (NSString *)productionUrl" ); -// code.LINE( @"{" ); -// code.LINE( [NSString stringWithFormat:@" return @\"%@\";", pro ? pro : @""] ); -// code.LINE( @"}" ); -// code.LINE( nil ); - + code.LINE( @"@end" ); code.LINE( nil ); } From 512c4849e90bdd0eccf5a3e45a09baa07ecf7615 Mon Sep 17 00:00:00 2001 From: PhilZhang Date: Fri, 27 Mar 2015 13:31:46 +0800 Subject: [PATCH 9/9] =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E5=8C=96=E7=94=9F?= =?UTF-8?q?=E6=88=90=E7=9A=84=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- projects/scaffold/scaffold/SchemaGenerator.m | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/projects/scaffold/scaffold/SchemaGenerator.m b/projects/scaffold/scaffold/SchemaGenerator.m index 0278378..dceb1ea 100644 --- a/projects/scaffold/scaffold/SchemaGenerator.m +++ b/projects/scaffold/scaffold/SchemaGenerator.m @@ -3031,7 +3031,7 @@ - (NSString *)h if ([value isKindOfClass:[NSDictionary class]]) { [urlNames addObject:key]; for (NSString *key1 in value) { - code.LINE( [NSString stringWithFormat:@"AS_STRING( %@_%@ )", [key uppercaseString], [key1 uppercaseString]]); + code.LINE( [NSString stringWithFormat:@"AS_STRING( CONFIG_%@_%@ )", [key uppercaseString], [key1 uppercaseString]]); } }else { @@ -3118,7 +3118,7 @@ - (NSString *)mm id value = [self.server objectForKey:key]; if ([value isKindOfClass:[NSDictionary class]]) { for (NSString *key1 in value) { - code.LINE( [NSString stringWithFormat:@"DEF_STRING( %@_%@, @\"%@_%@\")", [key uppercaseString], [key1 uppercaseString], [key uppercaseString], [key1 uppercaseString]]); + code.LINE( [NSString stringWithFormat:@"DEF_STRING( CONFIG_%@_%@, @\"%@_%@\")", [key uppercaseString], [key1 uppercaseString], [key uppercaseString], [key1 uppercaseString]]); } }else { @@ -3149,7 +3149,7 @@ - (NSString *)mm code.LINE( nil ); id value = [self.server objectForKey:[urlNames safeObjectAtIndex:i]]; for (NSString *key in value) { - code.LINE( [NSString stringWithFormat:@" if ( self.%@_%@ == self.Config%@ )", [[urlNames safeObjectAtIndex:i] uppercaseString], [key uppercaseString], [urlNames safeObjectAtIndex:i]] ); + code.LINE( [NSString stringWithFormat:@" if ( self.CONFIG_%@_%@ == self.Config%@ )", [[urlNames safeObjectAtIndex:i] uppercaseString], [key uppercaseString], [urlNames safeObjectAtIndex:i]] ); code.LINE( @" {" ); code.LINE( [NSString stringWithFormat:@" host = self.%@_%@_Url;", [urlNames safeObjectAtIndex:i], key] ); code.LINE( @" }" );