-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3b48146
commit 0aabf52
Showing
43 changed files
with
3,042 additions
and
295 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,11 +1,11 @@ | ||
# Uncomment the next line to define a global platform for your project | ||
# platform :ios, '9.0' | ||
|
||
target 'ResourceObjC' do | ||
target 'R.objc' do | ||
# Uncomment the next line if you're using Swift or would like to use dynamic frameworks | ||
# use_frameworks! | ||
|
||
# Pods for ResourceObjC | ||
# Pods for R.objc | ||
pod 'XMLDictionary' | ||
|
||
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 0 additions & 5 deletions
5
Pods/Target Support Files/Pods-ResourceObjC/Pods-ResourceObjC-dummy.m
This file was deleted.
Oops, something went wrong.
228 changes: 114 additions & 114 deletions
228
ResourceObjC.xcodeproj/project.pbxproj → R.objc.xcodeproj/project.pbxproj
Large diffs are not rendered by default.
Oops, something went wrong.
File renamed without changes.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,44 @@ | ||
// Copyright 2016 Sysdata Digital | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#import <Foundation/Foundation.h> | ||
#import "ResourceFinder.h" | ||
#import "Placeholders.h" | ||
#import "CommonUtils.h" | ||
#import "GeneratedStructures.h" | ||
|
||
#define END_CONTEXT @"@end\n\n" | ||
|
||
@protocol GeneratorProtocol <NSObject> | ||
|
||
- (NSString*) className; | ||
- (NSString*) propertyName; | ||
- (BOOL)generateResourceFileWithError:(NSError**)error; | ||
|
||
@end | ||
|
||
@interface BaseGenerator : NSObject <GeneratorProtocol> | ||
|
||
@property (nonatomic, readonly) ResourceFinder *finder; | ||
@property (nonatomic, strong) RClass *clazz; | ||
@property (nonatomic, strong) NSMutableArray<RClass*>* otherClasses; | ||
|
||
|
||
- (instancetype)initWithResourceFinder:(ResourceFinder*)finder; | ||
|
||
- (NSString*)resourceFileHeaderPath; | ||
- (NSString*)resourceFileImplementationPath; | ||
|
||
- (BOOL)writeStringInRFilesWithError:(NSError *__autoreleasing *)error; | ||
@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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
// Copyright 2016 Sysdata Digital | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#import "BaseGenerator.h" | ||
|
||
@implementation BaseGenerator | ||
|
||
- (instancetype)initWithResourceFinder:(ResourceFinder *)finder | ||
{ | ||
self = [super init]; | ||
if (self) | ||
{ | ||
_finder = finder; | ||
_clazz = [[RClass alloc] initWithName:self.className]; | ||
_otherClasses = [NSMutableArray new]; | ||
} | ||
return self; | ||
} | ||
|
||
-(NSString *)className | ||
{ | ||
return nil; | ||
} | ||
|
||
- (NSString *)propertyName | ||
{ | ||
return nil; | ||
} | ||
|
||
- (BOOL)generateResourceFileWithError:(NSError *__autoreleasing *)error | ||
{ | ||
return YES; | ||
} | ||
|
||
- (NSString *)resourceFileHeaderPath | ||
{ | ||
return [self.finder.outputURL.path stringByAppendingPathComponent:@"R.h"]; | ||
} | ||
|
||
- (NSString *)resourceFileImplementationPath | ||
{ | ||
return [self.finder.outputURL.path stringByAppendingPathComponent:@"R.m"]; | ||
} | ||
|
||
- (BOOL)writeStringInRFilesWithError:(NSError *__autoreleasing *)error | ||
{ | ||
BOOL hResult = [self writeStringInInterfaceWithError:error]; | ||
BOOL mResult = [self writeStringInImplementationWithError:error]; | ||
|
||
return hResult && mResult; | ||
} | ||
|
||
- (BOOL)writeStringInInterfaceWithError:(NSError *__autoreleasing *)error | ||
{ | ||
NSMutableString* content = [NSMutableString stringWithContentsOfFile:self.resourceFileHeaderPath encoding:NSUTF8StringEncoding error:error]; | ||
if (!content) | ||
{ | ||
[CommonUtils log:@"Unable to read %@", self.resourceFileHeaderPath.lastPathComponent]; | ||
return NO; | ||
} | ||
|
||
NSMutableString* interface = [NSMutableString new]; | ||
for (RClass* c in self.otherClasses) | ||
{ | ||
[interface appendString:[c generateInterfaceString]]; | ||
} | ||
|
||
[interface appendString:[self.clazz generateInterfaceString]]; | ||
|
||
[content appendString:interface]; | ||
|
||
return [content writeToFile:self.resourceFileHeaderPath atomically:YES encoding:NSUTF8StringEncoding error:error]; | ||
} | ||
|
||
- (BOOL)writeStringInImplementationWithError:(NSError *__autoreleasing *)error | ||
{ | ||
NSMutableString* content = [NSMutableString stringWithContentsOfFile:self.resourceFileImplementationPath encoding:NSUTF8StringEncoding error:error]; | ||
if (!content) | ||
{ | ||
[CommonUtils log:@"Unable to read %@", self.resourceFileImplementationPath.lastPathComponent]; | ||
return NO; | ||
} | ||
|
||
NSMutableString* implementation = [NSMutableString new]; | ||
for (RClass* c in self.otherClasses) | ||
{ | ||
[implementation appendString:[c generateImplementationString]]; | ||
} | ||
|
||
[implementation appendString:[self.clazz generateImplementationString]]; | ||
|
||
[content appendString:implementation]; | ||
|
||
return [content writeToFile:self.resourceFileImplementationPath atomically:YES encoding:NSUTF8StringEncoding error:error]; | ||
} | ||
|
||
@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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright 2016 Sysdata Digital | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
@interface CommonUtils : NSObject | ||
|
||
+ (void) logVerbose:(NSString *)format, ...; | ||
+ (void) log:(NSString *)format, ...; | ||
+ (NSString*)codableNameFromString:(NSString*)string; | ||
+ (NSString*)classNameFromFilename:(NSString*)filename removingExtension:(NSString*)extension; | ||
+ (NSString*)methodNameFromFilename:(NSString*)filename removingExtension:(NSString*)extension; | ||
|
||
@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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
// Copyright 2016 Sysdata Digital | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#import "CommonUtils.h" | ||
#import "Session.h" | ||
|
||
@implementation CommonUtils | ||
|
||
+ (void) logVerbose:(NSString *)format, ... | ||
{ | ||
if ([[Session shared] isVerboseLoggingEnabled]) | ||
{ | ||
[self log:format]; | ||
} | ||
} | ||
|
||
+ (void) log:(NSString *)format, ... | ||
{ | ||
va_list args; | ||
if (format) | ||
{ | ||
va_start(args, format); | ||
|
||
[self log:format args:args]; | ||
|
||
va_end(args); | ||
} | ||
} | ||
|
||
+ (void) log:(NSString *)format args:(va_list)args | ||
{ | ||
if (format) | ||
{ | ||
NSLogv(format, args);; | ||
} | ||
} | ||
|
||
+ (NSString*)codableNameFromString:(NSString*)string | ||
{ | ||
NSMutableCharacterSet* charactersEligible = [NSMutableCharacterSet alphanumericCharacterSet]; | ||
NSCharacterSet* charactersToRemove = [charactersEligible invertedSet]; | ||
NSArray* components = [string componentsSeparatedByCharactersInSet:charactersToRemove]; | ||
NSMutableArray* newComponents = [NSMutableArray new]; | ||
for (NSString* comp in components) | ||
{ | ||
NSString* newComp = comp; | ||
if (comp.length >= 2) | ||
{ | ||
newComp = [NSString stringWithFormat:@"%@%@", [comp substringToIndex:1].uppercaseString, [comp substringFromIndex:1]]; | ||
} | ||
[newComponents addObject:newComp]; | ||
} | ||
NSString *strippedString = [newComponents componentsJoinedByString:@""]; | ||
if (strippedString.length >= 2) | ||
{ | ||
strippedString = [NSString stringWithFormat:@"%@%@", [strippedString substringToIndex:1].lowercaseString, [strippedString substringFromIndex:1]]; | ||
} | ||
|
||
NSRegularExpression* regExpression = [NSRegularExpression | ||
regularExpressionWithPattern:@"^[0-9].*" | ||
options:0 | ||
error:nil]; | ||
|
||
if ([regExpression numberOfMatchesInString:strippedString options:0 range:[strippedString rangeOfString:strippedString]] > 0) | ||
{ | ||
strippedString = [NSString stringWithFormat:@"_%@", strippedString]; | ||
} | ||
return strippedString; | ||
} | ||
|
||
+ (NSString *)classNameFromFilename:(NSString *)filename removingExtension:(NSString *)extension | ||
{ | ||
NSString* retval = [NSString stringWithFormat:@"%@%@", [filename substringToIndex:1].uppercaseString, [filename substringFromIndex:1]]; | ||
if (extension.length > 0) | ||
{ | ||
retval = [retval stringByReplacingOccurrencesOfString:extension withString:@""]; | ||
} | ||
retval = [retval stringByReplacingOccurrencesOfString:@" " withString:@""]; | ||
return retval; | ||
} | ||
|
||
+ (NSString *)methodNameFromFilename:(NSString *)filename removingExtension:(NSString *)extension | ||
{ | ||
NSString* retval = [NSString stringWithFormat:@"%@%@", [filename substringToIndex:1].lowercaseString, [filename substringFromIndex:1]]; | ||
if (extension.length > 0) | ||
{ | ||
retval = [retval stringByReplacingOccurrencesOfString:extension withString:@""]; | ||
} | ||
retval = [retval stringByReplacingOccurrencesOfString:@" " withString:@""]; | ||
return retval; | ||
} | ||
|
||
@end |
Oops, something went wrong.