Permalink
Browse files

Refactored output files extension handling.

Instead of hard coding the extension to the clean XML, $EXTENSION placeholder string is used. This is eventually converted to proper extension by concrete GeneratorBase subclasses.

Note that since documentation set generation relies on XHTMLGenerator, it needs to know how to convert the placeholders as well. This brings close coupling between the two objects, but then XHTML generator creates the foundation for the documentation set generation anyway...
  • Loading branch information...
tomaz committed Jun 6, 2009
1 parent b6420bc commit 9a378d4811741fdfc7f7987cf60c42f9abbf9e56
@@ -34,13 +34,9 @@ - (void) createCleanOutputDocumentation
@try
{
- // Convert the index file.
- NSString* indexFilename = [cmd.outputCleanXHTMLPath stringByAppendingPathComponent:@"index.html"];
- [generator generateOutputForIndex:database toFile:indexFilename];
-
- // Convert the hierarchy file.
- NSString* hierarchyFilename = [cmd.outputCleanXHTMLPath stringByAppendingPathComponent:@"hierarchy.html"];
- [generator generateOutputForHierarchy:database toFile:hierarchyFilename];
+ // Convert the index and hierarchy files.
+ [generator generateOutputForIndex:database];
+ [generator generateOutputForHierarchy:database];
// Convert the object files.
NSDictionary* objects = [database objectForKey:kTKDataMainObjectsKey];
@@ -50,10 +46,7 @@ - (void) createCleanOutputDocumentation
loopAutoreleasePool = [[NSAutoreleasePool alloc] init];
NSDictionary* objectData = [objects objectForKey:objectName];
- NSString* relativePath = [objectData objectForKey:kTKDataObjectRelPathKey];
- NSString* filename = [cmd.outputCleanXHTMLPath stringByAppendingPathComponent:relativePath];
-
- [generator generateOutputForObject:objectData toFile:filename];
+ [generator generateOutputForObject:objectData];
}
// If cleantemp is used, remove clean XML temporary files.
@@ -147,7 +147,7 @@ - (void) createCleanObjectDocumentationMarkup
}
NSString* objectRelativePath = [objectRelativeDirectory stringByAppendingPathComponent:objectName];
- objectRelativePath = [objectRelativePath stringByAppendingPathExtension:@"html"];
+ objectRelativePath = [objectRelativePath stringByAppendingString:kTKPlaceholderExtension];
// (F) OK, now really add the node to the database... ;) First create the
// object's description dictionary. Then add the object to the Objects
@@ -1365,10 +1365,10 @@ - (NSString*) objectReferenceFromObject:(NSString*) source
// If the two subdirectories are not the same, we should prepend the relative path.
if (![sourceSubdir isEqualToString:destinationSubdir])
{
- return [NSString stringWithFormat:@"../%@/%@.html", destinationSubdir, destination];
+ return [NSString stringWithFormat:@"../%@/%@%@", destinationSubdir, destination, kTKPlaceholderExtension];
}
- return [NSString stringWithFormat:@"%@.html", destination];
+ return [NSString stringWithFormat:@"%@%@", destination, kTKPlaceholderExtension];
}
//----------------------------------------------------------------------------------------
View
@@ -7,6 +7,7 @@
//
#import "DoxygenConverter+DocSet.h"
+#import "XHTMLGenerator.h"
#import "CommandLineParser.h"
#import "LoggingProvider.h"
#import "Systemator.h"
@@ -87,6 +88,8 @@ - (void) createDocSetNodesFile
logNormal(@"Creating DocSet Nodes.xml file...");
NSAutoreleasePool* loopAutoreleasePool = [[NSAutoreleasePool alloc] init];
NSXMLDocument* document = [NSXMLDocument document];
+ NSString* indexFileName = [XHTMLGenerator indexFileName];
+ NSString* hierarchyFileName = [XHTMLGenerator hierarchyFileName];
// Create the version and ecoding elements.
[document setVersion:@"1.0"];
@@ -106,7 +109,7 @@ - (void) createDocSetNodesFile
[tocElement addChild:indexNodeElement];
NSXMLElement* indexNameElement = [NSXMLNode elementWithName:@"Name" stringValue:cmd.projectName];
[indexNodeElement addChild:indexNameElement];
- NSXMLElement* indexPathElement = [NSXMLNode elementWithName:@"Path" stringValue:@"index.html"];
+ NSXMLElement* indexPathElement = [NSXMLNode elementWithName:@"Path" stringValue:indexFileName];
[indexNodeElement addChild:indexPathElement];
NSXMLElement* indexSubnodesElement = [NSXMLNode elementWithName:@"Subnodes"];
[indexNodeElement addChild:indexSubnodesElement];
@@ -123,7 +126,7 @@ - (void) createDocSetNodesFile
[indexSubnodesElement addChild:directoryNodeElement];
NSXMLElement* directoryNameElement = [NSXMLNode elementWithName:@"Name" stringValue:directoryName];
[directoryNodeElement addChild:directoryNameElement];
- NSXMLElement* directoryPathElement = [NSXMLNode elementWithName:@"Path" stringValue:@"index.html"];
+ NSXMLElement* directoryPathElement = [NSXMLNode elementWithName:@"Path" stringValue:indexFileName];
[directoryNodeElement addChild:directoryPathElement];
NSXMLElement* directorySubnodesElement = [NSXMLNode elementWithName:@"Subnodes"];
[directoryNodeElement addChild:directorySubnodesElement];
@@ -132,9 +135,10 @@ - (void) createDocSetNodesFile
// simply links to the main "Objects" dictionary, so we can use the data from there.
NSArray* directoryObjects = [directories objectForKey:directoryName];
for (NSDictionary* objectData in directoryObjects)
- {
+ {
NSString* objectName = [objectData objectForKey:kTKDataObjectNameKey];
NSString* objectPath = [objectData objectForKey:kTKDataObjectRelPathKey];
+ objectPath = [XHTMLGenerator pathByReplacingPlaceholders:objectPath];
NSXMLElement* objectElement = [NSXMLNode elementWithName:@"Node"];
[directorySubnodesElement addChild:objectElement];
@@ -151,7 +155,7 @@ - (void) createDocSetNodesFile
[indexSubnodesElement addChild:hierarchyNodeElement];
NSXMLElement* hierarchyNameElement = [NSXMLNode elementWithName:@"Name" stringValue:@"Class hierarchy"];
[hierarchyNodeElement addChild:hierarchyNameElement];
- NSXMLElement* hierarchyPathElement = [NSXMLNode elementWithName:@"Path" stringValue:@"hierarchy.html"];
+ NSXMLElement* hierarchyPathElement = [NSXMLNode elementWithName:@"Path" stringValue:hierarchyFileName];
[hierarchyNodeElement addChild:hierarchyPathElement];
NSXMLElement* hierarchySubnodesElement = [NSXMLNode elementWithName:@"Subnodes"];
[hierarchyNodeElement addChild:hierarchySubnodesElement];
@@ -202,9 +206,10 @@ - (void) createDocSetTokesFile
{
// Get required object data.
NSDictionary* objectData = [objects objectForKey:objectName];
+ NSXMLDocument* objectDocument = [objectData objectForKey:kTKDataObjectMarkupKey];
NSString* objectKind = [objectData objectForKey:kTKDataObjectKindKey];
NSString* objectRelPath = [objectData objectForKey:kTKDataObjectRelPathKey];
- NSXMLDocument* objectDocument = [objectData objectForKey:kTKDataObjectMarkupKey];
+ objectRelPath = [XHTMLGenerator pathByReplacingPlaceholders:objectRelPath];
// Prepare the object identifier.
NSString* objectIdentifier = nil;
@@ -381,7 +386,9 @@ - (void) addDocSetNodeToElement:(NSXMLElement*) parent
NSDictionary* objectData = [data objectForKey:kTKDataHierarchyObjectDataKey];
NSString* objectName = [data objectForKey:kTKDataHierarchyObjectNameKey];
NSString* objectPath = [objectData objectForKey:kTKDataObjectRelPathKey];
- if (!objectPath) objectPath = @"hierarchy.html";
+ objectPath = objectPath ?
+ [XHTMLGenerator pathByReplacingPlaceholders:objectPath] :
+ [XHTMLGenerator hierarchyFileName];
// Create the main node that will represent the object.
NSXMLElement* node = [NSXMLNode elementWithName:@"Node"];
View
@@ -8,7 +8,8 @@
#import <Foundation/Foundation.h>
-#define kTKConverterException @"TKConverterException"
+#define kTKConverterException @"TKConverterException"
+#define kTKPlaceholderExtension @"$EXTENSION"
#define kTKDirClasses @"Classes"
#define kTKDirCategories @"Categories"
@@ -124,6 +124,17 @@ Note that this method always returns the first subitem if more than one exists.
- (id) extractSubitemFromItem:(id) item
withName:(NSString*) name;
+/** Converts the given path by replacing the placeholder texts.
+
+This method is provided so that subclasses can use standardized way of replacing path
+placeholders. It replaces extension placeholder with the extension returned from
+@c GeneratorBase::outputFilesExtension().
+
+@param path The path for which to replace placeholders.
+@return Returns a new autoreleased @c NSString containing correct path.
+*/
+- (NSString*) convertPathByReplacingPlaceholders:(NSString*) path;
+
//////////////////////////////////////////////////////////////////////////////////////////
/// @name Helper generation methods
//////////////////////////////////////////////////////////////////////////////////////////
@@ -80,6 +80,13 @@ - (id) extractSubitemFromItem:(id) item
return nil;
}
+//----------------------------------------------------------------------------------------
+- (NSString*) convertPathByReplacingPlaceholders:(NSString*) path
+{
+ return [path stringByReplacingOccurrencesOfString:kTKPlaceholderExtension
+ withString:[self outputFilesExtension]];
+}
+
//////////////////////////////////////////////////////////////////////////////////////////
#pragma mark Helper methods
//////////////////////////////////////////////////////////////////////////////////////////
@@ -85,7 +85,7 @@ - (NSString*) hierarchyTitle
//----------------------------------------------------------------------------------------
- (NSXMLDocument*) hierarchyMarkup
{
- return [hierarchyData objectForKey:kTKDataMainHierarchyKey];
+ return hierarchyMarkup;
}
@end
@@ -65,7 +65,7 @@ - (NSString*) indexTitle
//----------------------------------------------------------------------------------------
- (NSXMLDocument*) indexMarkup
{
- return [indexData objectForKey:kTKDataMainIndexKey];
+ return indexMarkup;
}
@end
@@ -158,7 +158,7 @@ - (NSString*) objectClass
//----------------------------------------------------------------------------------------
- (NSXMLDocument*) objectMarkup
{
- return [objectData objectForKey:kTKDataObjectMarkupKey];
+ return objectMarkup;
}
//----------------------------------------------------------------------------------------
View
@@ -64,9 +64,9 @@ make their job easier.
Each concrete subclass can convert three types of files - index, hierarchy and object files.
The subclass can only override the methods for generating output that makes sense for the
-implemented output type. The clients send @c generateOutputForIndex:toFile:() to generate the
-main index file, @c generateOutputForHierarchy:toFile:() to generate the main hierarchy
-file and @c generateOutputForObject:toFile:() to generate the documentation for
+implemented output type. The clients send @c generateOutputForIndex:() to generate the
+main index file, @c generateOutputForHierarchy:() to generate the main hierarchy
+file and @c generateOutputForObject:() to generate the documentation for
individual objects.
In all cases, there are two options for generating output in the subclass. The first is
@@ -80,14 +80,14 @@ intermediate results which it can store to class variables and then use to gener
complete output at the end of appending). If the subclass requires more control, it can
also override @c outputDataForObject(), @c outputDataForIndex() and/or
@c outputDataForHierarchy() methods and handle the data in a completely custom way
-(@c outputDataForObject() message is sent from @c generateOutputForObject:toFile:() which
+(@c outputDataForObject() message is sent from @c generateOutputForObject:() which
sets the class properties with the object data, so the subclass can use these to make
-it's life easier. Similarly, @c outputDataForIndex() is sent from @c generateOutputForIndex:toFile:()
-and @c outputDataForHierarchy() from @c generateOutputForHierarchy:toFile:()).
+it's life easier. Similarly, @c outputDataForIndex() is sent from @c generateOutputForIndex:()
+and @c outputDataForHierarchy() from @c generateOutputForHierarchy:()).
The class is designed so that the same instance can be re-used for generation of several
-objects by simply sending the instance @c generateOutputForObject:toFile:() message,
-@c generateOutputForIndex:toFile:() and/or @c generateOutputForHierarchy:toFile:() with
+objects by simply sending the instance @c generateOutputForObject:() message,
+@c generateOutputForIndex:() and/or @c generateOutputForHierarchy:() with
the required data.
*/
@interface GeneratorBase : NSObject
@@ -96,6 +96,9 @@ the required data.
NSDictionary* objectData;
NSDictionary* indexData;
NSDictionary* hierarchyData;
+ NSXMLDocument* objectMarkup;
+ NSXMLDocument* indexMarkup;
+ NSXMLDocument* hierarchyMarkup;
NSString* projectName;
NSString* lastUpdated;
BOOL wasFileCreated;
@@ -114,15 +117,12 @@ the receiver several messages that can be used to convert the data. When convers
finishes, the data is saved to the given file.
@param data An @c NSDictionary that describes the object for which output is generated.
-@param filename The name of the file to save to.
-@exception NSException Thrown if the given @c data or @c filename is @c nil or empty or
- output generation or saving to file fails.
+@exception NSException Thrown if the given @c data or saving to file fails.
@see outputDataForObject
-@see generateOutputForIndex:toFile:
-@see generateOutputForHierarchy:toFile:
+@see generateOutputForIndex:
+@see generateOutputForHierarchy:
*/
-- (void) generateOutputForObject:(NSDictionary*) data
- toFile:(NSString*) filename;
+- (void) generateOutputForObject:(NSDictionary*) data;
/** Generates the output data from the given index data.
@@ -133,15 +133,12 @@ the receiver several messages that can be used to convert the data. When convers
finishes, the data is saved to the given file.
@param data The main database @c NSDictionary that describes all objects and data.
-@param filename The name of the file to save to.
-@exception NSException Thrown if the given @c data or @c filename is @c nil or empty or
- output generation or saving to file fails.
+@exception NSException Thrown if the given @c data or saving to file fails.
@see outputDataForIndex
-@see generateOutputForObject:toFile:
-@see generateOutputForHierarchy:toFile:
+@see generateOutputForObject:
+@see generateOutputForHierarchy:
*/
-- (void) generateOutputForIndex:(NSDictionary*) data
- toFile:(NSString*) filename;
+- (void) generateOutputForIndex:(NSDictionary*) data;
/** Generates the output data from the given hierarchy data.
@@ -152,15 +149,12 @@ the receiver several messages that can be used to convert the data. When convers
finishes, the data is saved to the given file.
@param data The main database @c NSDictionary that describes all objects and data.
-@param filename The name of the file to save to.
-@exception NSException Thrown if the given @c data or @c filename is @c nil or empty or
- output generation or saving to file fails.
+@exception NSException Thrown if the given @c data or saving to file fails.
@see outputDataForHierarchy
-@see generateOutputForObject:toFile:
-@see generateOutputForIndex:toFile:
+@see generateOutputForObject:
+@see generateOutputForIndex:
*/
-- (void) generateOutputForHierarchy:(NSDictionary*) data
- toFile:(NSString*) filename;
+- (void) generateOutputForHierarchy:(NSDictionary*) data;
/** Indicates that the output generation is starting.
@@ -193,7 +187,7 @@ indeed created.
/** Generates the output data from the data contained in the class properties.
-This message is sent from @c generateOutputForObject:toFile:() after the passed object data
+This message is sent from @c generateOutputForObject:() after the passed object data
is stored in the class properties. The concrete subclasses that require full control over
the generated data, can override this method and return the desired output. If overriden,
the subclass can get the XML document through the @c objectMarkup property.
@@ -223,15 +217,15 @@ on the object data. Messages marked with @a * are optional, while messages marke
@return Returns an autoreleased @c NSData containing generated output.
@exception NSException Thrown if generation fails.
-@see generateOutputForObject:toFile:
+@see generateOutputForObject:
@see outputDataForIndex
@see outputDataForHierarchy
*/
- (NSData*) outputDataForObject;
/** Generates the output data from the data contained in the class properties.
-This message is sent from @c generateOutputForIndex:toFile:() after the passed object data
+This message is sent from @c generateOutputForIndex:() after the passed object data
is stored in the class properties. The concrete subclasses that require full control over
the generated data, can override this method and return the desired output. If overriden,
the subclass can get the database @c NSDictionary data through the @c indexMarkup() property.
@@ -250,15 +244,15 @@ on the object data. Messages marked with @a * are optional, while messages marke
@return Returns an autoreleased @c NSData containing generated output.
@exception NSException Thrown if generation fails.
-@see generateOutputForIndex:toFile:
+@see generateOutputForIndex:
@see outputDataForObject
@see outputDataForHierarchy
*/
- (NSData*) outputDataForIndex;
/** Generates the output data from the data contained in the class properties.
-This message is sent from @c generateOutputForHierarchy:toFile:() after the passed object
+This message is sent from @c generateOutputForHierarchy:() after the passed object
data is stored in the class properties. The concrete subclasses that require full control
over the generated data, can override this method and return the desired output. If
overriden, the subclass can get the database @c NSDictionary data through the
@@ -289,28 +283,38 @@ on the object data. Messages marked with @a * are optional, while messages marke
@c generateHierarchyGroupChildrenToData:forItem:() and
@c appendHierarchyGroupItemToData:fromItem:index:(), however do not fear, since the
base class method will automatically stop when no more children are detected.
-@see generateOutputForHierarchy:toFile:
+@see generateOutputForHierarchy:
@see outputDataForObject
@see outputDataForIndex
*/
- (NSData*) outputDataForHierarchy;
+/** Returns the output files extension.
+
+Subclasses must override this and return proper files extension. Default implementation
+throws an exception in case the subclass would forget to override.
+
+@return Returns the extension to use for the file, including the dot char.
+@exception NSException Thrown from the base class implementation.
+*/
+- (NSString*) outputFilesExtension;
+
//////////////////////////////////////////////////////////////////////////////////////////
/// @name Properties
//////////////////////////////////////////////////////////////////////////////////////////
/** Sets or returns the project name.
-Clients should set this value prior to sending @c generateOutputForObject:toFile:() or
-@c generateOutputForIndex:toFile:() messages. If the value is non @c nil and is not an empty
+Clients should set this value prior to sending @c generateOutputForObject:() or
+@c generateOutputForIndex:() messages. If the value is non @c nil and is not an empty
string, the value can be used by the concrete generators to indicate the project name.
*/
@property(copy) NSString* projectName;
/** Sets or returns the last updated date.
-Clients should set this value prior to sending @c generateOutputForObject:toFile:() or
-@c generateOutputForIndex:toFile:() messages. If the value is non @c nil and is not an empty,
+Clients should set this value prior to sending @c generateOutputForObject:() or
+@c generateOutputForIndex:() messages. If the value is non @c nil and is not an empty,
the value can be used by the concrete generators to indicate the time of the last update.
*/
@property(copy) NSString* lastUpdated;
Oops, something went wrong.

0 comments on commit 9a378d4

Please sign in to comment.