Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

file 631 lines (533 sloc) 30.194 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631
//
// GBApplicationSettingsProvider.m
// appledoc
//
// Created by Tomaz Kragelj on 3.10.10.
// Copyright (C) 2010, Gentle Bytes. All rights reserved.
//

#include "mkdio.h"
#import <objc/runtime.h>
#import "RegexKitLite.h"
#import "GBDataObjects.h"
#import "GBApplicationSettingsProvider.h"
#import "GBLog.h"

NSString *kGBTemplatePlaceholderCompanyID = @"%COMPANYID";
NSString *kGBTemplatePlaceholderProjectID = @"%PROJECTID";
NSString *kGBTemplatePlaceholderVersionID = @"%VERSIONID";
NSString *kGBTemplatePlaceholderProject = @"%PROJECT";
NSString *kGBTemplatePlaceholderCompany = @"%COMPANY";
NSString *kGBTemplatePlaceholderVersion = @"%VERSION";
NSString *kGBTemplatePlaceholderDocSetBundleFilename = @"%DOCSETBUNDLEFILENAME";
NSString *kGBTemplatePlaceholderDocSetAtomFilename = @"%DOCSETATOMFILENAME";
NSString *kGBTemplatePlaceholderDocSetPackageFilename = @"%DOCSETPACKAGEFILENAME";
NSString *kGBTemplatePlaceholderYear = @"%YEAR";
NSString *kGBTemplatePlaceholderUpdateDate = @"%UPDATEDATE";

NSString *kGBCustomDocumentIndexDescKey = @"index-description";

#pragma mark -

@interface GBApplicationSettingsProvider ()

+ (NSSet *)nonCopyableProperties;
- (NSString *)htmlReferenceForObjectFromIndex:(GBModelBase *)object;
- (NSString *)htmlReferenceForTopLevelObject:(GBModelBase *)object fromTopLevelObject:(GBModelBase *)source;
- (NSString *)htmlReferenceForMember:(id)member prefixedWith:(id)prefix;
- (NSString *)outputPathForObject:(id)object withExtension:(NSString *)extension;
- (NSString *)stringByReplacingOccurencesOfRegex:(NSString *)regex inHTML:(NSString *)string usingBlock:(NSString *(^)(NSInteger captureCount, NSString **capturedStrings, BOOL insideCode))block;
- (NSString *)stringByNormalizingString:(NSString *)string;
@property (readonly) NSDateFormatter *yearDateFormatter;
@property (readonly) NSDateFormatter *yearToDayDateFormatter;

@end

#pragma mark -

@implementation GBApplicationSettingsProvider

#pragma mark Initialization & disposal

+ (NSSet *)nonCopyableProperties {
return [NSSet setWithObjects:@"htmlExtension", @"yearDateFormatter", @"yearToDayDateFormatter", @"commentComponents", @"stringTemplates", nil];
}

+ (id)provider {
return [[[self alloc] init] autorelease];
}

