Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Refactored output paths handling to use template paths as much as pos…

…sible.

This decouples code from template locations. At the moment only classes, categories and protocols are manually copied to output locations.
  • Loading branch information...
commit fb727bed4aec1ebd1bc01b67902065cdbbbd12b2 1 parent 935b104
@tomaz authored
View
18 Generating/GBDocSetOutputGenerator.m
@@ -68,7 +68,7 @@ - (BOOL)moveSourceFilesToDocuments:(NSError **)error {
// Prepare all paths. Note that we determine the exact subdirectory by searching for documents-template and using it's subdirectory as the guide. If documents template wasn't found, exit.
NSString *sourceFilesPath = [self.previousGenerator.outputUserPath stringByStandardizingPath];
- NSString *documentsPath = [self templateFileKeyEndingWith:@"documents-template"];
+ NSString *documentsPath = [self outputPathToTemplateEndingWith:@"documents-template"];
if (!documentsPath) {
if (error) *error = [NSError errorWithCode:GBErrorDocSetDocumentTemplateMissing description:@"Documents template is missing!" reason:@"documents-template file is required to determine location for Documents path in DocSet bundle!"];
GBLogWarn(@"Failed finding documents-template in '%@'!", self.templateUserPath);
@@ -76,9 +76,7 @@ - (BOOL)moveSourceFilesToDocuments:(NSError **)error {
}
// First step is to move all files generated by previous generator as the Documents subfolder of docset structure.
- documentsPath = [documentsPath stringByDeletingLastPathComponent];
- NSString *destPath = [self.outputUserPath stringByAppendingPathComponent:documentsPath];
- NSString *movePath = [destPath stringByAppendingPathComponent:@"Documents"];
+ NSString *movePath = [documentsPath stringByAppendingPathComponent:@"Documents"];
if (![self.fileManager moveItemAtPath:sourceFilesPath toPath:[movePath stringByStandardizingPath] error:error]) {
GBLogWarn(@"Failed moving files from '%@' to '%@'!", self.previousGenerator.outputUserPath, movePath);
return NO;
@@ -88,7 +86,7 @@ - (BOOL)moveSourceFilesToDocuments:(NSError **)error {
- (BOOL)processInfoPlist:(NSError **)error {
GBLogInfo(@"Writting DocSet Info.plist...");
- NSString *templatePath = [self templateFileKeyEndingWith:@"info-template.plist"];
+ NSString *templatePath = [self outputPathToTemplateEndingWith:@"info-template.plist"];
if (!templatePath) {
if (error) *error = [NSError errorWithCode:GBErrorDocSetInfoPlistTemplateMissing description:@"Info.plist template is missing!" reason:@"info-template.plist file is required to specify information about DocSet!"];
GBLogWarn(@"Failed finding info-template.plist in '%@'!", self.templateUserPath);
@@ -115,8 +113,7 @@ - (BOOL)processInfoPlist:(NSError **)error {
// Run the template and save the results as Info.plist.
GBTemplateHandler *handler = [self.templateFiles objectForKey:templatePath];
NSString *output = [handler renderObject:vars];
- NSString *path = [[templatePath stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"Info.plist"];
- NSString *filename = [self.outputUserPath stringByAppendingPathComponent:path];
+ NSString *filename = [templatePath stringByAppendingPathComponent:@"Info.plist"];
if (![self writeString:output toFile:[filename stringByStandardizingPath] error:error]) {
GBLogWarn(@"Failed writting Info.plist to '%@'!", filename);
return NO;
@@ -126,7 +123,7 @@ - (BOOL)processInfoPlist:(NSError **)error {
- (BOOL)processNodesXml:(NSError **)error {
GBLogInfo(@"Writting DocSet Nodex.xml file...");
- NSString *templatePath = [self templateFileKeyEndingWith:@"nodes-template.xml"];
+ NSString *templatePath = [self outputPathToTemplateEndingWith:@"nodes-template.xml"];
if (!templatePath) {
if (error) *error = [NSError errorWithCode:GBErrorDocSetNodesTemplateMissing description:@"Nodes.xml template is missing!" reason:@"nodes-template.xml file is required to specify document structure for DocSet!"];
GBLogWarn(@"Failed finding nodes-template.xml in '%@'!", self.templateUserPath);
@@ -148,8 +145,7 @@ - (BOOL)processNodesXml:(NSError **)error {
// Run the template and save the results.
GBTemplateHandler *handler = [self.templateFiles objectForKey:templatePath];
NSString *output = [handler renderObject:vars];
- NSString *path = [[templatePath stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"Nodes.xml"];
- NSString *filename = [self.outputUserPath stringByAppendingPathComponent:path];
+ NSString *filename = [templatePath stringByAppendingPathComponent:@"Nodes.xml"];
[self.temporaryFiles addObject:filename];
if (![self writeString:output toFile:[filename stringByStandardizingPath] error:error]) {
GBLogWarn(@"Failed writting Nodes.xml to '%@'!", filename);
@@ -162,7 +158,7 @@ - (BOOL)processTokensXml:(NSError **)error {
GBLogInfo(@"Writting DocSet Tokens.xml files...");
// Get the template and prepare single Tokens.xml file for each object.
- NSString *templatePath = [self templateFileKeyEndingWith:@"tokens-template.xml"];
+ NSString *templatePath = [self templatePathForTemplateEndingWith:@"tokens-template.xml"];
if (!templatePath) {
GBLogWarn(@"Didn't find tokens-template.xml in '%@', DocSet will not be indexed!", self.templateUserPath);
return YES;
View
10 Generating/GBHTMLOutputGenerator.m
@@ -172,14 +172,16 @@ - (NSString *)stringByCleaningHtml:(NSString *)string {
- (NSString *)htmlOutputPathForIndex {
// Returns file name including full path for HTML file representing the main index.
- NSString *result = [self.outputUserPath stringByAppendingPathComponent:@"index"];
- return [result stringByAppendingPathExtension:self.settings.htmlExtension];
+ NSString *path = [self outputPathToTemplateEndingWith:@"index-template.html"];
+ path = [path stringByAppendingPathComponent:@"index"];
+ return [path 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 *path = [self outputPathToTemplateEndingWith:@"hierarchy-template.html"];
+ path = [path stringByAppendingPathComponent:@"hierarchy"];
+ return [path stringByAppendingPathExtension:self.settings.htmlExtension];
}
- (NSString *)htmlOutputPathForObject:(GBModelBase *)object {
View
21 Generating/GBOutputGenerator.h
@@ -86,15 +86,27 @@
/// @name Subclass parameters and helpers
///---------------------------------------------------------------------------------------
-/** Searches `templateFiles` dictionary for a key ending with the given suffix and returns the whole key if found.
+/** Returns the full path to the template ending with the given string.
- If the key is not found, `nil` is returned. This method is useful for finding keys for which we only know partial name (ussually the name of the file, but not the path to it).
+ The method searches `templateFiles` for a key ending with the given suffix and returns full path to the given template. This is useful for getting the template for which we only know filename, but not the whole path for example.
@param suffix Template file suffix to search for.
- @return Returns full key if found, `nil` otherwise.
+ @return Returns template path to the given template or `nil` if not found.
+ @see outputPathToTemplateEndingWith:
@see templateFiles
*/
-- (NSString *)templateFileKeyEndingWith:(NSString *)suffix;
+- (NSString *)templatePathForTemplateEndingWith:(NSString *)suffix;
+
+/** Returns the path to the template ending with the given string.
+
+ The method searches `templateFiles` for a key ending with the given suffix and returns the path to the output directory corresponding to the given template subpath. This is useful for generating actual template file names - just append the desired filename and you have output file name ready!
+
+ @param suffix Template file suffix to search for.
+ @return Returns output path corresponding to the given template or `nil` if not found.
+ @see templatePathForTemplateEndingWith:
+ @see templateFiles
+ */
+- (NSString *)outputPathToTemplateEndingWith:(NSString *)suffix;
/** The dictionary of all template files detected within `copyTemplateFilesToOutputPath:`.
@@ -103,7 +115,6 @@
This is intended to be used within subclasses only. Dictionary contents are automatically updated and should not be changed by subclasses.
@see copyTemplateFilesToOutputPath:
- @see templateFileKeyEndingWith:
*/
@property (readonly) NSMutableDictionary *templateFiles;
View
11 Generating/GBOutputGenerator.m
@@ -125,13 +125,22 @@ - (BOOL)isPathRepresentingIgnoredFile:(NSString *)path {
#pragma mark Helper methods
-- (NSString *)templateFileKeyEndingWith:(NSString *)suffix {
+- (NSString *)templatePathForTemplateEndingWith:(NSString *)suffix {
for (NSString *template in [self.templateFiles allKeys]) {
if ([template hasSuffix:suffix]) return template;
}
return nil;
}
+- (NSString *)outputPathToTemplateEndingWith:(NSString *)suffix {
+ NSString *template = [self templatePathForTemplateEndingWith:suffix];
+ if (template) {
+ NSString *path = [template substringToIndex:[template length] - [suffix length]];
+ return [self.outputUserPath stringByAppendingPathComponent:path];
+ }
+ return nil;
+}
+
- (BOOL)writeString:(NSString *)string toFile:(NSString *)path error:(NSError **)error {
NSString *standardized = [path stringByStandardizingPath];
NSString *directory = [standardized stringByDeletingLastPathComponent];
Please sign in to comment.
Something went wrong with that request. Please try again.