From b9d8122525f234889387127da1aa80122178d939 Mon Sep 17 00:00:00 2001 From: kovacsv Date: Sat, 14 Jan 2023 21:58:59 +0100 Subject: [PATCH] Refactor documentation generation. --- docs/{Camera.html => Class_Camera.html} | 52 +-- ...eSettings.html => Class_EdgeSettings.html} | 54 +-- ...dViewer.html => Class_EmbeddedViewer.html} | 122 +++--- ...gs.html => Class_EnvironmentSettings.html} | 52 +-- docs/{InputFile.html => Class_InputFile.html} | 40 +- docs/{RGBAColor.html => Class_RGBAColor.html} | 62 +-- docs/{RGBColor.html => Class_RGBColor.html} | 62 +-- .../{CameraMode.html => Enum_CameraMode.html} | 32 +- .../{FileSource.html => Enum_FileSource.html} | 32 +- ...html => Function_Init3DViewerElement.html} | 50 +-- ...tml => Function_Init3DViewerElements.html} | 44 +-- ...l => Function_SetExternalLibLocation.html} | 42 +-- ....html => Page_ContributionGuidelines.html} | 32 +- ...upPage.html => Page_EnvironmentSetup.html} | 32 +- ...lationPage.html => Page_Installation.html} | 32 +- docs/{UsagePage.html => Page_Usage.html} | 32 +- docs/index.html | 39 +- ...sPage.html => ContributionGuidelines.html} | 0 ...ntSetupPage.html => EnvironmentSetup.html} | 0 ...nstallationPage.html => Installation.html} | 0 docs/source/{UsagePage.html => Usage.html} | 0 docs/source/config.json | 8 +- docs/source/index.html | 7 +- docs/static/style.css | 8 +- tools/generate_docs.py | 357 ++---------------- tools/lib/doc_entities.py | 157 ++++++++ tools/lib/doc_generator.py | 86 +++++ tools/lib/doc_utils.py | 89 +++++ tools/lib/html_generator.py | 36 ++ 29 files changed, 812 insertions(+), 747 deletions(-) rename docs/{Camera.html => Class_Camera.html} (58%) rename docs/{EdgeSettings.html => Class_EdgeSettings.html} (54%) rename docs/{EmbeddedViewer.html => Class_EmbeddedViewer.html} (51%) rename docs/{EnvironmentSettings.html => Class_EnvironmentSettings.html} (54%) rename docs/{InputFile.html => Class_InputFile.html} (60%) rename docs/{RGBAColor.html => Class_RGBAColor.html} (61%) rename docs/{RGBColor.html => Class_RGBColor.html} (58%) rename docs/{CameraMode.html => Enum_CameraMode.html} (59%) rename docs/{FileSource.html => Enum_FileSource.html} (62%) rename docs/{Init3DViewerElement.html => Function_Init3DViewerElement.html} (54%) rename docs/{Init3DViewerElements.html => Function_Init3DViewerElements.html} (51%) rename docs/{SetExternalLibLocation.html => Function_SetExternalLibLocation.html} (52%) rename docs/{ContributionGuidelinesPage.html => Page_ContributionGuidelines.html} (66%) rename docs/{EnvironmentSetupPage.html => Page_EnvironmentSetup.html} (77%) rename docs/{InstallationPage.html => Page_Installation.html} (66%) rename docs/{UsagePage.html => Page_Usage.html} (78%) rename docs/source/{ContributionGuidelinesPage.html => ContributionGuidelines.html} (100%) rename docs/source/{EnvironmentSetupPage.html => EnvironmentSetup.html} (100%) rename docs/source/{InstallationPage.html => Installation.html} (100%) rename docs/source/{UsagePage.html => Usage.html} (100%) create mode 100644 tools/lib/doc_entities.py create mode 100644 tools/lib/doc_generator.py create mode 100644 tools/lib/doc_utils.py create mode 100644 tools/lib/html_generator.py diff --git a/docs/Camera.html b/docs/Class_Camera.html similarity index 58% rename from docs/Camera.html rename to docs/Class_Camera.html index 310074c..e69ae86 100644 --- a/docs/Camera.html +++ b/docs/Class_Camera.html @@ -25,34 +25,34 @@ @@ -60,9 +60,9 @@

Camera

Camera object.

Constructor

-
-
new Camera (eye, center, up, fov)
-
Parameters
+
+
new Camera (eye, center, up, fov)
+
Parameters
eye Coord3D @@ -93,13 +93,13 @@

Methods

-
-
Clone ()
-
Description
-
Creates a clone of the object.
-
Returns
-
-Camera +
+
Clone ()
+
Description
+
Creates a clone of the object.
+
Returns
+
diff --git a/docs/EdgeSettings.html b/docs/Class_EdgeSettings.html similarity index 54% rename from docs/EdgeSettings.html rename to docs/Class_EdgeSettings.html index a73bdff..2d6442f 100644 --- a/docs/EdgeSettings.html +++ b/docs/Class_EdgeSettings.html @@ -25,34 +25,34 @@
@@ -60,9 +60,9 @@

EdgeSettings

Edge settings object.

Constructor

-
-
new EdgeSettings (showEdges, edgeColor, edgeThreshold)
-
Parameters
+
+
new EdgeSettings (showEdges, edgeColor, edgeThreshold)
+
Parameters
showEdges boolean @@ -72,7 +72,7 @@
edgeColor -RGBColor +RGBColor
Color of the edges.
@@ -86,13 +86,13 @@

Methods

-
-
Clone ()
-
Description
-
Creates a clone of the object.
-
Returns
-
-EdgeSettings +
+
Clone ()
+
Description
+
Creates a clone of the object.
+
Returns
+
diff --git a/docs/EmbeddedViewer.html b/docs/Class_EmbeddedViewer.html similarity index 51% rename from docs/EmbeddedViewer.html rename to docs/Class_EmbeddedViewer.html index ace647a..4364739 100644 --- a/docs/EmbeddedViewer.html +++ b/docs/Class_EmbeddedViewer.html @@ -25,34 +25,34 @@
@@ -60,9 +60,9 @@

EmbeddedViewer

This is the main object for embedding the viewer on a website.

Constructor

