2
0
Эх сурвалжийг харах

Using the new file API functions to generate documentation with a single call to the generator.

David Piuva 3 жил өмнө
parent
commit
29130f31ee

+ 1 - 1
Doc/Generator/build.sh

@@ -22,4 +22,4 @@ ${ROOT_PATH}/tools/build.sh "${PROJECT_FOLDER}" "${TARGET_FILE}" "${ROOT_PATH}"
 
 # Execute the generation script to see the changes
 chmod +x gen.sh
-./gen.sh ./Input .. ./Resources/
+./gen.sh

+ 2 - 36
Doc/Generator/gen.sh

@@ -1,38 +1,4 @@
 #!/bin/bash
 
-# The root of the source files
-SOURCE_FOLDER=$1
-# The target folder where the library will be created
-TARGET_FOLDER=$2
-# The resource folder where styles are found
-RESOURCE_FOLDER=$3
-
-# Argument: $1 as the folder to generate HTML from
-generateInFolder() {
-	# Convert all the text files into HTML
-	for file in "$1"/*.txt
-	do
-		[ -e $file ] || continue
-		# Get name without path
-		name=${file##*/}
-		# Get name without extension nor path
-		base=${name%.txt}
-		./generator ${file} ${TARGET_FOLDER}/${base}.html ${RESOURCE_FOLDER}
-		if [ $? -ne 0 ]
-		then
-			echo "Failed to convert ${file}!"
-			exit 1
-		fi
-	done
-	# Recursively compile other folders
-	for folder in "$1"/*
-	do
-		if [ -d "$folder" ]
-		then
-			generateInFolder "$folder"
-		fi
-	done
-}
-
-echo "Generating HTML from $SOURCE_FOLDER to $TARGET."
-generateInFolder ${SOURCE_FOLDER}
+# Generate documentation from the folder ./Input to the Doc folder outside at .., using the style in ./Resources.
+./generator ./Input .. ./Resources

+ 44 - 16
Doc/Generator/main.cpp

@@ -1,4 +1,10 @@
 
+/* TODO:
+* Create syntax for automatically including links to outmost documents in a specified folder.
+* Create syntax for automatically documenting methods in specified headers based on above comments.
+  Follow include "", but not include <> when listing types.
+*/
+
 #include "../../Source/DFPSR/includeFramework.h"
 
 using namespace dsr;
@@ -6,7 +12,7 @@ using namespace dsr;
 // This program is only for maintaining the library's documentation,
 //   so it's okay to use features specific to the Linux operating system.
 
-String ResourceFolderPath;
+String resourceFolderPath;
 
 bool string_beginsWith(const ReadableString &a, const ReadableString &b) {
 	return string_caseInsensitiveMatch(string_before(a, string_length(b)), b);
@@ -96,7 +102,7 @@ void processContent(String &target, String content) {
 }
 
 String generateHtml(String content) {
-	String style = string_load(ResourceFolderPath + U"Default.css");
+	String style = string_load(file_combinePaths(resourceFolderPath, U"Default.css"));
 	String result = U"<!DOCTYPE html> <HTML lang=en> <HEAD> <STYLE>\n";
 	string_append(result, style);
 	string_append(result, U"</STYLE> </HEAD> <BODY>\n");
@@ -108,20 +114,42 @@ String generateHtml(String content) {
 	return result;
 }
 
-int main(int argn, char **argv) {
-	if (argn != 4) {
-		printText(U"The generator needs filenames for target!\n");
-		return 1;
+static ReadableString getExtensionless(const String& filename) {
+	int lastDotIndex = string_findLast(filename, U'.');
+	if (lastDotIndex != -1) {
+		return string_removeOuterWhiteSpace(string_before(filename, lastDotIndex));
+	} else {
+		return U"?";
 	}
-	String SourceFilePath = argv[1];
-	String TargetFilePath = argv[2];
-	ResourceFolderPath = argv[3];
+}
+
+void processFolder(const ReadableString& sourceFolderPath, const ReadableString& targetFolderPath) {
+	file_getFolderContent(sourceFolderPath, [targetFolderPath](const ReadableString& sourcePath, const ReadableString& entryName, EntryType entryType) {
+		printText("* Entry: ", entryName, " as ", entryType, "\n");
+		if (entryType == EntryType::Folder) {
+			// TODO: Create new output folders if needed for nested output.
+			//processFolder(sourcePath, file_combinePaths(targetFolderPath, entryName));
+		} else if (entryType == EntryType::File) {
+			ReadableString extensionless = getExtensionless(entryName);
+			String targetPath = file_combinePaths(targetFolderPath, extensionless + U".html");
+			printText(U"Generating ", targetPath, U" from ", sourcePath, U" using the style ", resourceFolderPath, U"\n");
+			String content = string_load(sourcePath);
+			String result = generateHtml(content);
+			string_save(file_combinePaths(targetFolderPath, targetPath), result);
+		}
+	});
+}
 
-	printText(U"Generating ", TargetFilePath, U" from ", SourceFilePath, U" using the style", ResourceFolderPath, U"\n");
-	
-	String content = string_load(SourceFilePath);
-	String result = generateHtml(content);
-	string_save(TargetFilePath, result);
-	printText(U"Done\n");
-	return 0;
+DSR_MAIN_CALLER(dsrMain)
+void dsrMain(List<String> args) {
+	if (args.length() != 4) {
+		printText(U"The generator needs input, output and resource folder paths as three arguments!\n");
+	} else {
+		String sourceFolderPath = file_getAbsolutePath(args[1]);
+		String targetFolderPath = file_getAbsolutePath(args[2]);
+		resourceFolderPath = args[3];
+		printText(U"Processing ", targetFolderPath, U" from ", sourceFolderPath, U" using the style ", resourceFolderPath, U"\n");
+		processFolder(sourceFolderPath, targetFolderPath);
+		printText(U"Done\n");
+	}
 }