- (id)init {
self = [super init];
if (self) {
self.projectName = nil;
self.projectCompany = nil;
self.projectVersion = @"1.0";
self.companyIdentifier = @"";

self.outputPath = @"";
self.templatesPath = nil;
self.docsetInstallPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Library/Developer/Shared/Documentation/DocSets"];
self.docsetUtilPath = @"/Developer/usr/bin/docsetutil";
self.indexDescriptionPath = nil;
self.includePaths = [NSMutableSet set];
self.ignoredPaths = [NSMutableSet set];
        self.excludeOutputPaths = [NSMutableSet set];

self.createHTML = YES;
self.createDocSet = YES;
self.installDocSet = YES;
self.publishDocSet = NO;
self.repeatFirstParagraphForMemberDescription = YES;
self.useSingleStarForBold = NO;
self.keepIntermediateFiles = NO;
self.cleanupOutputPathBeforeRunning = NO;
self.keepUndocumentedObjects = NO;
self.keepUndocumentedMembers = NO;
self.findUndocumentedMembersDocumentation = YES;
self.treatDocSetIndexingErrorsAsFatals = NO;
self.exitCodeThreshold = 0;

self.mergeCategoriesToClasses = YES;
self.keepMergedCategoriesSections = NO;
self.prefixMergedCategoriesSectionsWithCategoryName = NO;

self.prefixLocalMembersInRelatedItemsList = YES;
self.embedCrossReferencesWhenProcessingMarkdown = YES;
self.embedAppledocBoldMarkersWhenProcessingMarkdown = YES;

self.warnOnMissingOutputPathArgument = YES;
self.warnOnMissingCompanyIdentifier = YES;
self.warnOnUndocumentedObject = YES;
self.warnOnUndocumentedMember = YES;
self.warnOnEmptyDescription = YES;
self.warnOnUnknownDirective = YES;
self.warnOnInvalidCrossReference = YES;
self.warnOnMissingMethodArgument = YES;

self.docsetBundleIdentifier = [NSString stringWithFormat:@"%@.%@", kGBTemplatePlaceholderCompanyID, kGBTemplatePlaceholderProjectID];
self.docsetBundleName = [NSString stringWithFormat:@"%@ Documentation", kGBTemplatePlaceholderProject];
self.docsetCertificateIssuer = @"";
self.docsetCertificateSigner = @"";
self.docsetDescription = @"";
self.docsetFallbackURL = @"";
self.docsetFeedName = self.docsetBundleName;
self.docsetFeedURL = @"";
self.docsetPackageURL = @"";
self.docsetMinimumXcodeVersion = @"3.0";
self.docsetPlatformFamily = @"";
self.docsetPublisherIdentifier = [NSString stringWithFormat:@"%@.documentation", kGBTemplatePlaceholderCompanyID];
self.docsetPublisherName = [NSString stringWithFormat:@"%@", kGBTemplatePlaceholderCompany];
self.docsetCopyrightMessage = [NSString stringWithFormat:@"Copyright © %@ %@. All rights reserved.", kGBTemplatePlaceholderYear, kGBTemplatePlaceholderCompany];

self.docsetBundleFilename = [NSString stringWithFormat:@"%@.%@.docset", kGBTemplatePlaceholderCompanyID, kGBTemplatePlaceholderProjectID];
self.docsetAtomFilename = [NSString stringWithFormat:@"%@.%@.atom", kGBTemplatePlaceholderCompanyID, kGBTemplatePlaceholderProjectID];
self.docsetPackageFilename = [NSString stringWithFormat:@"%@.%@-%@.xar", kGBTemplatePlaceholderCompanyID, kGBTemplatePlaceholderProjectID, kGBTemplatePlaceholderVersionID];

self.commentComponents = [GBCommentComponentsProvider provider];
self.stringTemplates = [GBApplicationStringsProvider provider];
}
return self;
}

#pragma mark Helper methods

- (void)updateHelperClassesWithSettingsValues {
}

- (void)replaceAllOccurencesOfPlaceholderStringsInSettingsValues {
// These need to be replaced first as they can be used in other settings!
self.docsetBundleFilename = [self stringByReplacingOccurencesOfPlaceholdersInString:self.docsetBundleFilename];
self.docsetAtomFilename = [self stringByReplacingOccurencesOfPlaceholdersInString:self.docsetAtomFilename];
self.docsetPackageFilename = [self stringByReplacingOccurencesOfPlaceholdersInString:self.docsetPackageFilename];
// Handle the rest now.
self.docsetBundleIdentifier = [self stringByReplacingOccurencesOfPlaceholdersInString:self.docsetBundleIdentifier];
self.docsetBundleName = [self stringByReplacingOccurencesOfPlaceholdersInString:self.docsetBundleName];
self.docsetCertificateIssuer = [self stringByReplacingOccurencesOfPlaceholdersInString:self.docsetCertificateIssuer];
self.docsetCertificateSigner = [self stringByReplacingOccurencesOfPlaceholdersInString:self.docsetCertificateSigner];
self.docsetDescription = [self stringByReplacingOccurencesOfPlaceholdersInString:self.docsetDescription];
self.docsetFallbackURL = [self stringByReplacingOccurencesOfPlaceholdersInString:self.docsetFallbackURL];
self.docsetFeedName = [self stringByReplacingOccurencesOfPlaceholdersInString:self.docsetFeedName];
self.docsetFeedURL = [self stringByReplacingOccurencesOfPlaceholdersInString:self.docsetFeedURL];
self.docsetPackageURL = [self stringByReplacingOccurencesOfPlaceholdersInString:self.docsetPackageURL];
self.docsetMinimumXcodeVersion = [self stringByReplacingOccurencesOfPlaceholdersInString:self.docsetMinimumXcodeVersion];
self.docsetPlatformFamily = [self stringByReplacingOccurencesOfPlaceholdersInString:self.docsetPlatformFamily];
self.docsetPublisherIdentifier = [self stringByReplacingOccurencesOfPlaceholdersInString:self.docsetPublisherIdentifier];
self.docsetPublisherName = [self stringByReplacingOccurencesOfPlaceholdersInString:self.docsetPublisherName];
self.docsetCopyrightMessage = [self stringByReplacingOccurencesOfPlaceholdersInString:self.docsetCopyrightMessage];
}