-
-
new EmbeddedViewer (parentElement, parameters)
-
Parameters
+
+
new EmbeddedViewer (parentElement, parameters)
+
Parameters
parentElement Element @@ -78,7 +78,7 @@
Parameters for embedding.
camera -Camera +Camera (optional)
@@ -86,7 +86,7 @@
cameraMode -CameraMode +CameraMode (optional)
@@ -94,7 +94,7 @@
backgroundColor -RGBAColor +RGBAColor (optional)
@@ -102,7 +102,7 @@
defaultColor -RGBColor +RGBColor (optional)
@@ -110,7 +110,7 @@
edgeSettings -EdgeSettings +EdgeSettings (optional)
@@ -118,7 +118,7 @@
environmentSettings -EnvironmentSettings +EnvironmentSettings (optional)
@@ -135,11 +135,11 @@

Methods

-
-
LoadModelFromUrlList (modelUrls)
-
Description
-
Loads the model based on a list of urls. The list must contain the main model file and all of the referenced files. For example in case of an obj file the list must contain the corresponding mtl and texture files, too.
-
Parameters
+
+
LoadModelFromUrlList (modelUrls)
+
Description
+
Loads the model based on a list of urls. The list must contain the main model file and all of the referenced files. For example in case of an obj file the list must contain the corresponding mtl and texture files, too.
+
Parameters
modelUrls string[] @@ -148,11 +148,11 @@
Url list of model files.
-
-
LoadModelFromFileList (fileList)
-
Description
-
Loads the model based on a list of File objects. The list must contain the main model file and all of the referenced files. You must use this method when you are using a file picker or drag and drop to select files from a computer.
-
Parameters
+
+
LoadModelFromFileList (fileList)
+
Description
+
Loads the model based on a list of File objects. The list must contain the main model file and all of the referenced files. You must use this method when you are using a file picker or drag and drop to select files from a computer.
+
Parameters
fileList File[] @@ -161,46 +161,46 @@
File object list of model files.
-
-
LoadModelFromInputFiles (inputFiles)
-
Description
-
Loads the model based on a list of InputFile objects. This method is used internally, you should use LoadModelFromUrlList or LoadModelFromFileList instead.
-
Parameters
+
+
LoadModelFromInputFiles (inputFiles)
+
Description
+
Loads the model based on a list of InputFile objects. This method is used internally, you should use LoadModelFromUrlList or LoadModelFromFileList instead.
+
Parameters
inputFiles -InputFile[] +InputFile[]
List of model files.
-
-
GetViewer ()
-
Description
-
Returns the underlying Viewer object.
-
Returns
-
+
+
GetViewer ()
+
Description
+
Returns the underlying Viewer object.
+
Returns
+
Viewer
-
-
GetModel ()
-
Description
-
Returns the underlying Model object.
-
Returns
-
+
+
GetModel ()
+
Description
+
Returns the underlying Model object.
+
Returns
+
Model
-
-
Resize ()
-
Description
-
This method must be called when the size of the parent element changes to make sure that the context has the same dimensions as the parent element.
+
+
Resize ()
+
Description
+
This method must be called when the size of the parent element changes to make sure that the context has the same dimensions as the parent element.
-
-
Destroy ()
-
Description
-
Frees up all the memory that is allocated by the viewer. You should call this function if yo don't need the viewer anymore.
+
+
Destroy ()
+
Description
+
Frees up all the memory that is allocated by the viewer. You should call this function if yo don't need the viewer anymore.
diff --git a/docs/EnvironmentSettings.html b/docs/Class_EnvironmentSettings.html similarity index 54% rename from docs/EnvironmentSettings.html rename to docs/Class_EnvironmentSettings.html index 6b7ecf1..36f84c4 100644 --- a/docs/EnvironmentSettings.html +++ b/docs/Class_EnvironmentSettings.html @@ -25,34 +25,34 @@
@@ -60,9 +60,9 @@

EnvironmentSettings

Environment settings object.

Constructor

-
-
new EnvironmentSettings (textureNames, backgroundIsEnvMap)
-
Parameters
+
+
new EnvironmentSettings (textureNames, backgroundIsEnvMap)
+
Parameters
textureNames string[] @@ -79,13 +79,13 @@

Methods

-
-
Clone ()
-
Description
-
Creates a clone of the object.
-
Returns
-
-EnvironmentSettings +
+
Clone ()
+
Description
+
Creates a clone of the object.
+
Returns
+
diff --git a/docs/InputFile.html b/docs/Class_InputFile.html similarity index 60% rename from docs/InputFile.html rename to docs/Class_InputFile.html index 5cc74e2..e0b7241 100644 --- a/docs/InputFile.html +++ b/docs/Class_InputFile.html @@ -25,34 +25,34 @@
@@ -60,9 +60,9 @@

InputFile

File representation class for importers.

Constructor

-
-
new InputFile (name, source, data)
-
Parameters
+
+
new InputFile (name, source, data)
+
Parameters
name string @@ -72,7 +72,7 @@
Source of the file.
diff --git a/docs/RGBAColor.html b/docs/Class_RGBAColor.html similarity index 61% rename from docs/RGBAColor.html rename to docs/Class_RGBAColor.html index f172cf7..0ca4835 100644 --- a/docs/RGBAColor.html +++ b/docs/Class_RGBAColor.html @@ -25,34 +25,34 @@
@@ -60,9 +60,9 @@

RGBAColor

RGBA color object. Components are integers in the range of 0..255.

Constructor

-
-
new RGBAColor (r, g, b, a)
-
Parameters
+
+
new RGBAColor (r, g, b, a)
+
Parameters
r integer @@ -93,11 +93,11 @@

Methods

-
-
Set (r, g, b, a)
-
Description
-
Sets the value of all components.
-
Parameters
+
+
Set (r, g, b, a)
+
Description
+
Sets the value of all components.
+
Parameters
r integer @@ -127,13 +127,13 @@
Alpha component.
-
-
Clone ()
-
Description
-
Creates a clone of the object.
-
Returns
-
-RGBAColor +
+
Clone ()
+
Description
+
Creates a clone of the object.
+
Returns
+
diff --git a/docs/RGBColor.html b/docs/Class_RGBColor.html similarity index 58% rename from docs/RGBColor.html rename to docs/Class_RGBColor.html index 1e3fbf8..10abb96 100644 --- a/docs/RGBColor.html +++ b/docs/Class_RGBColor.html @@ -25,34 +25,34 @@
@@ -60,9 +60,9 @@

RGBColor

RGB color object. Components are integers in the range of 0..255.

Constructor

