Permalink
Browse files

Added support for documenting typedef enums. First draft seems to work

  • Loading branch information...
1 parent 3df677f commit faa266af0e7ba61f28529ce349c75748b24189a8 robvdveer committed Jul 25, 2013
@@ -517,6 +517,10 @@ - (NSString *)outputPathForObject:(id)object withExtension:(NSString *)extension
basePath = @"Protocols";
name = [object nameOfProtocol];
}
+ else if ([object isKindOfClass:[GBTypedefEnumData class]]) {
+ basePath = @"Constants";
+ name = [object nameOfEnum];
+ }
else if ([object isKindOfClass:[GBDocumentData class]]) {
GBDocumentData *document = object;
@@ -25,6 +25,7 @@ - (NSDictionary *)objectPage {
[result setObject:@"%@ Class Reference" forKey:@"classTitle"];
[result setObject:@"%1$@(%2$@) Category Reference" forKey:@"categoryTitle"];
[result setObject:@"%@ Protocol Reference" forKey:@"protocolTitle"];
+ [result setObject:@"%@ Constants Reference" forKey:@"constantTitle"];
[result setObject:@"%@ Methods" forKey:@"mergedCategorySectionTitle"];
[result setObject:@"Extension Methods" forKey:@"mergedExtensionSectionTitle"];
[result setObject:@"%2$@ from %1$@" forKey:@"mergedPrefixedCategorySectionTitle"];
@@ -38,6 +39,8 @@ - (NSDictionary *)objectSpecifications {
result = [[NSMutableDictionary alloc] init];
[result setObject:@"Inherits from" forKey:@"inheritsFrom"];
[result setObject:@"Conforms to" forKey:@"conformsTo"];
+ [result setObject:@"References" forKey:@"references"];
+ [result setObject:@"Availability" forKey:@"availability"];
[result setObject:@"Declared in" forKey:@"declaredIn"];
[result setObject:@"Companion guide" forKey:@"companionGuide"];
}
@@ -105,6 +108,7 @@ - (NSDictionary *)indexPage {
[result setObject:@"Class References" forKey:@"classesTitle"];
[result setObject:@"Category References" forKey:@"categoriesTitle"];
[result setObject:@"Protocol References" forKey:@"protocolsTitle"];
+ [result setObject:@"Constant References" forKey:@"constantsTitle"];
}
return result;
}
@@ -117,6 +121,7 @@ - (NSDictionary *)hierarchyPage {
[result setObject:@"Class Hierarchy" forKey:@"classesTitle"];
[result setObject:@"Category References" forKey:@"categoriesTitle"];
[result setObject:@"Protocol References" forKey:@"protocolsTitle"];
+ [result setObject:@"Constant References" forKey:@"constantsTitle"];
}
return result;
}
@@ -131,6 +136,7 @@ - (NSDictionary *)docset {
[result setObject:@"Classes" forKey:@"classesTitle"];
[result setObject:@"Categories" forKey:@"categoriesTitle"];
[result setObject:@"Protocols" forKey:@"protocolsTitle"];
+ [result setObject:@"Constants" forKey:@"constantsTitle"];
}
return result;
}
@@ -35,6 +35,7 @@ -(void) addGetterSetterToMethods:(GBMethodData *)property for:(NSString *)name w
@property (retain) NSArray *classes;
@property (retain) NSArray *categories;
@property (retain) NSArray *protocols;
+@property (retain) NSArray *constants;
@property (readonly) NSMutableSet *temporaryFiles;
@property (retain) id sectionID; //tmp for class's refid
@@ -145,10 +146,12 @@ - (BOOL)processNodesXml:(NSError **)error {
[vars setObject:[NSNumber numberWithBool:([self.classes count] > 0)] forKey:@"hasClasses"];
[vars setObject:[NSNumber numberWithBool:([self.categories count] > 0)] forKey:@"hasCategories"];
[vars setObject:[NSNumber numberWithBool:([self.protocols count] > 0)] forKey:@"hasProtocols"];
+ [vars setObject:[NSNumber numberWithBool:([self.constants count] > 0)] forKey:@"hasConstants"];
[vars setObject:self.documents forKey:@"docs"];
[vars setObject:self.classes forKey:@"classes"];
[vars setObject:self.categories forKey:@"categories"];
[vars setObject:self.protocols forKey:@"protocols"];
+ [vars setObject:self.constants forKey:@"constants"];
[vars setObject:self.settings.stringTemplates forKey:@"strings"];
// Run the template and save the results.
@@ -180,6 +183,7 @@ - (BOOL)processTokensXml:(NSError **)error {
if (![self processTokensXmlForObjects:self.classes type:@"cl" template:templatePath index:&index error:error]) return NO;
if (![self processTokensXmlForObjects:self.categories type:@"cat" template:templatePath index:&index error:error]) return NO;
if (![self processTokensXmlForObjects:self.protocols type:@"intf" template:templatePath index:&index error:error]) return NO;
+ if (![self processTokensXmlForObjects:self.constants type:@"tdef" template:templatePath index:&index error:error]) return NO;
return YES;
}
@@ -228,7 +232,7 @@ - (BOOL)processTokensXmlForObjects:(NSArray *)objects type:(NSString *)type temp
for (NSMutableDictionary *simplifiedObjectData in objects) {
// Get the object's methods provider and prepare the array of all methods.
GBModelBase *topLevelObject = [simplifiedObjectData objectForKey:@"object"];
- GBMethodsProvider *methodsProvider = [topLevelObject valueForKey:@"methods"];
+
// Prepare template variables for object. Note that we reuse the ID assigned while creating the data for Nodes.xml.
NSMutableDictionary *objectData = [NSMutableDictionary dictionaryWithCapacity:2];
@@ -237,21 +241,45 @@ - (BOOL)processTokensXmlForObjects:(NSArray *)objects type:(NSString *)type temp
_sectionID = [objectData objectForKey:@"refid"];
[self addTokensXmlModelObjectDataForObject:topLevelObject toData:objectData];
- // Prepare the list of all members.
- NSMutableArray *membersData = [NSMutableArray arrayWithCapacity:[methodsProvider.methods count]];
- for (GBMethodData *method in methodsProvider.methods) {
- NSMutableDictionary *data = [NSMutableDictionary dictionaryWithCapacity:4];
- [data setObject:[self.settings htmlReferenceNameForObject:method] forKey:@"anchor"];
- [self addTokensXmlModelObjectDataForObject:method toData:data];
- [self addTokensXmlModelObjectDataForPropertySetterAndGetter:method withData:data toArray:membersData];
- [membersData addObject:data];
- }
-
- // Prepare the variables for the template.
NSMutableDictionary *vars = [NSMutableDictionary dictionary];
- [vars setObject:[simplifiedObjectData objectForKey:@"path"] forKey:@"filePath"];
- [vars setObject:objectData forKey:@"object"];
- [vars setObject:membersData forKey:@"members"];
+
+ // Prepare the list of all members.
+ if([topLevelObject respondsToSelector:@selector(methods)])
+ {
+ GBMethodsProvider *methodsProvider = [topLevelObject valueForKey:@"methods"];
+ NSMutableArray *membersData = [NSMutableArray arrayWithCapacity:[methodsProvider.methods count]];
+ for (GBMethodData *method in methodsProvider.methods) {
+ NSMutableDictionary *data = [NSMutableDictionary dictionaryWithCapacity:4];
+ [data setObject:[self.settings htmlReferenceNameForObject:method] forKey:@"anchor"];
+ [self addTokensXmlModelObjectDataForObject:method toData:data];
+ [self addTokensXmlModelObjectDataForPropertySetterAndGetter:method withData:data toArray:membersData];
+ [membersData addObject:data];
+
+ }
+
+ // Prepare the variables for the template.
+ [vars setObject:[simplifiedObjectData objectForKey:@"path"] forKey:@"filePath"];
+ [vars setObject:objectData forKey:@"object"];
+ [vars setObject:membersData forKey:@"members"];
+ }
+
+ //if the object is a enum typedef, use this enumerator for the values.
+ if([topLevelObject isKindOfClass:[GBTypedefEnumData class]])
+ {
+ GBEnumConstantProvider *typedefEnum = [topLevelObject valueForKey:@"constants"];
+ NSMutableArray *constantsData = [NSMutableArray arrayWithCapacity:[typedefEnum.constants count]];
+ for (GBEnumConstantData *constant in typedefEnum.constants) {
+ NSMutableDictionary *data = [NSMutableDictionary dictionaryWithCapacity:4];
+ [data setObject:[self.settings htmlReferenceNameForObject:constant] forKey:@"anchor"];
+ [self addTokensXmlModelObjectDataForObject:constant toData:data];
+ [constantsData addObject:data];
+ }
+
+ // Prepare the variables for the template.
+ [vars setObject:[simplifiedObjectData objectForKey:@"path"] forKey:@"filePath"];
+ [vars setObject:objectData forKey:@"object"];
+ [vars setObject:constantsData forKey:@"members"];
+ }
// Run the template and save the results.
NSString *output = [handler renderObject:vars];
@@ -376,9 +404,16 @@ - (NSString *)tokenIdentifierForObject:(GBModelBase *)object {
NSString *objectName = [(GBProtocolData *)object nameOfProtocol];
return [NSString stringWithFormat:@"//apple_ref/occ/intf/%@", objectName];
}
+ else if ([object isKindOfClass:[GBTypedefEnumData class]]){
+ NSString *objectName = [(GBTypedefEnumData *)object nameOfEnum];
+ return [NSString stringWithFormat:@"//apple_ref/occ/tdef/%@", objectName];
+ }
} else if ([object isKindOfClass:[GBDocumentData class]]){
NSString *objectName = [(GBDocumentData *)object prettyNameOfDocument];
return [NSString stringWithFormat:@"//apple_ref/occ/doc/%@", objectName];
+ } else if ([object isKindOfClass:[GBEnumConstantData class]]){
+ NSString *objectName = [(GBEnumConstantData *)object name];
+ return [NSString stringWithFormat:@"//apple_ref/occ/tag/%@", objectName];
} else if (!object.isStaticDocument) {
// Members are slighly more complex - their identifier is different regarding to whether they are part of class or category/protocol. Then it depends on whether they are method or property. Finally their parent object (class/category/protocol) name (again class name for category) and selector should be added.
if (!object.parentObject) [NSException raise:@"Can't create token identifier for %@; object is not top level and has no parent assigned!", object];
@@ -416,6 +451,7 @@ - (void)initializeSimplifiedObjects {
self.classes = [self simplifiedObjectsFromObjects:[self.store classesSortedByName] value:@"nameOfClass" index:&index];
self.categories = [self simplifiedObjectsFromObjects:[self.store categoriesSortedByName] value:@"idOfCategory" index:&index];
self.protocols = [self simplifiedObjectsFromObjects:[self.store protocolsSortedByName] value:@"nameOfProtocol" index:&index];
+ self.constants = [self simplifiedObjectsFromObjects:[self.store constantsSortedByName] value:@"nameOfEnum" index:&index];
}
- (NSArray *)simplifiedObjectsFromObjects:(NSArray *)objects value:(NSString *)value index:(NSUInteger *)index {
@@ -456,5 +492,6 @@ - (NSMutableSet *)temporaryFiles {
@synthesize classes;
@synthesize categories;
@synthesize protocols;
+@synthesize constants;
@end
@@ -21,6 +21,7 @@ - (BOOL)processClasses:(NSError **)error;
- (BOOL)processCategories:(NSError **)error;
- (BOOL)processProtocols:(NSError **)error;
- (BOOL)processDocuments:(NSError **)error;
+- (BOOL)processConstants:(NSError **)error;
- (BOOL)processIndex:(NSError **)error;
- (BOOL)processHierarchy:(NSError **)error;
- (NSString *)stringByCleaningHtml:(NSString *)string;
@@ -49,6 +50,7 @@ - (BOOL)generateOutputWithStore:(id)store error:(NSError **)error {
if (![self processCategories:error]) return NO;
if (![self processProtocols:error]) return NO;
if (![self processDocuments:error]) return NO;
+ if (![self processConstants:error]) return NO;
if (![self processIndex:error]) return NO;
if (![self processHierarchy:error]) return NO;
return YES;
@@ -105,6 +107,23 @@ - (BOOL)processProtocols:(NSError **)error {
return YES;
}
+- (BOOL)processConstants:(NSError **)error {
+ for (GBTypedefEnumData *enumTypedef in self.store.constants) {
+ if (!enumTypedef.includeInOutput) continue;
+ GBLogInfo(@"Generating output for protocol %@...", enumTypedef);
+ NSDictionary *vars = [self.variablesProvider variablesForConstant:enumTypedef withStore:self.store];
+ NSString *output = [self.htmlObjectTemplate renderObject:vars];
+ NSString *cleaned = [self stringByCleaningHtml:output];
+ NSString *path = [self htmlOutputPathForObject:enumTypedef];
+ if (![self writeString:cleaned toFile:[path stringByStandardizingPath] error:error]) {
+ GBLogWarn(@"Failed writing HTML for constant %@ to '%@'!", enumTypedef, path);
+ return NO;
+ }
+ GBLogDebug(@"Finished generating output for constant %@.", enumTypedef);
+ }
+ return YES;
+}
+
- (BOOL)processDocuments:(NSError **)error {
// First process all include paths by copying them over to the destination. Note that we do it even if no template is found - if the user specified some include path, we should use it...
NSString *docsUserPath = [self.outputUserPath stringByAppendingPathComponent:self.settings.htmlStaticDocumentsSubpath];
@@ -136,7 +155,7 @@ - (BOOL)processDocuments:(NSError **)error {
- (BOOL)processIndex:(NSError **)error {
GBLogInfo(@"Generating output for index...");
- if ([self.store.classes count] > 0 || [self.store.protocols count] > 0 || [self.store.categories count] > 0) {
+ if ([self.store.classes count] > 0 || [self.store.protocols count] > 0 || [self.store.categories count] > 0 || [self.store.constants count] > 0) {
NSDictionary *vars = [self.variablesProvider variablesForIndexWithStore:self.store];
NSString *output = [self.htmlIndexTemplate renderObject:vars];
NSString *cleaned = [self stringByCleaningHtml:output];
@@ -152,7 +171,7 @@ - (BOOL)processIndex:(NSError **)error {
- (BOOL)processHierarchy:(NSError **)error {
GBLogInfo(@"Generating output for hierarchy...");
- if ([self.store.classes count] > 0 || [self.store.protocols count] > 0 || [self.store.categories count] > 0) {
+ if ([self.store.classes count] > 0 || [self.store.protocols count] > 0 || [self.store.categories count] > 0 || [self.store.constants count] > 0) {
NSDictionary *vars = [self.variablesProvider variablesForHierarchyWithStore:self.store];
NSString *output = [self.htmlHierarchyTemplate renderObject:vars];
NSString *cleaned = [self stringByCleaningHtml:output];
@@ -92,6 +92,8 @@
*/
- (NSDictionary *)variablesForProtocol:(GBProtocolData *)object withStore:(id)store;
+- (NSDictionary *)variablesForConstant:(GBTypedefEnumData *)object withStore:(id)store;
+
/** Returns the variables for the given `GBDocumentData` using the given `GBStore` for links.
The result can be used with `GBTemplateHandler` to generate document specific output.
Oops, something went wrong.

0 comments on commit faa266a

Please sign in to comment.