#pragma mark Common HTML handling

- (NSString *)stringByEmbeddingCrossReference:(NSString *)value {
if (!self.embedCrossReferencesWhenProcessingMarkdown) return value;
return [NSString stringWithFormat:@"%@%@%@", self.commentComponents.codeSpanStartMarker, value, self.commentComponents.codeSpanEndMarker];
}

- (NSString *)stringByEmbeddingAppledocBoldMarkers:(NSString *)value {
if (!self.embedAppledocBoldMarkersWhenProcessingMarkdown) return value;
return [NSString stringWithFormat:@"%@%@%@", self.commentComponents.appledocBoldStartMarker, value, self.commentComponents.appledocBoldEndMarker];
}

- (NSString *)stringByConvertingMarkdownToHTML:(NSString *)markdown {
// First pass the markdown to discount to get it converted to HTML.
NSString *result = nil;
const char* input=[markdown cStringUsingEncoding:NSUTF8StringEncoding];

if(input) {
MMIOT *document = mkd_string((char *)input, (int)strlen(input), 0);
mkd_compile(document, 0);

char *html = NULL;
int size = mkd_document(document, &html);

if (size <= 0) {
GBLogWarn(@"Failed converting markdown '%@' to HTML!", [markdown description]);
} else {
result = [NSString stringWithCString:html encoding:NSUTF8StringEncoding];
if(!result)
result = [NSString stringWithCString:html encoding:NSASCIIStringEncoding];
}
mkd_cleanup(document);
}

// We should properly handle cross references: if outside example block, simply strip prexif/suffix markers, otherwise extract description from Markdown style scross reference (i.e. [description](the rest)) and only use that part.
if (self.embedCrossReferencesWhenProcessingMarkdown) {
NSString *regex = [self stringByEmbeddingCrossReference:@"(.+?)"];
result = [self stringByReplacingOccurencesOfRegex:regex inHTML:result usingBlock:^NSString *(NSInteger captureCount, NSString **capturedStrings, BOOL insideCode) {
NSString *linkText = capturedStrings[1];
if (!insideCode) return linkText;
NSArray *components = [linkText captureComponentsMatchedByRegex:self.commentComponents.markdownInlineLinkRegex];
if ([components count] < 1) return linkText;
return [components objectAtIndex:1];
}];
}

// We should properly handle Markdown bold markers (**) converted from appledoc style ones (*): if outside example block, simply strip prefix/suffix markers, otherwise convert back to single stars. Note that we first need to handle remaining placeholder markers inside example blocks, then cleanup converter formats.
if (self.embedAppledocBoldMarkersWhenProcessingMarkdown) {
NSString *openingMarker = [NSString stringWithFormat:@"**%@", self.commentComponents.appledocBoldStartMarker];
NSString *closingMarker = [NSString stringWithFormat:@"%@**", self.commentComponents.appledocBoldEndMarker];
result = [result stringByReplacingOccurrencesOfString:openingMarker withString:@"*"];
result = [result stringByReplacingOccurrencesOfString:closingMarker withString:@"*"];
result = [result stringByReplacingOccurrencesOfString:self.commentComponents.appledocBoldStartMarker withString:@""];
result = [result stringByReplacingOccurrencesOfString:self.commentComponents.appledocBoldEndMarker withString:@""];
}

return result;
}