-
-
new RGBColor (r, g, b)
-
Parameters
+
+
new RGBColor (r, g, b)
+
Parameters
r integer @@ -86,11 +86,11 @@

Methods

-
-
Set (r, g, b)
-
Description
-
Sets the value of all components.
-
Parameters
+
+
Set (r, g, b)
+
Description
+
Sets the value of all components.
+
Parameters
r integer @@ -113,13 +113,13 @@
Blue component.
-
-
Clone ()
-
Description
-
Creates a clone of the object.
-
Returns
-
-RGBColor +
+
Clone ()
+
Description
+
Creates a clone of the object.
+
Returns
+
diff --git a/docs/CameraMode.html b/docs/Enum_CameraMode.html similarity index 59% rename from docs/CameraMode.html rename to docs/Enum_CameraMode.html index 21dc832..dcdf375 100644 --- a/docs/CameraMode.html +++ b/docs/Enum_CameraMode.html @@ -25,34 +25,34 @@
diff --git a/docs/FileSource.html b/docs/Enum_FileSource.html similarity index 62% rename from docs/FileSource.html rename to docs/Enum_FileSource.html index 2183f03..34f2fab 100644 --- a/docs/FileSource.html +++ b/docs/Enum_FileSource.html @@ -25,34 +25,34 @@
diff --git a/docs/Init3DViewerElement.html b/docs/Function_Init3DViewerElement.html similarity index 54% rename from docs/Init3DViewerElement.html rename to docs/Function_Init3DViewerElement.html index 2574c14..48ad5a0 100644 --- a/docs/Init3DViewerElement.html +++ b/docs/Function_Init3DViewerElement.html @@ -25,44 +25,44 @@

Init3DViewerElement

-
-
Init3DViewerElement (parentElement, modelUrls, parameters)
-
Description
-
Loads the model specified by urls.
-
Parameters
+
+
Init3DViewerElement (parentElement, modelUrls, parameters)
+
Description
+
Loads the model specified by urls.
+
Parameters
parentElement Element @@ -82,11 +82,11 @@ object
-
See EmbeddedViewer constructor for details.
+
See EmbeddedViewer constructor for details.
-
Returns
- diff --git a/docs/Init3DViewerElements.html b/docs/Function_Init3DViewerElements.html similarity index 51% rename from docs/Init3DViewerElements.html rename to docs/Function_Init3DViewerElements.html index 923afa4..86ecd82 100644 --- a/docs/Init3DViewerElements.html +++ b/docs/Function_Init3DViewerElements.html @@ -25,50 +25,50 @@

Init3DViewerElements

-
-
Init3DViewerElements (onReady)
-
Description
-
Loads all the models on the page. This function looks for all the elements with online_3d_viewer class name, and loads the model according to the tag's parameters.
-
Parameters
+
+
Init3DViewerElements (onReady)
+
Description
+
Loads all the models on the page. This function looks for all the elements with online_3d_viewer class name, and loads the model according to the tag's parameters.
+
Parameters
onReady function
-
Callback that called when all models are loaded. It has one parameter that is an array of the created EmbeddedViewer objects.
+
Callback that called when all models are loaded. It has one parameter that is an array of the created EmbeddedViewer objects.
diff --git a/docs/SetExternalLibLocation.html b/docs/Function_SetExternalLibLocation.html similarity index 52% rename from docs/SetExternalLibLocation.html rename to docs/Function_SetExternalLibLocation.html index 4e16613..c5a16e4 100644 --- a/docs/SetExternalLibLocation.html +++ b/docs/Function_SetExternalLibLocation.html @@ -25,44 +25,44 @@

SetExternalLibLocation

-
-
SetExternalLibLocation (newExternalLibLocation)
-
Description
-
Sets the location of the external libraries used by the engine. This is the content of the libs folder in the package. The location must be relative to the main file.
-
Parameters
+
+
SetExternalLibLocation (newExternalLibLocation)
+
Description
+
Sets the location of the external libraries used by the engine. This is the content of the libs folder in the package. The location must be relative to the main file.
+
Parameters
newExternalLibLocation string diff --git a/docs/ContributionGuidelinesPage.html b/docs/Page_ContributionGuidelines.html similarity index 66% rename from docs/ContributionGuidelinesPage.html rename to docs/Page_ContributionGuidelines.html index 03c4142..748ce0f 100644 --- a/docs/ContributionGuidelinesPage.html +++ b/docs/Page_ContributionGuidelines.html @@ -25,34 +25,34 @@
diff --git a/docs/EnvironmentSetupPage.html b/docs/Page_EnvironmentSetup.html similarity index 77% rename from docs/EnvironmentSetupPage.html rename to docs/Page_EnvironmentSetup.html index 84099d2..c5ff100 100644 --- a/docs/EnvironmentSetupPage.html +++ b/docs/Page_EnvironmentSetup.html @@ -25,34 +25,34 @@
diff --git a/docs/InstallationPage.html b/docs/Page_Installation.html similarity index 66% rename from docs/InstallationPage.html rename to docs/Page_Installation.html index b00ea28..8048daa 100644 --- a/docs/InstallationPage.html +++ b/docs/Page_Installation.html @@ -25,34 +25,34 @@
diff --git a/docs/UsagePage.html b/docs/Page_Usage.html similarity index 78% rename from docs/UsagePage.html rename to docs/Page_Usage.html index 016167a..fd0d6bd 100644 --- a/docs/UsagePage.html +++ b/docs/Page_Usage.html @@ -25,34 +25,34 @@
diff --git a/docs/index.html b/docs/index.html index d6ace38..ef00c3f 100644 --- a/docs/index.html +++ b/docs/index.html @@ -25,34 +25,34 @@
@@ -72,8 +72,8 @@

These documents help you understanding how to use the engine in your own solution.

    -
  • Installation - How to get the package?
  • -
  • Usage - How to use it to embed 3D models?
  • +
  • Installation - How to get the package?
  • +
  • Usage - How to use it to embed 3D models?

Contribution

@@ -81,7 +81,8 @@

If you would like to contribute to the codebase, these documents help you to start.

