Permalink
Browse files

Prepared ground for HTML hierarchy file generation.

At this stage, hierarchy file is generated but it only contains categories and protocols.
  • Loading branch information...
1 parent 7a5e4f8 commit 7392348d4e121818113424e4020d651df8135dbf @tomaz committed Dec 22, 2010
@@ -48,6 +48,9 @@
/** Strings used for generating common page strings for index. */
@property (readonly) NSDictionary *indexPage;
+/** Strings used for generating common page strings for hierarchy. */
+@property (readonly) NSDictionary *hierarchyPage;
+
///---------------------------------------------------------------------------------------
/// @name DocSet output strings
///---------------------------------------------------------------------------------------
@@ -93,6 +93,17 @@ - (NSDictionary *)indexPage {
return result;
}
+- (NSDictionary *)hierarchyPage {
+ static NSMutableDictionary *result = nil;
+ if (!result) {
+ result = [[NSMutableDictionary alloc] init];
+ [result setObject:@"Class Hierarchy" forKey:@"classesTitle"];
+ [result setObject:@"Category References" forKey:@"categoriesTitle"];
+ [result setObject:@"Protocol References" forKey:@"protocolsTitle"];
+ }
+ return result;
+}
+
#pragma mark Documentation set output strings
- (NSDictionary *)docset {
@@ -29,6 +29,7 @@ enum {
GBErrorHTMLObjectTemplateMissing = 8000,
GBErrorHTMLIndexTemplateMissing,
+ GBErrorHTMLHierarchyTemplateMissing,
GBErrorDocSetDocumentTemplateMissing = 9000,
GBErrorDocSetInfoPlistTemplateMissing,
@@ -21,11 +21,14 @@ - (BOOL)processClasses:(NSError **)error;
- (BOOL)processCategories:(NSError **)error;
- (BOOL)processProtocols:(NSError **)error;
- (BOOL)processIndex:(NSError **)error;
+- (BOOL)processHierarchy:(NSError **)error;
- (NSString *)stringByCleaningHtml:(NSString *)string;
- (NSString *)htmlOutputPathForIndex;
+- (NSString *)htmlOutputPathForHierarchy;
- (NSString *)htmlOutputPathForObject:(GBModelBase *)object;
@property (readonly) GBTemplateHandler *htmlObjectTemplate;
@property (readonly) GBTemplateHandler *htmlIndexTemplate;
+@property (readonly) GBTemplateHandler *htmlHierarchyTemplate;
@property (readonly) GBHTMLTemplateVariablesProvider *variablesProvider;
@end
@@ -43,6 +46,7 @@ - (BOOL)generateOutputWithStore:(id)store error:(NSError **)error {
if (![self processCategories:error]) return NO;
if (![self processProtocols:error]) return NO;
if (![self processIndex:error]) return NO;
+ if (![self processHierarchy:error]) return NO;
return YES;
}
@@ -110,6 +114,22 @@ - (BOOL)processIndex:(NSError **)error {
return YES;
}
+- (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) {
+ NSDictionary *vars = [self.variablesProvider variablesForHierarchyWithStore:self.store];
+ NSString *output = [self.htmlHierarchyTemplate renderObject:vars];
+ NSString *cleaned = [self stringByCleaningHtml:output];
+ NSString *path = [[self htmlOutputPathForHierarchy] stringByStandardizingPath];
+ if (![self writeString:cleaned toFile:[path stringByStandardizingPath] error:error]) {
+ GBLogWarn(@"Failed writting HTML hierarchy to '%@'!", path);
+ return NO;
+ }
+ }
+ GBLogDebug(@"Finished generating output for hierarchy.");
+ return YES;
+}
+
- (BOOL)validateTemplates:(NSError **)error {
if (!self.htmlObjectTemplate) {
if (error) {
@@ -125,6 +145,13 @@ - (BOOL)validateTemplates:(NSError **)error {
}
return NO;
}
+ if (!self.htmlHierarchyTemplate) {
+ if (error) {
+ NSString *desc = [NSString stringWithFormat:@"Hierarchy template file 'hierarchy-template.html' is missing at '%@'!", self.templateUserPath];
+ *error = [NSError errorWithCode:GBErrorHTMLHierarchyTemplateMissing description:desc reason:nil];
+ }
+ return NO;
+ }
return YES;
}
@@ -149,6 +176,12 @@ - (NSString *)htmlOutputPathForIndex {
return [result stringByAppendingPathExtension:self.settings.htmlExtension];
}
+- (NSString *)htmlOutputPathForHierarchy {
+ // Returns file name including full path for HTML file representing the main hierarchy.
+ NSString *result = [self.outputUserPath stringByAppendingPathComponent:@"hierarchy"];
+ return [result stringByAppendingPathExtension:self.settings.htmlExtension];
+}
+
- (NSString *)htmlOutputPathForObject:(GBModelBase *)object {
// Returns file name including full path for HTML file representing the given top-level object. This works for any top-level object: class, category or protocol. The path is automatically determined regarding to the object class.
NSString *inner = [self.settings htmlReferenceForObjectFromIndex:object];
@@ -172,6 +205,10 @@ - (GBTemplateHandler *)htmlIndexTemplate {
return [self.templateFiles objectForKey:@"index-template.html"];
}
+- (GBTemplateHandler *)htmlHierarchyTemplate {
+ return [self.templateFiles objectForKey:@"hierarchy-template.html"];
+}
+
#pragma mark Overriden methods
- (NSString *)outputSubpath {
@@ -55,6 +55,7 @@
@see variablesForCategory:withStore:
@see variablesForProtocol:withStore:
@see variablesForIndexWithStore:
+ @see variablesForHierarchyWithStore:
*/
- (NSDictionary *)variablesForClass:(GBClassData *)object withStore:(id)store;
@@ -69,6 +70,7 @@
@see variablesForClass:withStore:
@see variablesForProtocol:withStore:
@see variablesForIndexWithStore:
+ @see variablesForHierarchyWithStore:
*/
- (NSDictionary *)variablesForCategory:(GBCategoryData *)object withStore:(id)store;
@@ -83,6 +85,7 @@
@see variablesForClass:withStore:
@see variablesForCategory:withStore:
@see variablesForIndexWithStore:
+ @see variablesForHierarchyWithStore:
*/
- (NSDictionary *)variablesForProtocol:(GBProtocolData *)object withStore:(id)store;
@@ -95,8 +98,23 @@
@exception NSException Thrown if the given object or store is `nil`.
@see variablesForClass:withStore:
@see variablesForCategory:withStore:
- @see variablesForIndexWithStore:
+ @see variablesForProtocol:withStore:
+ @see variablesForHierarchyWithStore:
*/
- (NSDictionary *)variablesForIndexWithStore:(id)store;
+/** Returns the variables for the hierarchy file using the given `GBStore` for links.
+
+ The result can be used with `GBTemplateHandler` to generate protocol specific output.
+
+ @param store Store provider to be used for links generation.
+ @return Returns dictionary of all variables.
+ @exception NSException Thrown if the given object or store is `nil`.
+ @see variablesForClass:withStore:
+ @see variablesForCategory:withStore:
+ @see variablesForProtocol:withStore:
+ @see variablesForIndexWithStore:
+ */
+- (NSDictionary *)variablesForHierarchyWithStore:(id)store;
+
@end
@@ -57,9 +57,11 @@ - (NSArray *)delimitObjectSpecificationValues:(NSArray *)values withDelimiter:(N
@interface GBHTMLTemplateVariablesProvider (IndexVariables)
- (NSString *)pageTitleForIndex;
+- (NSString *)pageTitleForHierarchy;
- (NSArray *)classesForIndex;
- (NSArray *)categoriesForIndex;
- (NSArray *)protocolsForIndex;
+- (NSArray *)classesForHierarchy;
- (void)registerObjectsUsageForIndexInDictionary:(NSMutableDictionary *)dict;
@end
@@ -142,6 +144,21 @@ - (NSDictionary *)variablesForIndexWithStore:(id)store {
return result;
}
+- (NSDictionary *)variablesForHierarchyWithStore:(id)store {
+ self.store = store;
+ NSMutableDictionary *page = [NSMutableDictionary dictionary];
+ [page setObject:[self pageTitleForHierarchy] forKey:@"title"];
+ [self addFooterVarsToDictionary:page];
+ NSMutableDictionary *result = [NSMutableDictionary dictionary];
+ [result setObject:page forKey:@"page"];
+ [result setObject:[self classesForHierarchy] forKey:@"classes"];
+ [result setObject:[self protocolsForIndex] forKey:@"protocols"];
+ [result setObject:[self categoriesForIndex] forKey:@"categories"];
+ [result setObject:self.settings.stringTemplates forKey:@"strings"];
+ [self registerObjectsUsageForIndexInDictionary:result];
+ return result;
+}
+
#pragma mark Helper methods
- (NSString *)hrefForObject:(id)object fromObject:(id)source {
@@ -318,6 +335,10 @@ - (NSString *)pageTitleForIndex {
return [NSString stringWithFormat:@"%@ Reference", self.settings.projectName];
}
+- (NSString *)pageTitleForHierarchy {
+ return [NSString stringWithFormat:@"%@ Hierarchy", self.settings.projectName];
+}
+
- (NSArray *)classesForIndex {
NSArray *classes = [self.store classesSortedByName];
NSMutableArray *result = [NSMutableArray arrayWithCapacity:[classes count]];
@@ -354,6 +375,11 @@ - (NSArray *)protocolsForIndex {
return result;
}
+- (NSArray *)classesForHierarchy {
+ // This returns the array of all root classes, each class containing further arrays of subclasses and so on. Ussually root classes array only contains single NSObject class, but can also include all root classes (not derived from NSObject). The algorithm for creating hierarhy is not state of the art, but it's quite simple and effective: for each class we iterate over the whole hierarchy and add the class itself as well as each super class to temporary dictionary together with known
+ return [NSArray array];
+}
+
- (void)registerObjectsUsageForIndexInDictionary:(NSMutableDictionary *)dict {
BOOL classes = [self.store.classes count] > 0;
BOOL categories = [self.store.categories count] > 0;
@@ -0,0 +1,53 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <title>{{page/title}}</title>
+ <meta http-equiv="Content-Type" content="application/xhtml+xml;charset=utf-8" />
+ <link rel="stylesheet" type="text/css" href="css/styles.css" />
+ <meta name="generator" content="appledoc" />
+ </head>
+ <body>
+ <article id="contents" role="main">
+ <div id="header">
+ <div class="section-header">
+ <h1 class="title title-header">{{page/title}}</h1>
+ </div>
+ </div>
+ <div id="container">
+ {{#hasClasses}}
+ <div class="index-column">
+ <h2 class="index-title">{{strings/hierarchyPage/classesTitle}}</h2>
+ </div>
+ {{/hasClasses}}
+
+ {{#hasProtocolsOrCategories}}
+ <div class="index-column">
+ {{#hasProtocols}}
+ <h2 class="index-title">{{strings/indexPage/protocolsTitle}}</h2>
+ <ul>
+ {{#protocols}}
+ <li><a href="{{href}}">{{title}}</a></li>
+ {{/protocols}}
+ </ul>
+ {{/hasProtocols}}
+ {{#hasCategories}}
+ <h2 class="index-title">{{strings/indexPage/categoriesTitle}}</h2>
+ <ul>
+ {{#categories}}
+ <li><a href="{{href}}">{{title}}</a></li>
+ {{/categories}}
+ </ul>
+ {{/hasCategories}}
+ </div>
+ {{/hasProtocolsOrCategories}}
+ </div>
+ <div id="footer">
+ <hr />
+ <div class="footer-copyright">
+ <p><span class="copyright">&copy; {{page//copyrightDate}} {{page/copyrightHolder}}. All rights reserved. (Last updated: {{page//lastUpdatedDate}})</span><br />
+ <span class="generator">Generated by <a href="http://appledoc.gentlebytes.com">appledoc</a>.</span></p>
+ </div>
+ </div>
+ </article>
+ </body>
+</html>

0 comments on commit 7392348

Please sign in to comment.