- (NSString *)stringByConvertingMarkdownToText:(NSString *)markdown {
NSString *result = markdown;

// Clean Markdown inline links. Note that we need to additionally handle remote member links [[class method]](address), these are not detected by our standard regex, but using common regex for these cases would incorrectly handle multiple links in the same string (it would greedily match the whole content between the first and the last link as the description). Note that the order of processing is important - we first need to handle "simple" links and then continue with remote members.
result = [result stringByReplacingOccurrencesOfRegex:self.commentComponents.markdownInlineLinkRegex usingBlock:^NSString *(NSInteger captureCount, NSString *const *capturedStrings, const NSRange *capturedRanges, volatile BOOL *const stop) {
return capturedStrings[1];
}];
result = [result stringByReplacingOccurrencesOfRegex:@"\\[(.+)\\]\\(([^\\s]+)(?:\\s*\"([^\"]+)\")?\\)" usingBlock:^NSString *(NSInteger captureCount, NSString *const *capturedStrings, const NSRange *capturedRanges, volatile BOOL *const stop) {
return capturedStrings[1];
}];

// Clean formatting directives. Couldn't find single regex matcher for cleaning up all cases, so ended up in doing several phases and finally repeating the last one for any remaining cases... This makes unit tests pass...
result = [result stringByReplacingOccurrencesOfRegex:@"(\\*\\*\\*|___|\\*\\*_|_\\*\\*|\\*__|__\\*)(.+?)\\1" usingBlock:^NSString *(NSInteger captureCount, NSString *const *capturedStrings, const NSRange *capturedRanges, volatile BOOL *const stop) {
return capturedStrings[2];
}];
result = [result stringByReplacingOccurrencesOfRegex:@"(\\*\\*|__|\\*_|_\\*)(.+?)\\1" usingBlock:^NSString *(NSInteger captureCount, NSString *const *capturedStrings, const NSRange *capturedRanges, volatile BOOL *const stop) {
return capturedStrings[2];
}];
result = [result stringByReplacingOccurrencesOfRegex:@"([*_`])(.+?)\\1" usingBlock:^NSString *(NSInteger captureCount, NSString *const *capturedStrings, const NSRange *capturedRanges, volatile BOOL *const stop) {
return capturedStrings[2];
}];
result = [result stringByReplacingOccurrencesOfRegex:@"([*_`])(.+?)\\1" usingBlock:^NSString *(NSInteger captureCount, NSString *const *capturedStrings, const NSRange *capturedRanges, volatile BOOL *const stop) {
return capturedStrings[2];
}];

// Convert hard coded HTML anchor links as these may cause problems with docsetutil. Basically we get address and description and output only description if found. Otherwise we use address.
NSString *anchorRegex = @"<a\\s+href\\s*=\\s*([\"'])([^\\1]*)[\"']\\s*(?:(?:>([^>]*)</a>)|(?:/>))";
result = [result stringByReplacingOccurrencesOfRegex:anchorRegex usingBlock:^NSString *(NSInteger captureCount, NSString *const *capturedStrings, const NSRange *capturedRanges, volatile BOOL *const stop) {
if (captureCount < 2) return capturedStrings[0];
if (captureCount < 3) return capturedStrings[2];
NSString *description = capturedStrings[3];
if ([description length] > 0) return description;
return capturedStrings[2];
}];

// Remove escaped HTML entitites or docsetutil will complain.
result = [result stringByReplacingOccurrencesOfString:@"<" withString:@""];
result = [result stringByReplacingOccurrencesOfString:@">" withString:@""];

// Remove embedded prefix/suffix.
result = [result stringByReplacingOccurrencesOfString:self.commentComponents.codeSpanStartMarker withString:@""];
result = [result stringByReplacingOccurrencesOfString:self.commentComponents.codeSpanEndMarker withString:@""];
result = [result stringByReplacingOccurrencesOfString:self.commentComponents.appledocBoldStartMarker withString:@""];
result = [result stringByReplacingOccurrencesOfString:self.commentComponents.appledocBoldEndMarker withString:@""];
return result;
}