diff --git a/docs/source/ContributionGuidelinesPage.html b/docs/source/ContributionGuidelines.html similarity index 100% rename from docs/source/ContributionGuidelinesPage.html rename to docs/source/ContributionGuidelines.html diff --git a/docs/source/EnvironmentSetupPage.html b/docs/source/EnvironmentSetup.html similarity index 100% rename from docs/source/EnvironmentSetupPage.html rename to docs/source/EnvironmentSetup.html diff --git a/docs/source/InstallationPage.html b/docs/source/Installation.html similarity index 100% rename from docs/source/InstallationPage.html rename to docs/source/Installation.html diff --git a/docs/source/UsagePage.html b/docs/source/Usage.html similarity index 100% rename from docs/source/UsagePage.html rename to docs/source/Usage.html diff --git a/docs/source/config.json b/docs/source/config.json index 72fa957..0d48a82 100644 --- a/docs/source/config.json +++ b/docs/source/config.json @@ -18,11 +18,11 @@ "pages" : [ { "name" : "Installation", - "url" : "InstallationPage.html" + "url" : "Installation.html" }, { "name" : "Usage", - "url" : "UsagePage.html" + "url" : "Usage.html" } ] }, @@ -31,11 +31,11 @@ "pages" : [ { "name" : "Contribution Guidelines", - "url" : "ContributionGuidelinesPage.html" + "url" : "ContributionGuidelines.html" }, { "name" : "Environment Setup", - "url" : "EnvironmentSetupPage.html" + "url" : "EnvironmentSetup.html" } ] } diff --git a/docs/source/index.html b/docs/source/index.html index 3c2b974..97ab839 100644 --- a/docs/source/index.html +++ b/docs/source/index.html @@ -12,8 +12,8 @@

These documents help you understanding how to use the engine in your own solution.

    -
  • Installation - How to get the package?
  • -
  • Usage - How to use it to embed 3D models?
  • +
  • Installation - How to get the package?
  • +
  • Usage - How to use it to embed 3D models?

Contribution

@@ -21,5 +21,6 @@

If you would like to contribute to the codebase, these documents help you to start.