- (NSString *)stringByEscapingHTML:(NSString *)string {
// Copied directly from GRMustache's GRMustacheVariableElement.m...
NSMutableString *result = [NSMutableString stringWithCapacity:5 + ceilf(string.length * 1.1)];
[result appendString:string];
[result replaceOccurrencesOfString:@"&" withString:@"&amp;" options:NSLiteralSearch range:NSMakeRange(0, result.length)];
[result replaceOccurrencesOfString:@"<" withString:@"&lt;" options:NSLiteralSearch range:NSMakeRange(0, result.length)];
[result replaceOccurrencesOfString:@">" withString:@"&gt;" options:NSLiteralSearch range:NSMakeRange(0, result.length)];
[result replaceOccurrencesOfString:@"\"" withString:@"&quot;" options:NSLiteralSearch range:NSMakeRange(0, result.length)];
[result replaceOccurrencesOfString:@"'" withString:@"&apos;" options:NSLiteralSearch range:NSMakeRange(0, result.length)];
return result;
}

- (NSString *)stringByReplacingOccurencesOfRegex:(NSString *)regex inHTML:(NSString *)string usingBlock:(NSString *(^)(NSInteger captureCount, NSString **capturedStrings, BOOL insideCode))block {
NSString *theRegex = [NSString stringWithFormat:@"<code>|</code>|%@", regex];
__block BOOL insideExampleBlock = NO;
return [string stringByReplacingOccurrencesOfRegex:theRegex usingBlock:^NSString *(NSInteger captureCount, NSString *const *capturedStrings, const NSRange *capturedRanges, volatile BOOL *const stop) {
// Change flag when inside example block - we need to handle strings differently there!
NSString *matchedText = capturedStrings[0];
if ([matchedText isEqualToString:@"<code>"]) {
insideExampleBlock = YES;
return matchedText;
} else if ([matchedText isEqualToString:@"</code>"]) {
insideExampleBlock = NO;
return matchedText;
}

// Invoke parent block when matched the given regex
NSString **strings = (NSString **)capturedStrings;
return block(captureCount, strings, insideExampleBlock);
}];
}

- (NSString *)htmlReferenceNameForObject:(GBModelBase *)object {
NSParameterAssert(object != nil);
if (object.isTopLevelObject) return [self htmlReferenceForObject:object fromSource:object];
if (object.isStaticDocument) return [self htmlReferenceForObject:object fromSource:object];
return [self htmlReferenceForMember:object prefixedWith:@""];
}

- (NSString *)htmlReferenceForObject:(GBModelBase *)object fromSource:(GBModelBase *)source {
NSParameterAssert(object != nil);

// Generate hrefs from index to objects:
if (!source) {
// To top-level object.
if (object.isTopLevelObject) return [self htmlReferenceForObjectFromIndex:object];
if (object.isStaticDocument) return [self htmlReferenceForObjectFromIndex:object];

// To a member of top-level object.
NSString *path = [self htmlReferenceForObjectFromIndex:object.parentObject];
NSString *memberReference = [self htmlReferenceForMember:object prefixedWith:@"#"];
return [NSString stringWithFormat:@"%@%@", path, memberReference];
}

// Generate hrefs from members to other objects.
if (!source.isTopLevelObject && !source.isStaticDocument) {
GBModelBase *sourceParent = source.parentObject;

// To the parent or another top-level object.
if (object.isTopLevelObject) return [self htmlReferenceForObject:object fromSource:sourceParent];
if (object.isStaticDocument) return [self htmlReferenceForObject:object fromSource:sourceParent];

// To same or another member of the same parent.
if (object.parentObject == sourceParent) return [self htmlReferenceForMember:object prefixedWith:@"#"];

// To a member of another top-level object.
NSString *path = [self htmlReferenceForObject:object.parentObject fromSource:sourceParent];
NSString *memberReference = [self htmlReferenceForMember:object prefixedWith:@"#"];
return [NSString stringWithFormat:@"%@%@", path, memberReference];
}

// From now on we're generating hrefs from top-level object or documents to other documents, top-level objects or their members. First handle links from any kind of object to itself and top-level object or document to top-level object. Handle links from document to document slighlty differently, they are more complicated due to arbitrary directory structure.
if (object == source || object.isTopLevelObject || object.isStaticDocument) return [self htmlReferenceForTopLevelObject:object fromTopLevelObject:source];

// From top-level object or document to top-level object member.
NSString *memberPath = [self htmlReferenceForMember:object prefixedWith:@"#"];
if (object.parentObject != source) {
NSString *objectPath = [self htmlReferenceForTopLevelObject:object.parentObject fromTopLevelObject:source];
return [NSString stringWithFormat:@"%@%@", objectPath, memberPath];
}

// From top-level object to one of it's members.
return memberPath;
}