diff --git a/docs/static/style.css b/docs/static/style.css index cb140da..b37b77f 100644 --- a/docs/static/style.css +++ b/docs/static/style.css @@ -158,12 +158,12 @@ li overflow: auto; } -.method_container +.function_container { margin-bottom: 50px; } -.method_signature +.function_signature { background: #eeeeee; font-size: 18px; @@ -173,12 +173,12 @@ li border-left: 4px solid #bbbbbb; } -.method_description +.function_description { margin: 10px 0px; } -.method_title +.function_title { font-size: 16px; font-weight: bold; diff --git a/tools/generate_docs.py b/tools/generate_docs.py index 801c375..6ee06ee 100644 --- a/tools/generate_docs.py +++ b/tools/generate_docs.py @@ -8,252 +8,8 @@ import platform import html import re -from lib import utils as Utils - -class HtmlGenerator: - def __init__ (self, eol): - self.html = '' - self.eol = eol - - def AddText (self, content): - self.html += content - - def AddLine (self, content): - self.AddText (content + self.eol) - - def AddTag (self, tagName, content): - self.AddLine ('<{0}>{1}'.format (tagName, content)) - - def AddTagWithClass (self, tagName, className, content): - self.AddLine ('<{0} class="{1}">{2}'.format (tagName, className, content)) - - def AddTagWithAttributes (self, tagName, attributes, content): - line = '<{0}'.format (tagName); - if len (attributes) > 0: - attributeStrings = map (lambda x : '{0}="{1}"'.format (x[0], x[1]), attributes) - line += ' ' + ' '.join (attributeStrings) - line += '>{1}'.format (tagName, content) - self.AddLine (line) - - def BeginTag (self, tagName): - self.AddLine ('<{0}>'.format (tagName)) - - def BeginTagWithClass (self, tagName, className): - self.AddLine ('<{0} class="{1}">'.format (tagName, className)) - - def EndTag (self, tagName): - self.AddLine (''.format (tagName)) - - def GetHtml (self): - return self.html - -def CleanUpText (text): - if text == None: - return '' - invalidChars = ['\r', '\n', '\t'] - for invalidChar in invalidChars: - text = text.replace (invalidChar, ' ') - text = html.escape (text) - return text - -def GenerateLink (entityName, entityLink): - target = '_blank' if entityLink.startswith ('http') else '_self' - return '{0}'.format (entityName, entityLink, target) - -def FinalizeType (text, entityLinks): - text = CleanUpText (text) - arrayMatch = re.match ('Array\.<(.+)>', text) - if arrayMatch != None: - matchedName = arrayMatch.group (1) - if matchedName in entityLinks: - return GenerateLink (matchedName, entityLinks[matchedName]) + '[]' - else: - return arrayMatch.group (1) + '[]' - if text in entityLinks: - return GenerateLink (text, entityLinks[text]) - return text - -def FinalizeDescription (text, entityLinks): - text = CleanUpText (text) - links = re.findall ('{@link (.+)}', text) - for link in links: - if link in entityLinks: - text = text.replace ('{@link ' + link + '}', GenerateLink (link, entityLinks[link])) - else: - text = text.replace ('{@link ' + link + '}', link) - return text - -class NavigationGroup: - def __init__ (self, name, sort): - self.name = name - self.sort = sort - self.links = [] - - def AddLink (self, name, url): - self.links.append ({ - 'name' : name, - 'url' : url - }) - -class Navigation: - def __init__ (self): - self.groups = [] - self.entityLinks = {} - - def AddGroup (self, group): - self.groups.append (group) - - def AddEntityLink (self, name, url): - self.entityLinks[name] = url - - def GenerateHtml (self, eol): - generator = HtmlGenerator (eol) - for group in self.groups: - if len (group.links) == 0: - continue - generator.BeginTagWithClass ('div', 'navigation_section') - generator.AddTagWithClass ('div', 'navigation_title', group.name) - finalLinks = group.links - if group.sort: - finalLinks = sorted (group.links, key = lambda x : x['name']) - for link in finalLinks: - linkHtml = GenerateLink (link['name'], link['url']) - generator.AddTagWithAttributes ('div', [('id', 'nav-' + link['name']), ('class', 'navigation_item')], linkHtml) - generator.EndTag ('div') - return generator.GetHtml () - -class EnumMemberDoc: - def __init__ (self, name, description): - self.name = name - self.description = description - -class EnumDoc: - def __init__ (self, name, description): - self.name = name - self.description = description - self.members = [] - - def AddMember (self, member): - self.members.append (member) - - def GenerateHtml (self, navigation, eol): - generator = HtmlGenerator (eol) - generator.AddTag ('h1', self.name) - generator.AddTagWithClass ('div', 'description', FinalizeDescription (self.description, navigation.entityLinks)) - if len (self.members) > 0: - generator.AddTag ('h2', 'Values') - for member in self.members: - generator.BeginTagWithClass ('div', 'parameter_header') - generator.AddTagWithClass ('span', 'parameter_name', member.name) - generator.EndTag ('div') - generator.BeginTagWithClass ('div', 'parameter_main') - generator.AddTagWithClass ('div', 'parameter_description', FinalizeDescription (member.description, navigation.entityLinks)) - generator.EndTag ('div') - - return generator.GetHtml () - -class ParameterDoc: - def __init__ (self, name, types, isOptional, description): - self.name = name - self.types = types - self.isOptional = isOptional - self.description = description - self.subParameters = [] - - def AddSubParameter (self, parameter): - self.subParameters.append (parameter) - -class ReturnsDoc: - def __init__ (self, types, description): - self.types = types - self.description = description - -class MethodDoc: - def __init__ (self, name, description, parameters, returns): - self.name = name - self.description = description - self.parameters = parameters - self.returns = returns - - def AddParameter (self, parameter): - self.parameters.append (parameter) - - def GenerateHtml (self, navigation, eol): - generator = HtmlGenerator (eol) - generator.AddTag ('h1', self.name) - GenerateMethodHtml (self, generator, navigation, False) - return generator.GetHtml () - -class ClassDoc: - def __init__ (self, name, description): - self.name = name - self.description = description - self.constructor = None - self.methods = [] - - def SetConstructor (self, constructor): - self.constructor = constructor - - def AddMethod (self, method): - self.methods.append (method) - - def GenerateHtml (self, navigation, eol): - generator = HtmlGenerator (eol) - generator.AddTag ('h1', self.name) - generator.AddTagWithClass ('div', 'description', FinalizeDescription (self.description, navigation.entityLinks)) - if self.constructor != None: - generator.AddTag ('h2', 'Constructor') - GenerateMethodHtml (self.constructor, generator, navigation, True) - if len (self.methods) > 0: - generator.AddTag ('h2', 'Methods') - for method in self.methods: - GenerateMethodHtml (method, generator, navigation, False) - return generator.GetHtml () - -def GenerateParameterTypesHtml (paramTypes, generator, navigation): - for i in range (0, len (paramTypes)): - paramType = paramTypes[i] - paramTypeHtml = FinalizeType (paramType, navigation.entityLinks) - generator.AddTagWithClass ('span', 'type parameter_type', paramTypeHtml) - if (i < len (paramTypes) - 1): - generator.AddTagWithClass ('span', 'parameter_type_separator', '|') - -def GenerateParameterListHtml (parameters, generator, navigation): - for param in parameters: - generator.BeginTagWithClass ('div', 'parameter_header') - generator.AddTagWithClass ('span', 'parameter_name', param.name) - GenerateParameterTypesHtml (param.types, generator, navigation) - if param.isOptional: - generator.AddTagWithClass ('span', 'parameter_attributes', '(optional)') - generator.EndTag ('div') - generator.BeginTagWithClass ('div', 'parameter_main') - generator.AddTagWithClass ('div', 'parameter_description', FinalizeDescription (param.description, navigation.entityLinks)) - if len (param.subParameters) > 0: - GenerateParameterListHtml (param.subParameters, generator, navigation) - generator.EndTag ('div') - -def GenerateMethodHtml (method, generator, navigation, isConstructor): - paramNames = map (lambda x : x.name, method.parameters) - methodSignature = method.name + ' (' + ', '.join (paramNames) + ')' - if isConstructor: - methodSignature = 'new ' + methodSignature - generator.BeginTagWithClass ('div', 'method_container') - generator.AddTagWithAttributes ('div', [('id', method.name), ('class', 'method_signature')], methodSignature) - if method.description != None: - generator.AddTagWithClass ('div', 'method_title', 'Description') - generator.AddTagWithClass ('div', 'method_description', FinalizeDescription (method.description, navigation.entityLinks)) - if method.parameters != None and len (method.parameters) > 0: - generator.AddTagWithClass ('div', 'method_title', 'Parameters') - GenerateParameterListHtml (method.parameters, generator, navigation) - if method.returns != None: - generator.AddTagWithClass ('div', 'method_title', 'Returns') - generator.BeginTagWithClass ('div', 'method_returns') - if method.returns.types != None: - GenerateParameterTypesHtml (method.returns.types, generator, navigation) - if method.returns.description != None: - generator.AddTagWithClass ('span', 'return_description', FinalizeDescription (method.returns.description, navigation.entityLinks)) - generator.EndTag ('div') - generator.EndTag ('div') +from lib.doc_entities import PageType, PageGroup, PageDoc, EnumMemberDoc, EnumDoc, ParameterDoc, ReturnsDoc, FunctionDoc, ClassDoc +from lib.doc_generator import Documentation, GenerateDocumentation def GetDictValue (dict, key): if not key in dict: @@ -317,12 +73,16 @@ def GetReturnsFromDoclet (doclet): GetDictValue (returns, 'description') ) -def BuildHierarchy (doclets): - hierarchy = { - 'classes' : [], - 'functions' : [], - 'enums' : [] - } +def AddPageGroupsToDocumentation (documentation, pageGroups, sourcesFolder): + for pageGroup in pageGroups: + pageGroupDoc = PageGroup (pageGroup['name']) + for page in pageGroup['pages']: + pageType = PageType.External if page['url'].startswith ('http') else PageType.Internal + pageDoc = PageDoc (page['name'], page['url'], sourcesFolder, pageType) + pageGroupDoc.AddPage (pageDoc) + documentation.AddPageGroup (pageGroupDoc) + +def AddEntitiesToDocumentation (documentation, doclets): classNameToDoc = {} enumNameToDoc = {} for doclet in doclets: @@ -333,24 +93,24 @@ def BuildHierarchy (doclets): description = GetDictValue (doclet, 'description') if kind == 'class': classDoc = ClassDoc (name, doclet['classdesc']) - constructorDoc = MethodDoc (name, description, parameters, returns) + constructorDoc = FunctionDoc (name, description, parameters, returns) classDoc.SetConstructor (constructorDoc) - hierarchy['classes'].append (classDoc) + documentation.AddClass (classDoc) classNameToDoc[name] = classDoc elif kind == 'function': if 'memberof' in doclet: parentName = doclet['memberof'] if parentName in classNameToDoc: classDoc = classNameToDoc[parentName] - methodDoc = MethodDoc (name, description, parameters, returns) - classDoc.AddMethod (methodDoc) + functionDoc = FunctionDoc (name, description, parameters, returns) + classDoc.AddFunction (functionDoc) else: - methodDoc = MethodDoc (name, description, parameters, returns) - hierarchy['functions'].append (methodDoc) + functionDoc = FunctionDoc (name, description, parameters, returns) + documentation.AddFunction (functionDoc) elif kind == 'constant': if 'isEnum' in doclet and doclet['isEnum'] == True: enumDoc = EnumDoc (name, description) - hierarchy['enums'].append (enumDoc) + documentation.AddEnum (enumDoc) enumNameToDoc[name] = enumDoc elif kind == 'member': parentName = doclet['memberof'] @@ -358,72 +118,6 @@ def BuildHierarchy (doclets): enumDoc = enumNameToDoc[parentName] memberDoc = EnumMemberDoc (name, description) enumDoc.AddMember (memberDoc) - return hierarchy - -def CreateFromTemplate (templateHtmlPath, resultHtmlPath, navigation, title, content, eol): - shutil.copy (templateHtmlPath, resultHtmlPath) - Utils.ReplaceStringsInFile (resultHtmlPath, [ - ('$$$TITLE$$$', title), - ('$$$NAVIGATION$$$', navigation.GenerateHtml (eol)), - ('$$$MAIN$$$', content) - ]) - -def BuildNavigation (pageGroups, hierarchy): - navigation = Navigation () - - for pageGroup in pageGroups: - navGroup = NavigationGroup (pageGroup['name'], False) - for page in pageGroup['pages']: - navGroup.AddLink (page['name'], page['url']) - navigation.AddGroup (navGroup) - - classesGroup = NavigationGroup ('Classes', True) - for classDoc in hierarchy['classes']: - navigation.AddEntityLink (classDoc.name, classDoc.name + '.html') - classesGroup.AddLink (classDoc.name, classDoc.name + '.html') - navigation.AddGroup (classesGroup) - - functionsGroup = NavigationGroup ('Functions', True) - for methodDoc in hierarchy['functions']: - navigation.AddEntityLink (methodDoc.name, methodDoc.name + '.html') - functionsGroup.AddLink (methodDoc.name, methodDoc.name + '.html') - navigation.AddGroup (functionsGroup) - - enumsGroup = NavigationGroup ('Enums', True) - for enumDoc in hierarchy['enums']: - navigation.AddEntityLink (enumDoc.name, enumDoc.name + '.html') - enumsGroup.AddLink (enumDoc.name, enumDoc.name + '.html') - navigation.AddGroup (enumsGroup) - - return navigation - -def BuildDocumentationFiles (navigation, pageGroups, hierarchy, sourceDir, resultDir): - templateHtmlPath = os.path.join (sourceDir, 'Template.html') - eol = Utils.GetEOLCharFromFile (templateHtmlPath) - - for pageGroup in pageGroups: - for page in pageGroup['pages']: - if page['url'].startswith ('http'): - continue - sourceHtmlPath = os.path.join (sourceDir, page['url']) - pageHtmlPath = os.path.join (resultDir, page['url']) - pageContent = '
' + eol + Utils.GetFileContent (sourceHtmlPath) + eol + '
' - CreateFromTemplate (templateHtmlPath, pageHtmlPath, navigation, page['name'], pageContent, eol) - - for classDoc in hierarchy['classes']: - classHtmlPath = os.path.join (resultDir, classDoc.name + '.html') - docContent = classDoc.GenerateHtml (navigation, eol) - CreateFromTemplate (templateHtmlPath, classHtmlPath, navigation, classDoc.name, docContent, eol) - - for methodDoc in hierarchy['functions']: - methodHtmlPath = os.path.join (resultDir, methodDoc.name + '.html') - docContent = methodDoc.GenerateHtml (navigation, eol) - CreateFromTemplate (templateHtmlPath, methodHtmlPath, navigation, methodDoc.name, docContent, eol) - - for enumDoc in hierarchy['enums']: - enumHtmlPath = os.path.join (resultDir, enumDoc.name + '.html') - docContent = enumDoc.GenerateHtml (navigation, eol) - CreateFromTemplate (templateHtmlPath, enumHtmlPath, navigation, enumDoc.name, docContent, eol) def Main (argv): toolsDir = os.path.dirname (os.path.abspath (__file__)) @@ -448,16 +142,17 @@ def Main (argv): with open (os.path.join (sourceDir, 'config.json')) as configJson: config = json.load (configJson) - doclets = GetDocumentedDoclets (resultJson) + documentation = Documentation () + pageGroups = config['page_groups'] - hierarchy = BuildHierarchy (doclets) + AddPageGroupsToDocumentation (documentation, pageGroups, sourceDir) - navigation = BuildNavigation (pageGroups, hierarchy) + doclets = GetDocumentedDoclets (resultJson) + AddEntitiesToDocumentation (documentation, doclets) for name in config['external_refs']: - navigation.AddEntityLink (name, config['external_refs'][name]) - - BuildDocumentationFiles (navigation, pageGroups, hierarchy, sourceDir, resultDir) + documentation.AddEntityLink (name, config['external_refs'][name]) + GenerateDocumentation (documentation, sourceDir, resultDir) return 0 sys.exit (Main (sys.argv)) diff --git a/tools/lib/doc_entities.py b/tools/lib/doc_entities.py new file mode 100644 index 0000000..44a87cd --- /dev/null +++ b/tools/lib/doc_entities.py @@ -0,0 +1,157 @@ +import os +from enum import Enum + +from . import utils as Utils +from .html_generator import HtmlGenerator +from .doc_utils import FinalizeDescription, FunctionType, GenerateFunctionHtml + +class DocEntity: + def GetName (self): + raise Exception ('Not implemented.') + + def GetLocation (self): + raise Exception ('Not implemented.') + + def GetHtml (self, entityLinks, eol): + raise Exception ('Not implemented.') + +class PageGroup: + def __init__ (self, name): + self.name = name + self.pages = [] + + def AddPage (self, page): + self.pages.append (page) + +class PageType (Enum): + Internal = 1 + External = 2 + +class PageDoc (DocEntity): + def __init__ (self, name, link, folder, type): + self.name = name + self.link = link + self.folder = folder + self.type = type + + def GetName (self): + return self.name + + def GetLocation (self): + if self.type == PageType.Internal: + prefix = 'Page_' if self.link != 'index.html' else '' + return prefix + self.link + else: + return self.link + + def GetHtml (self, entityLinks, eol): + if self.type == PageType.Internal: + pageContent = Utils.GetFileContent (os.path.join (self.folder, self.link)) + return '
' + eol + pageContent + eol + '
' + else: + raise Exception ('GetHtml called for external link.') + +class EnumMemberDoc: + def __init__ (self, name, description): + self.name = name + self.description = description + +class EnumDoc (DocEntity): + def __init__ (self, name, description): + self.name = name + self.description = description + self.members = [] + + def AddMember (self, member): + self.members.append (member) + + def GetName (self): + return self.name + + def GetLocation (self): + return 'Enum_' + self.name + '.html' + + def GetHtml (self, entityLinks, eol): + generator = HtmlGenerator (eol) + generator.AddTag ('h1', self.name) + generator.AddTagWithClass ('div', 'description', FinalizeDescription (self.description, entityLinks)) + if len (self.members) > 0: + generator.AddTag ('h2', 'Values') + for member in self.members: + generator.BeginTagWithClass ('div', 'parameter_header') + generator.AddTagWithClass ('span', 'parameter_name', member.name) + generator.EndTag ('div') + generator.BeginTagWithClass ('div', 'parameter_main') + generator.AddTagWithClass ('div', 'parameter_description', FinalizeDescription (member.description, entityLinks)) + generator.EndTag ('div') + return generator.GetHtml () + +class ParameterDoc: + def __init__ (self, name, types, isOptional, description): + self.name = name + self.types = types + self.isOptional = isOptional + self.description = description + self.subParameters = [] + + def AddSubParameter (self, parameter): + self.subParameters.append (parameter) + +class ReturnsDoc: + def __init__ (self, types, description): + self.types = types + self.description = description + +class FunctionDoc (DocEntity): + def __init__ (self, name, description, parameters, returns): + self.name = name + self.description = description + self.parameters = parameters + self.returns = returns + + def AddParameter (self, parameter): + self.parameters.append (parameter) + + def GetName (self): + return self.name + + def GetLocation (self): + return 'Function_' + self.name + '.html' + + def GetHtml (self, navigation, eol): + generator = HtmlGenerator (eol) + generator.AddTag ('h1', self.name) + GenerateFunctionHtml (self, generator, navigation, FunctionType.Standalone) + return generator.GetHtml () + +class ClassDoc (DocEntity): + def __init__ (self, name, description): + self.name = name + self.description = description + self.constructor = None + self.functions = [] + + def SetConstructor (self, constructor): + self.constructor = constructor + + def AddFunction (self, function): + self.functions.append (function) + + def GetName (self): + return self.name + + def GetLocation (self): + return 'Class_' + self.name + '.html' + + def GetHtml (self, entityLinks, eol): + generator = HtmlGenerator (eol) + generator.AddTag ('h1', self.name) + generator.AddTagWithClass ('div', 'description', FinalizeDescription (self.description, entityLinks)) + if self.constructor != None: + generator.AddTag ('h2', 'Constructor') + GenerateFunctionHtml (self.constructor, generator, entityLinks, FunctionType.Constructor) + if len (self.functions) > 0: + generator.AddTag ('h2', 'Methods') + for function in self.functions: + GenerateFunctionHtml (function, generator, entityLinks, FunctionType.Standalone.ClassMethod) + return generator.GetHtml () diff --git a/tools/lib/doc_generator.py b/tools/lib/doc_generator.py new file mode 100644 index 0000000..fde3e7c --- /dev/null +++ b/tools/lib/doc_generator.py @@ -0,0 +1,86 @@ +import os +import shutil + +from . import utils as Utils +from .html_generator import HtmlGenerator +from .doc_entities import PageType + +class Documentation: + def __init__ (self): + self.pageGroups = [] + self.classes = [] + self.functions = [] + self.enums = [] + self.entityLinks = {} + + def AddPageGroup (self, pageGroup): + for page in pageGroup.pages: + self.AddEntityLink (page.name, page.GetLocation ()) + self.pageGroups.append (pageGroup) + + def AddClass (self, classDoc): + self.AddEntityLink (classDoc.GetName (), classDoc.GetLocation ()) + self.classes.append (classDoc) + + def AddFunction (self, functionDoc): + self.AddEntityLink (functionDoc.GetName (), functionDoc.GetLocation ()) + self.functions.append (functionDoc) + + def AddEnum (self, enumDoc): + self.AddEntityLink (enumDoc.GetName (), enumDoc.GetLocation ()) + self.enums.append (enumDoc) + + def AddEntityLink (self, name, url): + assert (not name in self.entityLinks) + self.entityLinks[name] = url + +def GenerateDocumentationPage (documentation, templatePath, resultDirPath, navigationHtml, entity, eol): + resultPath = os.path.join (resultDirPath, entity.GetLocation ()) + shutil.copy (templatePath, resultPath) + Utils.ReplaceStringsInFile (resultPath, [ + ('$$$TITLE$$$', entity.GetName ()), + ('$$$NAVIGATION$$$', navigationHtml), + ('$$$MAIN$$$', entity.GetHtml (documentation.entityLinks, eol)) + ]) + +def GenerateLinkHtml (entityName, entityLink): + target = '_blank' if entityLink.startswith ('http') else '_self' + return '{0}'.format (entityName, entityLink, target) + +def AddNavigationSection (generator, name, entities): + generator.BeginTagWithClass ('div', 'navigation_section') + generator.AddTagWithClass ('div', 'navigation_title', name) + for entity in entities: + linkHtml = GenerateLinkHtml (entity.GetName (), entity.GetLocation ()) + generator.AddTagWithAttributes ('div', [('id', 'nav-' + entity.GetName ()), ('class', 'navigation_item')], linkHtml) + generator.EndTag ('div') + +def GenerateNavigationHtml (documentation, eol): + generator = HtmlGenerator (eol) + for pageGroup in documentation.pageGroups: + AddNavigationSection (generator, pageGroup.name, pageGroup.pages) + AddNavigationSection (generator, 'Classes', documentation.classes) + AddNavigationSection (generator, 'Functions', documentation.functions) + AddNavigationSection (generator, 'Enums', documentation.enums) + return generator.GetHtml () + +def GenerateDocumentation (documentation, sourceFolder, targetFolder): + templateHtmlPath = os.path.join (sourceFolder, 'Template.html') + eol = Utils.GetEOLCharFromFile (templateHtmlPath) + + navigationHtml = GenerateNavigationHtml (documentation, eol) + + for pageGroup in documentation.pageGroups: + for page in pageGroup.pages: + if page.type == PageType.External: + continue + GenerateDocumentationPage (documentation, templateHtmlPath, targetFolder, navigationHtml, page, eol) + + allEntities = [ + documentation.classes, + documentation.functions, + documentation.enums + ] + for entityList in allEntities: + for entity in entityList: + GenerateDocumentationPage (documentation, templateHtmlPath, targetFolder, navigationHtml, entity, eol) diff --git a/tools/lib/doc_utils.py b/tools/lib/doc_utils.py new file mode 100644 index 0000000..4b48eb4 --- /dev/null +++ b/tools/lib/doc_utils.py @@ -0,0 +1,89 @@ +import re +import html +from enum import Enum + +def CleanUpText (text): + if text == None: + return '' + invalidChars = ['\r', '\n', '\t'] + for invalidChar in invalidChars: + text = text.replace (invalidChar, ' ') + text = html.escape (text) + return text + +def GenerateLink (entityName, entityLink): + target = '_blank' if entityLink.startswith ('http') else '_self' + return '{0}'.format (entityName, entityLink, target) + +def FinalizeType (text, entityLinks): + text = CleanUpText (text) + arrayMatch = re.match ('Array\.<(.+)>', text) + if arrayMatch != None: + matchedName = arrayMatch.group (1) + if matchedName in entityLinks: + return GenerateLink (matchedName, entityLinks[matchedName]) + '[]' + else: + return arrayMatch.group (1) + '[]' + if text in entityLinks: + return GenerateLink (text, entityLinks[text]) + return text + +def FinalizeDescription (text, entityLinks): + text = CleanUpText (text) + links = re.findall ('{@link (.+)}', text) + for link in links: + if link in entityLinks: + text = text.replace ('{@link ' + link + '}', GenerateLink (link, entityLinks[link])) + else: + text = text.replace ('{@link ' + link + '}', link) + return text + +def GenerateParameterTypesHtml (paramTypes, generator, entityLinks): + for i in range (0, len (paramTypes)): + paramType = paramTypes[i] + paramTypeHtml = FinalizeType (paramType, entityLinks) + generator.AddTagWithClass ('span', 'type parameter_type', paramTypeHtml) + if (i < len (paramTypes) - 1): + generator.AddTagWithClass ('span', 'parameter_type_separator', '|') + +def GenerateParameterListHtml (parameters, generator, entityLinks): + for param in parameters: + generator.BeginTagWithClass ('div', 'parameter_header') + generator.AddTagWithClass ('span', 'parameter_name', param.name) + GenerateParameterTypesHtml (param.types, generator, entityLinks) + if param.isOptional: + generator.AddTagWithClass ('span', 'parameter_attributes', '(optional)') + generator.EndTag ('div') + generator.BeginTagWithClass ('div', 'parameter_main') + generator.AddTagWithClass ('div', 'parameter_description', FinalizeDescription (param.description, entityLinks)) + if len (param.subParameters) > 0: + GenerateParameterListHtml (param.subParameters, generator, entityLinks) + generator.EndTag ('div') + +class FunctionType (Enum): + Constructor = 1 + ClassMethod = 2 + Standalone = 3 + +def GenerateFunctionHtml (function, generator, entityLinks, type): + paramNames = map (lambda x : x.name, function.parameters) + functionSignature = function.name + ' (' + ', '.join (paramNames) + ')' + if type == FunctionType.Constructor: + functionSignature = 'new ' + functionSignature + generator.BeginTagWithClass ('div', 'function_container') + generator.AddTagWithAttributes ('div', [('id', function.name), ('class', 'function_signature')], functionSignature) + if function.description != None: + generator.AddTagWithClass ('div', 'function_title', 'Description') + generator.AddTagWithClass ('div', 'function_description', FinalizeDescription (function.description, entityLinks)) + if function.parameters != None and len (function.parameters) > 0: + generator.AddTagWithClass ('div', 'function_title', 'Parameters') + GenerateParameterListHtml (function.parameters, generator, entityLinks) + if function.returns != None: + generator.AddTagWithClass ('div', 'function_title', 'Returns') + generator.BeginTagWithClass ('div', 'function_returns') + if function.returns.types != None: + GenerateParameterTypesHtml (function.returns.types, generator, entityLinks) + if function.returns.description != None: + generator.AddTagWithClass ('span', 'return_description', FinalizeDescription (function.returns.description, entityLinks)) + generator.EndTag ('div') + generator.EndTag ('div') diff --git a/tools/lib/html_generator.py b/tools/lib/html_generator.py new file mode 100644 index 0000000..1c67578 --- /dev/null +++ b/tools/lib/html_generator.py @@ -0,0 +1,36 @@ +class HtmlGenerator: + def __init__ (self, eol): + self.html = '' + self.eol = eol + + def AddText (self, content): + self.html += content + + def AddLine (self, content): + self.AddText (content + self.eol) + + def AddTag (self, tagName, content): + self.AddLine ('<{0}>{1}'.format (tagName, content)) + + def AddTagWithClass (self, tagName, className, content): + self.AddLine ('<{0} class="{1}">{2}'.format (tagName, className, content)) + + def AddTagWithAttributes (self, tagName, attributes, content): + line = '<{0}'.format (tagName); + if len (attributes) > 0: + attributeStrings = map (lambda x : '{0}="{1}"'.format (x[0], x[1]), attributes) + line += ' ' + ' '.join (attributeStrings) + line += '>{1}'.format (tagName, content) + self.AddLine (line) + + def BeginTag (self, tagName): + self.AddLine ('<{0}>'.format (tagName)) + + def BeginTagWithClass (self, tagName, className): + self.AddLine ('<{0} class="{1}">'.format (tagName, className)) + + def EndTag (self, tagName): + self.AddLine (''.format (tagName)) + + def GetHtml (self): + return self.html