- (NSString *)htmlReferenceForObjectFromIndex:(GBModelBase *)object {
return [self outputPathForObject:object withExtension:[self htmlExtension]];
}

- (NSString *)htmlReferenceForTopLevelObject:(id)object fromTopLevelObject:(id)source {
// Handles top-level object or document to top-level object or document.
NSString *path = [self outputPathForObject:object withExtension:[self htmlExtension]];
if (object == source) return [path lastPathComponent];
NSString *prefix = [self htmlRelativePathToIndexFromObject:source];
return [prefix stringByAppendingPathComponent:path];
}

- (NSString *)htmlReferenceForMember:(GBModelBase *)member prefixedWith:(NSString *)prefix {
NSParameterAssert(member != nil);
NSParameterAssert(prefix != nil);
if ([member isKindOfClass:[GBMethodData class]]) {
GBMethodData *method = (GBMethodData *)member;
return [NSString stringWithFormat:@"%@//api/name/%@", prefix, method.methodSelector];
}
return @"";
}

- (NSString *)htmlStaticDocumentsSubpath {
return @"docs";
}

- (NSString *)htmlExtension {
return @"html";
}

#pragma mark Common template files helpers

- (BOOL)isPathRepresentingTemplateFile:(NSString *)path {
NSString *filename = [[path lastPathComponent] stringByDeletingPathExtension];
if ([filename hasSuffix:@"-template"]) return YES;
return NO;
}

- (NSString *)outputFilenameForTemplatePath:(NSString *)path {
NSString *result = [path lastPathComponent];
return [result stringByReplacingOccurrencesOfString:@"-template" withString:@""];
}

- (NSString *)templateFilenameForOutputPath:(NSString *)path {
// If the path is already valid template, just return it.
if ([self isPathRepresentingTemplateFile:path]) return path;

// Get all components.
NSString *prefix = [path stringByDeletingLastPathComponent];
NSString *filename = [[[path lastPathComponent] stringByDeletingPathExtension] stringByAppendingString:@"-template"];
NSString *extension = [path pathExtension];

// Prepare the result.
NSString *result = [prefix stringByAppendingPathComponent:filename];
if ([extension length] > 0) result = [result stringByAppendingPathExtension:extension];
return result;
}

#pragma mark Date and time helpers

- (NSString *)yearStringFromDate:(NSDate *)date {
return [self.yearDateFormatter stringFromDate:date];
}

- (NSString *)yearToDayStringFromDate:(NSDate *)date {
return [self.yearToDayDateFormatter stringFromDate:date];
}

- (NSDateFormatter *)yearDateFormatter {
static NSDateFormatter *result = nil;
if (!result) {
result = [[NSDateFormatter alloc] init];
[result setDateFormat:@"yyyy"];
}
return result;
}

- (NSDateFormatter *)yearToDayDateFormatter {
static NSDateFormatter *result = nil;
if (!result) {
result = [[NSDateFormatter alloc] init];
[result setDateFormat:@"yyyy-MM-dd"];
}
return result;
}

#pragma mark Paths helper methods

- (NSString *)outputPathForObject:(id)object withExtension:(NSString *)extension {
// Returns relative path to the given object from the output root (i.e. from the index file).
NSString *basePath = nil;
NSString *name = nil;
if ([object isKindOfClass:[GBClassData class]]) {
basePath = @"Classes";
name = [object nameOfClass];
}
else if ([object isKindOfClass:[GBCategoryData class]]) {
basePath = @"Categories";
name = [object idOfCategory];
}
else if ([object isKindOfClass:[GBProtocolData class]]) {
basePath = @"Protocols";
name = [object nameOfProtocol];
}
else if ([object isKindOfClass:[GBDocumentData class]]) {
GBDocumentData *document = object;

// If this is custom document, just use it's relative path, otherwise take into account the registered path.
if (document.isCustomDocument) {
basePath = document.basePathOfDocument;
name = document.nameOfDocument;
} else {
// Get output filename (removing template suffix) and document subpath without filename. Note that we need to remove extension as we'll add html by default!
NSString *subpath = [document.subpathOfDocument stringByDeletingLastPathComponent];
NSString *filename = [self outputFilenameForTemplatePath:document.pathOfDocument];
filename = [filename stringByDeletingPathExtension];

// If the document is included as part of a directory structure, we should use subdir, otherwise just leave the filename.
if (![document.basePathOfDocument isEqualToString:document.pathOfDocument]) {
NSString *includePath = [document.basePathOfDocument lastPathComponent];
subpath = [includePath stringByAppendingPathComponent:subpath];
}

// Prepare relative path from output path to the document now.
basePath = [self.htmlStaticDocumentsSubpath stringByAppendingPathComponent:subpath];
name = filename;
}
}

if (basePath == nil || name == nil) return nil;
basePath = [basePath stringByAppendingPathComponent:name];
return [basePath stringByAppendingPathExtension:extension];
}

- (NSString *)htmlRelativePathToIndexFromObject:(id)object {
// Returns relative path prefix from the given source to the given destination or empty string if both objects live in the same path. This is pretty simple except when object is a document. In such case we need to handle arbitrary depth.
if ([object isStaticDocument]) {
NSString *subpath = [self outputPathForObject:object withExtension:@"extension"];
subpath = [subpath stringByDeletingLastPathComponent];
if ([subpath length] > 0) {
NSArray *components = [subpath pathComponents];
NSMutableString *result = [NSMutableString stringWithCapacity:[subpath length]];
for (NSUInteger i=0; i<[components count]; i++) [result appendString:@"../"];
return result;
} else {
return @"";
}
}
return @"../";
}

#pragma mark Helper methods

- (BOOL)isTopLevelStoreObject:(id)object {
if ([object isKindOfClass:[GBClassData class]] || [object isKindOfClass:[GBCategoryData class]] || [object isKindOfClass:[GBProtocolData class]])
return YES;
return NO;
}

- (NSString *)stringByReplacingOccurencesOfPlaceholdersInString:(NSString *)string {
string = [string stringByReplacingOccurrencesOfString:kGBTemplatePlaceholderCompanyID withString:self.companyIdentifier];
string = [string stringByReplacingOccurrencesOfString:kGBTemplatePlaceholderProjectID withString:self.projectIdentifier];
string = [string stringByReplacingOccurrencesOfString:kGBTemplatePlaceholderVersionID withString:self.versionIdentifier];
string = [string stringByReplacingOccurrencesOfString:kGBTemplatePlaceholderProject withString:self.projectName];
string = [string stringByReplacingOccurrencesOfString:kGBTemplatePlaceholderCompany withString:self.projectCompany];
string = [string stringByReplacingOccurrencesOfString:kGBTemplatePlaceholderVersion withString:self.projectVersion];
string = [string stringByReplacingOccurrencesOfString:kGBTemplatePlaceholderDocSetBundleFilename withString:self.docsetBundleFilename];
string = [string stringByReplacingOccurrencesOfString:kGBTemplatePlaceholderDocSetAtomFilename withString:self.docsetAtomFilename];
string = [string stringByReplacingOccurrencesOfString:kGBTemplatePlaceholderDocSetPackageFilename withString:self.docsetPackageFilename];
string = [string stringByReplacingOccurrencesOfString:kGBTemplatePlaceholderYear withString:[self yearStringFromDate:[NSDate date]]];
string = [string stringByReplacingOccurrencesOfString:kGBTemplatePlaceholderUpdateDate withString:[self yearToDayStringFromDate:[NSDate date]]];
return string;
}

- (NSString *)stringByNormalizingString:(NSString *)string {
return [string stringByReplacingOccurrencesOfRegex:@"[ \t]+" withString:@"-"];
}

#pragma mark Overriden methods

- (NSString *)description {
return [self className];
}

- (NSString *)debugDescription {
// Based on http://stackoverflow.com/questions/754824/get-an-object-attributes-list-in-objective-c/4008326#4008326
NSMutableString *result = [NSMutableString string];
unsigned int outCount, i;
objc_property_t *properties = class_copyPropertyList([self class], &outCount);
for (i=0; i<outCount; i++) {
objc_property_t property = properties[i];
const char *propName = property_getName(property);
if (propName) {
            NSString *propertyName = [NSString stringWithUTF8String:propName];
NSString *propertyValue = [self valueForKey:propertyName];
[result appendFormat:@"%@ = %@\n", propertyName, propertyValue];
}
}
free(properties);
return result;
}

#pragma mark Properties

- (NSString *)projectIdentifier {
return [self stringByNormalizingString:self.projectName];
}

- (NSString *)versionIdentifier {
return [self stringByNormalizingString:self.projectVersion];
}

@synthesize projectName;
@synthesize projectCompany;
@synthesize projectVersion;
@synthesize companyIdentifier;

@synthesize outputPath;
@synthesize docsetInstallPath;
@synthesize docsetUtilPath;
@synthesize templatesPath;
@synthesize includePaths;
@synthesize indexDescriptionPath;
@synthesize ignoredPaths;
@synthesize excludeOutputPaths;

@synthesize docsetBundleIdentifier;
@synthesize docsetBundleName;
@synthesize docsetCertificateIssuer;
@synthesize docsetCertificateSigner;
@synthesize docsetDescription;
@synthesize docsetFallbackURL;
@synthesize docsetFeedName;
@synthesize docsetFeedURL;
@synthesize docsetPackageURL;
@synthesize docsetMinimumXcodeVersion;
@synthesize docsetPlatformFamily;
@synthesize docsetPublisherIdentifier;
@synthesize docsetPublisherName;
@synthesize docsetCopyrightMessage;

@synthesize docsetBundleFilename;
@synthesize docsetAtomFilename;
@synthesize docsetPackageFilename;

@synthesize repeatFirstParagraphForMemberDescription;
@synthesize useSingleStarForBold;
@synthesize keepUndocumentedObjects;
@synthesize keepUndocumentedMembers;
@synthesize findUndocumentedMembersDocumentation;

@synthesize mergeCategoriesToClasses;
@synthesize keepMergedCategoriesSections;
@synthesize prefixMergedCategoriesSectionsWithCategoryName;

@synthesize prefixLocalMembersInRelatedItemsList;
@synthesize embedCrossReferencesWhenProcessingMarkdown;
@synthesize embedAppledocBoldMarkersWhenProcessingMarkdown;

@synthesize createHTML;
@synthesize createDocSet;
@synthesize installDocSet;
@synthesize publishDocSet;
@synthesize keepIntermediateFiles;
@synthesize cleanupOutputPathBeforeRunning;
@synthesize treatDocSetIndexingErrorsAsFatals;
@synthesize exitCodeThreshold;

@synthesize warnOnMissingOutputPathArgument;
@synthesize warnOnMissingCompanyIdentifier;
@synthesize warnOnUndocumentedObject;
@synthesize warnOnUndocumentedMember;
@synthesize warnOnEmptyDescription;
@synthesize warnOnUnknownDirective;
@synthesize warnOnInvalidCrossReference;
@synthesize warnOnMissingMethodArgument;

@synthesize commentComponents;
@synthesize stringTemplates;

@end
Something went wrong with that request. Please try again.