diff --git a/data/web/common/base.js b/data/web/common/base.js deleted file mode 100644 index b362bc94fc..0000000000 --- a/data/web/common/base.js +++ /dev/null @@ -1,4 +0,0 @@ -function parseJson(elementId) { - var jsonElement = document.getElementById(elementId); - return JSON.parse(jsonElement.innerHTML); -} diff --git a/data/web/documentation/factory.hbs b/data/web/documentation/factory.hbs new file mode 100644 index 0000000000..6fec23432e --- /dev/null +++ b/data/web/documentation/factory.hbs @@ -0,0 +1,24 @@ +{{#each data}} +
+
+

+ + {{name}} + +

+ {{#each classes}} +
+
+ +
+
+ {{/each}} +
+
+{{/each}} diff --git a/data/web/common/handlebars-v4.0.5.js b/data/web/documentation/handlebars-v4.0.5.js similarity index 100% rename from data/web/common/handlebars-v4.0.5.js rename to data/web/documentation/handlebars-v4.0.5.js diff --git a/data/web/keybindings/keybinding.hbs b/data/web/documentation/keybinding.hbs similarity index 95% rename from data/web/keybindings/keybinding.hbs rename to data/web/documentation/keybinding.hbs index cca289cb31..e4b09f066d 100644 --- a/data/web/keybindings/keybinding.hbs +++ b/data/web/documentation/keybinding.hbs @@ -1,3 +1,4 @@ +{{#each data}}
@@ -11,3 +12,4 @@
+{{/each}} diff --git a/data/web/documentation/main.hbs b/data/web/documentation/main.hbs index e96f942df9..f84d4d782b 100644 --- a/data/web/documentation/main.hbs +++ b/data/web/documentation/main.hbs @@ -8,8 +8,10 @@ {{#each documentation}}
  • - {{name}} + {{name}}
  • + {{/each}} @@ -18,15 +20,8 @@

    OpenSpace Documentation

    Version: {{version.[0]}}.{{version.[1]}}.{{version.[2]}}

    - - {{#each documentation}} -
    -
    -

    {{name}}

    - {{> documentation}} -
    -
    - {{/each}} +
    +
    diff --git a/data/web/properties/property.hbs b/data/web/documentation/property.hbs similarity index 100% rename from data/web/properties/property.hbs rename to data/web/documentation/property.hbs diff --git a/data/web/documentation/propertylist.hbs b/data/web/documentation/propertylist.hbs new file mode 100644 index 0000000000..95a2854bbc --- /dev/null +++ b/data/web/documentation/propertylist.hbs @@ -0,0 +1,13 @@ +{{#each data}} +
    +
    +

    {{name}}

    + {{#each properties}} + {{> property}} + {{/each}} + {{#each propertyOwners}} + {{> propertyOwners}} + {{/each}} +
    +
    +{{/each}} diff --git a/data/web/properties/propertyowner.hbs b/data/web/documentation/propertyowners.hbs similarity index 93% rename from data/web/properties/propertyowner.hbs rename to data/web/documentation/propertyowners.hbs index 2417eceaf3..c889651ae7 100644 --- a/data/web/properties/propertyowner.hbs +++ b/data/web/documentation/propertyowners.hbs @@ -10,9 +10,8 @@ {{> property}} {{/each}} {{#each propertyOwners}} - {{> propertyOwner}} + {{> propertyOwners}} {{/each}} - diff --git a/data/web/scenelicense/scenelicense.hbs b/data/web/documentation/scenelicense.hbs similarity index 93% rename from data/web/scenelicense/scenelicense.hbs rename to data/web/documentation/scenelicense.hbs index 2bd8e98d20..0399a74564 100644 --- a/data/web/scenelicense/scenelicense.hbs +++ b/data/web/documentation/scenelicense.hbs @@ -1,3 +1,4 @@ +{{#each data}}
    @@ -14,3 +15,4 @@
    +{{/each}} diff --git a/data/web/documentation/script.js b/data/web/documentation/script.js index 00bd699b00..de1f726e0a 100644 --- a/data/web/documentation/script.js +++ b/data/web/documentation/script.js @@ -1,22 +1,105 @@ +var parseJson = (elementId) => { + var jsonElement = document.getElementById(elementId); + return JSON.parse(jsonElement.innerHTML); +}; + +var urlifyFunction = (options, context) => { + var data = context.data; + + var identifier = options.replace(/ /g, ''); + // while (data) { + // data = data._parent + // if (data && data.key !== undefined) { + // identifier = data.key + "-" + identifier; + // } + // } + + return identifier; +}; + + +var copyTextToClipboard = (text) => { + var textArea = document.createElement("textarea"); + textArea.style.position = 'fixed'; + textArea.style.top = 0; + textArea.style.left = 0; + + textArea.style.width = '2em'; + textArea.style.height = '2em'; + + textArea.style.padding = 0; + + textArea.style.border = 'none'; + textArea.style.outline = 'none'; + textArea.style.boxShadow = 'none'; + + textArea.style.background = 'transparent'; + textArea.value = text; + + document.body.appendChild(textArea); + + textArea.select(); + document.execCommand('copy'); + + document.body.removeChild(textArea); +} + + +var sidebarNavigate = (index) => { + var subtreeSelector = "#index" + index + "-subtree"; + + if ((currentDocumentation == documentation[index]) + && (document.querySelector(subtreeSelector).innerHTML != "") ) + { + var subtreeSelector = "#index" + index + "-subtree"; + document.querySelector(subtreeSelector).innerHTML = ""; + return; + } + currentDocumentation = documentation[index]; + var template = templates[currentDocumentation.identifier]; + var html = template(currentDocumentation); + document.getElementById('current-documentation-container').innerHTML = html; + //empty existing subtreee + document.querySelectorAll('.sidebar-subtree').forEach((e) => {e.innerHTML = ''}); + //create current subtree + var subTreeHTML = ""; + for (var i = 0; i < currentDocumentation.data.length; ++i) { + var entry = currentDocumentation.data[i]; + var entryProp = "name"; + if (!entry[entryProp]) { + entryProp = "library"; + if (!entry[entryProp]) { + entryProp = "key"; + } + } + + var entryValue = entry[entryProp]; + var entryURL = entryValue; + switch (currentDocumentation.identifier) { + case 'scripting': + entryURL = "openspace" + (entryValue ? "." + entryValue : ""); + entryValue = entryURL; + break; + default: + entryURL = urlifyFunction(entryValue, entry); + } + + subTreeHTML += "
  • "; + subTreeHTML += "" + entryValue + ""; + subTreeHTML += "
  • "; + } + + //find our subtree and fill it with data + document.querySelector(subtreeSelector).innerHTML = subTreeHTML; +}; + window.onload = function () { var mainTemplateElement = document.getElementById('mainTemplate'); var mainTemplate = Handlebars.compile(mainTemplateElement.innerHTML); - var documentationTemplateElement = document.getElementById('documentationTemplate'); - Handlebars.registerPartial('documentation', documentationTemplateElement.innerHTML); + window.registerTemplates(); - Handlebars.registerHelper('urlify', function(options, context) { - var data = context.data; - var identifier = options.replace(" ", "-").toLowerCase(); - - while (data = data._parent) { - if (data.key !== undefined) { - identifier = data.key + "-" + identifier; - } - } - - return identifier; - }); + Handlebars.registerHelper('urlify', urlifyFunction); Handlebars.registerHelper('level', function(options, context) { var data = context.data; @@ -31,15 +114,31 @@ window.onload = function () { return level; }); - documentation.sort(function (a, b) { - return a.name < b.name ? -1 : (a.name > b.name ? 1 : 0); - }); + for (var i = 0; i < documentation.length; i++) { + documentation[i].data.sort(function (a, b) { + return a.name < b.name ? -1 : (a.name > b.name ? 1 : 0); + }); + + if (documentation[i].identifier == "propertylist") { + for (var j = 0; j < documentation[i].data.length; j++) { + if (documentation[i].data[j].name == "Scene") { + documentation[i].data.splice(j, 1); + } + } + } + + } + + currentDocumentation = documentation[3]; var data = { documentation: documentation, - version: version + version: version, + currentDocumentation: currentDocumentation } + var templates = {}; + var contents = mainTemplate(data); document.body.innerHTML = contents; -} \ No newline at end of file +} diff --git a/data/web/documentation/scripting.hbs b/data/web/documentation/scripting.hbs new file mode 100644 index 0000000000..984a92ed02 --- /dev/null +++ b/data/web/documentation/scripting.hbs @@ -0,0 +1,28 @@ +{{#each data}} +
    +
    +

    + + openspace{{#if library}}.{{library}}{{/if}} + +

    + {{#each functions}} +
    + +
    + {{/each}} +
    +
    +{{/each}} diff --git a/data/web/common/style.css b/data/web/documentation/style.css similarity index 100% rename from data/web/common/style.css rename to data/web/documentation/style.css index b22e07cb61..08cea11009 100644 --- a/data/web/common/style.css +++ b/data/web/documentation/style.css @@ -146,12 +146,12 @@ body { width: 280px; margin: 0; padding: 0; - list-style: none; } .sidebar-nav li { text-indent: 20px; line-height: 40px; + list-style: none; } .sidebar-nav li a { diff --git a/data/web/documentation/documentation.hbs b/data/web/documentation/toplevel.hbs similarity index 82% rename from data/web/documentation/documentation.hbs rename to data/web/documentation/toplevel.hbs index b22165447b..3701dd057a 100644 --- a/data/web/documentation/documentation.hbs +++ b/data/web/documentation/toplevel.hbs @@ -1,3 +1,7 @@ +{{#each data}} +
    +
    +

    {{name}}

    {{#each entries}}
    @@ -14,7 +18,7 @@

    {{description}}

    {{documentation}}

    {{#with restrictions}} - {{>documentation}} + {{>toplevel}} {{/with}} {{#if reference}} {{#if reference.found}} @@ -27,3 +31,6 @@
    {{/each}} +
    +
    +{{/each}} \ No newline at end of file diff --git a/data/web/factories/factory.hbs b/data/web/factories/factory.hbs deleted file mode 100644 index 7c73a9462f..0000000000 --- a/data/web/factories/factory.hbs +++ /dev/null @@ -1,13 +0,0 @@ -{{#each classes}} -
    -
    - -
    -
    -{{/each}} diff --git a/data/web/factories/main.hbs b/data/web/factories/main.hbs deleted file mode 100644 index 56f1a3187d..0000000000 --- a/data/web/factories/main.hbs +++ /dev/null @@ -1,35 +0,0 @@ -
    - - -
    -
    -

    OpenSpace Factories

    -

    Version: {{version.[0]}}.{{version.[1]}}.{{version.[2]}}

    - {{#each factories}} -
    -
    -

    - - {{name}} - -

    - {{> factory}} -
    -
    - {{/each}} -
    -
    -
    diff --git a/data/web/factories/script.js b/data/web/factories/script.js deleted file mode 100644 index 02322b7f3e..0000000000 --- a/data/web/factories/script.js +++ /dev/null @@ -1,45 +0,0 @@ -window.onload = function () { - var mainTemplateElement = document.getElementById('mainTemplate'); - var mainTemplate = Handlebars.compile(mainTemplateElement.innerHTML); - - var factoryTemplateElement = document.getElementById('factoryTemplate'); - Handlebars.registerPartial('factory', factoryTemplateElement.innerHTML); - - Handlebars.registerHelper('urlify', function(options, context) { - var data = context.data; - var identifier = options.replace(" ", "-").toLowerCase(); - - while (data = data._parent) { - if (data.key !== undefined) { - identifier = data.key + "-" + identifier; - } - } - - return identifier; - }); - - Handlebars.registerHelper('level', function(options, context) { - var data = context.data; - var level = 0; - - while (data = data._parent) { - if (data.key !== undefined) { - ++level; - } - } - - return level; - }); - - factories.sort(function (a, b) { - return a.name < b.name ? -1 : (a.name > b.name ? 1 : 0); - }); - - var data = { - factories: factories, - version: version - } - - var contents = mainTemplate(data); - document.body.innerHTML = contents; -} \ No newline at end of file diff --git a/data/web/keybindings/main.hbs b/data/web/keybindings/main.hbs deleted file mode 100644 index ba1de9fdd0..0000000000 --- a/data/web/keybindings/main.hbs +++ /dev/null @@ -1,9 +0,0 @@ -
    -
    -

    OpenSpace Keybindings

    -

    Version: {{version.[0]}}.{{version.[1]}}.{{version.[2]}}

    - {{#each keybindings}} - {{> keybinding}} - {{/each}} -
    -
    \ No newline at end of file diff --git a/data/web/keybindings/script.js b/data/web/keybindings/script.js deleted file mode 100644 index 018d49eb48..0000000000 --- a/data/web/keybindings/script.js +++ /dev/null @@ -1,45 +0,0 @@ -window.onload = function () { - var mainTemplateElement = document.getElementById('mainTemplate'); - var mainTemplate = Handlebars.compile(mainTemplateElement.innerHTML); - - var keybindingTemplateElement = document.getElementById('keybindingTemplate'); - Handlebars.registerPartial('keybinding', keybindingTemplateElement.innerHTML); - - Handlebars.registerHelper('urlify', function(options, context) { - var data = context.data; - var identifier = options.replace(" ", "-").toLowerCase(); - - while (data = data._parent) { - if (data.key !== undefined) { - identifier = data.key + "-" + identifier; - } - } - - return identifier; - }); - - Handlebars.registerHelper('level', function(options, context) { - var data = context.data; - var level = 0; - - while (data = data._parent) { - if (data.key !== undefined) { - ++level; - } - } - - return level; - }); - - keybindings.sort(function (a, b) { - return a.key < b.key ? -1 : (a.key > b.key ? 1 : 0); - }); - - var data = { - keybindings: keybindings, - version: version - } - - var contents = mainTemplate(data); - document.body.innerHTML = contents; -} \ No newline at end of file diff --git a/data/web/luascripting/main.hbs b/data/web/luascripting/main.hbs deleted file mode 100644 index 1d67289346..0000000000 --- a/data/web/luascripting/main.hbs +++ /dev/null @@ -1,35 +0,0 @@ -
    - - -
    -
    -

    OpenSpace Lua Scripting

    -

    Version: {{version.[0]}}.{{version.[1]}}.{{version.[2]}}

    - {{#each scripting}} - - {{/each}} -
    -
    -
    diff --git a/data/web/luascripting/script.js b/data/web/luascripting/script.js deleted file mode 100644 index da7dede2e4..0000000000 --- a/data/web/luascripting/script.js +++ /dev/null @@ -1,45 +0,0 @@ -window.onload = function () { - var mainTemplateElement = document.getElementById('mainTemplate'); - var mainTemplate = Handlebars.compile(mainTemplateElement.innerHTML); - - var scriptingTemplateElement = document.getElementById('scriptingTemplate'); - Handlebars.registerPartial('scripting', scriptingTemplateElement.innerHTML); - - Handlebars.registerHelper('urlify', function(options, context) { - var data = context.data; - var identifier = options.replace(" ", "-").toLowerCase(); - - while (data = data._parent) { - if (data.key !== undefined) { - identifier = data.key + "-" + identifier; - } - } - - return identifier; - }); - - Handlebars.registerHelper('level', function(options, context) { - var data = context.data; - var level = 0; - - while (data = data._parent) { - if (data.key !== undefined) { - ++level; - } - } - - return level; - }); - - scripting.sort(function (a, b) { - return a.library < b.library ? -1 : (a.library > b.library ? 1 : 0); - }); - - var data = { - scripting: scripting, - version: version - } - - var contents = mainTemplate(data); - document.body.innerHTML = contents; -} \ No newline at end of file diff --git a/data/web/luascripting/scripting.hbs b/data/web/luascripting/scripting.hbs deleted file mode 100644 index 00e35ab6d4..0000000000 --- a/data/web/luascripting/scripting.hbs +++ /dev/null @@ -1,17 +0,0 @@ -{{#each functions}} -
    -
    - -
    -
    -{{/each}} diff --git a/data/web/properties/main.hbs b/data/web/properties/main.hbs deleted file mode 100644 index ae6024b98f..0000000000 --- a/data/web/properties/main.hbs +++ /dev/null @@ -1,37 +0,0 @@ -
    - - -
    -
    -

    OpenSpace Scene Properties

    -

    Version: {{version.[0]}}.{{version.[1]}}.{{version.[2]}}

    - - {{#each propertyOwners}} -
    -
    -

    {{name}}

    - {{#each properties}} - {{> property}} - {{/each}} - {{#each propertyOwners}} - {{> propertyOwner}} - {{/each}} -
    -
    - {{/each}} -
    -
    -
    diff --git a/data/web/properties/script.js b/data/web/properties/script.js deleted file mode 100644 index 642d860c05..0000000000 --- a/data/web/properties/script.js +++ /dev/null @@ -1,73 +0,0 @@ -function copyTextToClipboard(text) { - var textArea = document.createElement("textarea"); - textArea.style.position = 'fixed'; - textArea.style.top = 0; - textArea.style.left = 0; - - textArea.style.width = '2em'; - textArea.style.height = '2em'; - - textArea.style.padding = 0; - - textArea.style.border = 'none'; - textArea.style.outline = 'none'; - textArea.style.boxShadow = 'none'; - - textArea.style.background = 'transparent'; - textArea.value = text; - - document.body.appendChild(textArea); - - textArea.select(); - document.execCommand('copy'); - - document.body.removeChild(textArea); -} - -window.onload = function () { - var mainTemplateElement = document.getElementById('mainTemplate'); - var mainTemplate = Handlebars.compile(mainTemplateElement.innerHTML); - - var propertyOwnerTemplateElement = document.getElementById('propertyOwnerTemplate'); - Handlebars.registerPartial('propertyOwner', propertyOwnerTemplateElement.innerHTML); - - var propertyTemplateElement = document.getElementById('propertyTemplate'); - Handlebars.registerPartial('property', propertyTemplateElement.innerHTML); - - Handlebars.registerHelper('urlify', function(options, context) { - var data = context.data; - var identifier = options.replace(" ", "-").toLowerCase(); - - while (data = data._parent) { - if (data.key !== undefined) { - identifier = data.key + "-" + identifier; - } - } - return identifier; - }); - - Handlebars.registerHelper('level', function(options, context) { - var data = context.data; - var level = 0; - - while (data = data._parent) { - if (data.key !== undefined) { - ++level; - } - } - - return level; - }); - - propertyOwners.sort(function (a, b) { - return a.name < b.name ? -1 : (a.name > b.name ? 1 : 0); - }); - - var data = { - propertyOwners: propertyOwners, - version: version - } - - var contents = mainTemplate(data); - document.body.innerHTML = contents; -} diff --git a/data/web/scenelicense/main.hbs b/data/web/scenelicense/main.hbs deleted file mode 100644 index 786b51a823..0000000000 --- a/data/web/scenelicense/main.hbs +++ /dev/null @@ -1,9 +0,0 @@ -
    -
    -

    OpenSpace Scene License Information

    -

    Version: {{version.[0]}}.{{version.[1]}}.{{version.[2]}}

    - {{#each sceneLicenses}} - {{> scenelicense}} - {{/each}} -
    -
    \ No newline at end of file diff --git a/data/web/scenelicense/script.js b/data/web/scenelicense/script.js deleted file mode 100644 index 9e1e815d80..0000000000 --- a/data/web/scenelicense/script.js +++ /dev/null @@ -1,41 +0,0 @@ -window.onload = function () { - var mainTemplateElement = document.getElementById('mainTemplate'); - var mainTemplate = Handlebars.compile(mainTemplateElement.innerHTML); - - var sceneLicenseTemplate = document.getElementById('sceneLicenseTemplate'); - Handlebars.registerPartial('scenelicense', sceneLicenseTemplate.innerHTML); - - Handlebars.registerHelper('urlify', function(options, context) { - var data = context.data; - var identifier = options.replace(" ", "-").toLowerCase(); - - while (data = data._parent) { - if (data.key !== undefined) { - identifier = data.key + "-" + identifier; - } - } - - return identifier; - }); - - Handlebars.registerHelper('level', function(options, context) { - var data = context.data; - var level = 0; - - while (data = data._parent) { - if (data.key !== undefined) { - ++level; - } - } - - return level; - }); - - var data = { - sceneLicenses: sceneLicenses, - version: version - } - - var contents = mainTemplate(data); - document.body.innerHTML = contents; -} \ No newline at end of file diff --git a/include/openspace/documentation/documentationengine.h b/include/openspace/documentation/documentationengine.h index c0d6d6d7ee..24760ed2d7 100644 --- a/include/openspace/documentation/documentationengine.h +++ b/include/openspace/documentation/documentationengine.h @@ -70,6 +70,14 @@ public: */ void addDocumentation(Documentation documentation); + /* Adds the \p templates to the list of templates that are written to the + * documentation html file. + * \param templates Vector of templates to add. Most of the time this list + * will just contain one item, but some modules may wish to provide + * multiple templates for subtypes, etc + */ + void addHandlebarTemplates(std::vector templates); + /** * Returns a list of all registered Documentation%s. * @@ -88,11 +96,25 @@ public: */ static DocumentationEngine& ref(); -private: + /** + * Generates the documentation html file. Generated file will have embeded + * in it: HandlebarJS Templates (from _handlebarTemplates) and json (from + * \p data) along with the base template and js/css files from the source + * directory ${WEB}/documentation + * \param templates Vector of templates to add. Most of the time this list + * will just contain one item, but some modules may wish to provide + * multiple templates for subtypes, etc + */ + void writeDocumentationHtml(const std::string path, const std::string data); + std::string generateJson() const override; +private: + /// The list of all Documentation%s that are stored by the DocumentationEngine std::vector _documentations; + /// The list of templates to render the documentation with. + std::vector _handlebarTemplates; static DocumentationEngine* _instance; }; diff --git a/include/openspace/documentation/documentationgenerator.h b/include/openspace/documentation/documentationgenerator.h index ad255aaaed..43733989c3 100644 --- a/include/openspace/documentation/documentationgenerator.h +++ b/include/openspace/documentation/documentationgenerator.h @@ -67,20 +67,16 @@ public: * \pre javascriptFilename must not be empty */ DocumentationGenerator(std::string name, std::string jsonName, - std::vector handlebarTemplates, - std::string javascriptFilename); + std::vector handlebarTemplates); /// Default constructor virtual ~DocumentationGenerator() = default; - /** - * Create the documentation into the provided filename. Any existing file will be - * silently overwritten. This method will call the generateJson method that can be - * used by concrete subclasses to provide the actual data that is provided in the - * documentation. - * \param filename The filename in which the documentation is written - */ - void writeDocumentation(const std::string& filename); + //getter for handlebar templates + std::vector templatesToRegister(); + + //getter for identifier + std::string jsonName(); /** * This abstract method is used by concrete subclasses to provide the actual data that @@ -96,7 +92,6 @@ private: const std::string _name; const std::string _jsonName; const std::vector _handlebarTemplates; - const std::string _javascriptFile; }; /** diff --git a/include/openspace/engine/configuration.h b/include/openspace/engine/configuration.h index 5e567ff4c2..12a4e9e093 100644 --- a/include/openspace/engine/configuration.h +++ b/include/openspace/engine/configuration.h @@ -52,16 +52,10 @@ struct Configuration { }; Logging logging; - std::string scriptLog = ""; + std::string scriptLog; struct DocumentationInfo { - std::string lua = ""; - std::string property = ""; - std::string sceneProperty = ""; - std::string keyboard = ""; - std::string documentation = ""; - std::string factory = ""; - std::string license = ""; + std::string path; }; DocumentationInfo documentation; @@ -99,8 +93,8 @@ struct Configuration { bool isActive = false; bool isSynchronous = true; struct IdentifierFilter { - std::string type = ""; - std::string source = ""; + std::string type; + std::string source; unsigned int identifier = 0; }; std::vector identifierFilters; diff --git a/include/openspace/engine/openspaceengine.h b/include/openspace/engine/openspaceengine.h index b95b6a859f..c6d5888d42 100644 --- a/include/openspace/engine/openspaceengine.h +++ b/include/openspace/engine/openspaceengine.h @@ -115,6 +115,9 @@ private: bool _hasScheduledAssetLoading = false; std::string _scheduledAssetPathToLoad; + //grabs json from each module to pass to the documentation engine. + std::string _documentationJson; + ShutdownInformation _shutdown; // The first frame might take some more time in the update loop, so we need to know to diff --git a/include/openspace/properties/propertyowner.h b/include/openspace/properties/propertyowner.h index 47d1c0ae93..8844726c53 100644 --- a/include/openspace/properties/propertyowner.h +++ b/include/openspace/properties/propertyowner.h @@ -291,6 +291,9 @@ public: */ void removeTag(const std::string& tag); + //Generate JSON for documentation + std::string generateJson() const override; + protected: /// The unique identifier of this PropertyOwner @@ -301,8 +304,6 @@ protected: std::string _description; private: - std::string generateJson() const override; - /// The owner of this PropertyOwner PropertyOwner* _owner = nullptr; /// A list of all registered Property's diff --git a/include/openspace/scene/scene.h b/include/openspace/scene/scene.h index 98d95aaca6..cfaae6e160 100644 --- a/include/openspace/scene/scene.h +++ b/include/openspace/scene/scene.h @@ -147,12 +147,12 @@ public: const std::vector& allSceneGraphNodes() const; /** - * Write information about the license information for the scenegraph nodes that are + * Generate JSON about the license information for the scenegraph nodes that are * contained in this scene * \param path The file path that will contain the documentation about the licenses * used in this scene */ - void writeSceneLicenseDocumentation(const std::string& path) const; + std::string generateSceneLicenseDocumentationJson(); /** * Returns a map from identifier to scene graph node. diff --git a/include/openspace/scene/scenelicensewriter.h b/include/openspace/scene/scenelicensewriter.h index af46d44342..59270476ab 100644 --- a/include/openspace/scene/scenelicensewriter.h +++ b/include/openspace/scene/scenelicensewriter.h @@ -36,10 +36,9 @@ struct SceneLicense; class SceneLicenseWriter : public DocumentationGenerator { public: SceneLicenseWriter(std::vector licenses); - -private: std::string generateJson() const override; +private: const std::vector& _licenses; }; diff --git a/modules/globebrowsing/globebrowsingmodule.cpp b/modules/globebrowsing/globebrowsingmodule.cpp index 29385a899e..6d7aa584d6 100644 --- a/modules/globebrowsing/globebrowsingmodule.cpp +++ b/modules/globebrowsing/globebrowsingmodule.cpp @@ -61,6 +61,7 @@ namespace { constexpr const char* _loggerCat = "GlobeBrowsingModule"; + constexpr const char* _factoryName = "TileProvider"; constexpr const openspace::properties::Property::PropertyInfo CacheEnabledInfo = { "CacheEnabled", @@ -267,7 +268,7 @@ void GlobeBrowsingModule::internalInitialize(const ghoul::Dictionary& dict) { )] ); - FactoryManager::ref().addFactory(std::move(fTileProvider)); + FactoryManager::ref().addFactory(std::move(fTileProvider), _factoryName); auto fDashboard = FactoryManager::ref().factory(); ghoul_assert(fDashboard, "Dashboard factory was not created"); diff --git a/openspace.cfg b/openspace.cfg index 3b497a4db9..94200eee28 100644 --- a/openspace.cfg +++ b/openspace.cfg @@ -154,13 +154,7 @@ Logging = { ScriptLog = "${LOGS}/ScriptLog.txt" Documentation = { - LuaDocumentation = "${DOCUMENTATION}/LuaScripting.html", - PropertyDocumentation = "${DOCUMENTATION}/Properties.html", - ScenePropertyDocumentation = "${DOCUMENTATION}/SceneProperties.html", - KeyboardShortcuts = "${DOCUMENTATION}/KeyboardMapping.html", - Documentation = "${DOCUMENTATION}/Documentation.html", - FactoryDocumentation = "${DOCUMENTATION}/FactoryDocumentation.html", - LicenseDocumentation = "${DOCUMENTATION}/License.html", + Path = "${DOCUMENTATION}/" } VersionCheckUrl = "http://data.openspaceproject.com/latest-version" diff --git a/src/documentation/core_registration.cpp b/src/documentation/core_registration.cpp index 610ddbed84..74448d18d6 100644 --- a/src/documentation/core_registration.cpp +++ b/src/documentation/core_registration.cpp @@ -69,6 +69,8 @@ void registerCoreClasses(documentation::DocumentationEngine& engine) { engine.addDocumentation(LightSource::Documentation()); } +//NOTE: should this be in the documentation/core_reg.cpp file? Seems to be here just because it has the same +//method name (and similar implementaiton) as the documentation version. void registerCoreClasses(scripting::ScriptEngine& engine) { engine.addLibrary(Dashboard::luaLibrary()); engine.addLibrary(MissionManager::luaLibrary()); diff --git a/src/documentation/documentationengine.cpp b/src/documentation/documentationengine.cpp index fc68608828..635855c0ea 100644 --- a/src/documentation/documentationengine.cpp +++ b/src/documentation/documentationengine.cpp @@ -28,11 +28,15 @@ #include #include #include +#include + +#include namespace { - constexpr const char* MainTemplateFilename = "${WEB}/documentation/main.hbs"; - constexpr const char* DocumentationTemplateFilename = - "${WEB}/documentation/documentation.hbs"; + constexpr const char* HandlebarsFilename = + "${WEB}/documentation/handlebars-v4.0.5.js"; + constexpr const char* BootstrapFilename = "${WEB}/common/bootstrap.min.css"; + constexpr const char* CssFilename = "${WEB}/documentation/style.css"; constexpr const char* JsFilename = "${WEB}/documentation/script.js"; } // namespace @@ -41,24 +45,22 @@ namespace openspace::documentation { DocumentationEngine* DocumentationEngine::_instance = nullptr; DocumentationEngine::DuplicateDocumentationException::DuplicateDocumentationException( - Documentation doc) + Documentation documentation) : ghoul::RuntimeError(fmt::format( "Duplicate Documentation with name '{}' and id '{}'", - doc.name, - doc.id + documentation.name, + documentation.id )) - , documentation(std::move(doc)) + , documentation(std::move(documentation)) {} DocumentationEngine::DocumentationEngine() : DocumentationGenerator( - "Documentation", - "documentation", + "Top Level", + "toplevel", { - { "mainTemplate", MainTemplateFilename }, - { "documentationTemplate", DocumentationTemplateFilename } - }, - JsFilename + { "toplevelTemplate", "${WEB}/documentation/toplevel.hbs" }, + } ) {} @@ -85,69 +87,6 @@ DocumentationEngine& DocumentationEngine::ref() { return *_instance; } -std::string generateTextDocumentation(const Documentation& d, int& indentLevel) { - auto indentMessage = [&indentLevel](const std::string& prefix, const std::string& msg) - { - if (msg.empty()) { - return std::string(); - } - else { - return std::string(indentLevel, '\t') + prefix + ": " + msg + '\n'; - } - }; - std::string result; - - result += indentMessage("Name", d.name); - if (!d.name.empty()) { - ++indentLevel; - } - for (const DocumentationEntry& p : d.entries) { - result += indentMessage("Key", (p.key == "*") ? p.key : "\"" + p.key + "\""); - result += indentMessage("Optional", (p.optional ? "true" : "false")); - result += indentMessage("Type", p.verifier->type()); - result += indentMessage("Documentation", p.documentation); - TableVerifier* tv = dynamic_cast(p.verifier.get()); - ReferencingVerifier* rv = dynamic_cast(p.verifier.get()); - - // We have to check ReferencingVerifier first as a ReferencingVerifier is also a - // TableVerifier - if (rv) { - const std::vector& documentations = DocEng.documentations(); - auto it = std::find_if( - documentations.begin(), - documentations.end(), - [rv](const Documentation& doc) { return doc.id == rv->identifier; } - ); - - if (it == documentations.end()) { - result += indentMessage("Referencing", rv->identifier + "(NOT FOUND)"); - } - else { - result += indentMessage("Referencing", it->name); - } - } else if (tv) { - // We have a TableVerifier, so we need to recurse - ++indentLevel; - result += generateTextDocumentation( - { "", "", tv->documentations }, - indentLevel - ); - result = result.substr(0, result.size() - 2); - --indentLevel; - } - else { - result += indentMessage("Restrictions", p.verifier->documentation()); - } - result += indentMessage("Documentation", p.documentation); - result += "\n\n"; - } - if (!d.name.empty()) { - --indentLevel; - } - - return result; -} - std::string generateJsonDocumentation(const Documentation& d) { std::stringstream result; result << "{"; @@ -203,77 +142,6 @@ std::string generateJsonDocumentation(const Documentation& d) { return result.str(); } -std::string generateHtmlDocumentation(const Documentation& d) { - std::stringstream html; - - html << "\t\n" - << "\t\t" << d.name << "\n"; - - for (const DocumentationEntry& p : d.entries) { - html << "\t\n" - << "\t\t\n" - << "\t\t" << p.key << "\n" - << "\t\t" << (p.optional ? "Optional" : "Required") << "\n" - << "\t\t" << escapedJson(p.documentation) << "\n" - << "\t\t" << p.verifier->type() << "\n"; - - TableVerifier* tv = dynamic_cast(p.verifier.get()); - ReferencingVerifier* rv = dynamic_cast(p.verifier.get()); - - // We have to check ReferencingVerifier first as a ReferencingVerifier is also a - // TableVerifier - if (rv) { - const std::vector& documentations = DocEng.documentations(); - auto it = std::find_if( - documentations.begin(), - documentations.end(), - [rv](const Documentation& doc) { return doc.id == rv->identifier; } - ); - - if (it == documentations.end()) { - html << "\t\t" - << "" - << "Could not find identifier: " << rv->identifier - << "" - << ""; - } - else { - html << "\t\t" - << "\t\t\tReferencing: " - << "identifier << "\">" << it->name << "" - << "\t\t"; - } - } - else if (tv) { - // We have a TableVerifier, so we need to recurse - html << "\n" - << "\t\n" - << "\t\t\n" - << "\t\t\t\n" - << "\t\t\t\n" - << "\t\t\t\n" - << "\t\t\t\n" - << "\t\t\t\n" - << "\t\t\t\n" - << "\t\t\n" - << "\t\n" - << "\t\n" - << generateHtmlDocumentation({ "", "", tv->documentations }) - << "\t\n" - << "
    KeyOptionalTypeRestrictionsDocumentation
    \n" - << "\n"; - } - else { - html << "\t\t" << p.verifier->documentation() << "\n"; - } - html << "\t\t" << p.documentation << "\n" - << "\t\n"; - - } - - return html.str(); -} - std::string DocumentationEngine::generateJson() const { std::stringstream json; json << "["; @@ -310,8 +178,135 @@ void DocumentationEngine::addDocumentation(Documentation documentation) { } } +void DocumentationEngine::addHandlebarTemplates(std::vector templates) { + _handlebarTemplates.insert(std::end(_handlebarTemplates), std::begin(templates), std::end(templates)); +} + std::vector DocumentationEngine::documentations() const { return _documentations; } +void DocumentationEngine::writeDocumentationHtml(const std::string path, const std::string data) { + + std::ifstream handlebarsInput; + handlebarsInput.exceptions(~std::ofstream::goodbit); + handlebarsInput.open(absPath(HandlebarsFilename)); + const std::string handlebarsContent = std::string( + std::istreambuf_iterator(handlebarsInput), + std::istreambuf_iterator() + ); + std::ifstream jsInput; + jsInput.exceptions(~std::ofstream::goodbit); + jsInput.open(absPath(JsFilename)); + const std::string jsContent = std::string( + std::istreambuf_iterator(jsInput), + std::istreambuf_iterator() + ); + + std::ifstream bootstrapInput; + bootstrapInput.exceptions(~std::ofstream::goodbit); + bootstrapInput.open(absPath(BootstrapFilename)); + const std::string bootstrapContent = std::string( + std::istreambuf_iterator(bootstrapInput), + std::istreambuf_iterator() + ); + + std::ifstream cssInput; + cssInput.exceptions(~std::ofstream::goodbit); + cssInput.open(absPath(CssFilename)); + const std::string cssContent = std::string( + std::istreambuf_iterator(cssInput), + std::istreambuf_iterator() + ); + + std::string filename = path + ("index.html"); + std::ofstream file; + file.exceptions(~std::ofstream::goodbit); + file.open(filename); + + // We probably should escape backslashes here? + file << "" << '\n' + << "" << '\n' + << " " << "" << '\n'; + + //write handlebar templates to htmlpage as script elements (as per hb) + for (const HandlebarTemplate& t : _handlebarTemplates) { + const char* Type = "text/x-handlebars-template"; + file << " " << '\n'; + } + + //write main template + file << " " << '\n'; + + //write scripte to register templates dynamically + file << " " << '\n'; + + + const std::string DataId = "data"; + + const std::string Version = + "[" + + std::to_string(OPENSPACE_VERSION_MAJOR) + "," + + std::to_string(OPENSPACE_VERSION_MINOR) + "," + + std::to_string(OPENSPACE_VERSION_PATCH) + + "]"; + + file + << " " << "" << '\n'; + + + file + << " " << "" << '\n' + << " " << "" << '\n' + << " " << "OpenSpace Documentation" << '\n' + << " " << "" << '\n' + << " " << "" << '\n' + << " " << "" << '\n' + << "" << '\n'; +} + + } // namespace openspace::documentation diff --git a/src/documentation/documentationgenerator.cpp b/src/documentation/documentationgenerator.cpp index cedce29ba3..92ab7a60d9 100644 --- a/src/documentation/documentationgenerator.cpp +++ b/src/documentation/documentationgenerator.cpp @@ -30,23 +30,14 @@ #include #include -namespace { - constexpr const char* HandlebarsFilename = "${WEB}/common/handlebars-v4.0.5.js"; - constexpr const char* BaseLibraryFilename = "${WEB}/common/base.js"; - constexpr const char* BootstrapFilename = "${WEB}/common/bootstrap.min.css"; - constexpr const char* CssFilename = "${WEB}/common/style.css"; -} // namespace - namespace openspace { DocumentationGenerator::DocumentationGenerator(std::string name, std::string jsonName, - std::vector handlebarTemplates, - std::string javascriptFilename) + std::vector handlebarTemplates) : _name(std::move(name)) , _jsonName(std::move(jsonName)) , _handlebarTemplates(std::move(handlebarTemplates)) - , _javascriptFile(std::move(javascriptFilename)) { ghoul_precondition(!_name.empty(), "name must not be empty"); ghoul_precondition(!_jsonName.empty(), "jsonName must not be empty"); @@ -55,109 +46,16 @@ DocumentationGenerator::DocumentationGenerator(std::string name, ghoul_precondition(!t.name.empty(), "name must not be empty"); ghoul_precondition(!t.filename.empty(), "filename must not be empty"); } - ghoul_precondition(!_javascriptFile.empty(), "javascriptFilename must not be empty"); } -void DocumentationGenerator::writeDocumentation(const std::string& filename) { - std::ifstream handlebarsInput; - handlebarsInput.exceptions(~std::ofstream::goodbit); - handlebarsInput.open(absPath(HandlebarsFilename)); - const std::string handlebarsContent = std::string( - std::istreambuf_iterator(handlebarsInput), - std::istreambuf_iterator() - ); +std::vector +DocumentationGenerator::templatesToRegister() +{ + return _handlebarTemplates; +} - std::ifstream baseLibarayInput; - baseLibarayInput.exceptions(~std::ofstream::goodbit); - baseLibarayInput.open(absPath(BaseLibraryFilename)); - const std::string baseLibraryContent = std::string( - std::istreambuf_iterator(baseLibarayInput), - std::istreambuf_iterator() - ); - - std::ifstream jsInput; - jsInput.exceptions(~std::ofstream::goodbit); - jsInput.open(absPath(_javascriptFile)); - const std::string jsContent = std::string( - std::istreambuf_iterator(jsInput), - std::istreambuf_iterator() - ); - - std::ifstream bootstrapInput; - bootstrapInput.exceptions(~std::ofstream::goodbit); - bootstrapInput.open(absPath(BootstrapFilename)); - const std::string bootstrapContent = std::string( - std::istreambuf_iterator(bootstrapInput), - std::istreambuf_iterator() - ); - - std::ifstream cssInput; - cssInput.exceptions(~std::ofstream::goodbit); - cssInput.open(absPath(CssFilename)); - const std::string cssContent = std::string( - std::istreambuf_iterator(cssInput), - std::istreambuf_iterator() - ); - - std::ofstream file; - file.exceptions(~std::ofstream::goodbit); - file.open(filename); - - std::string json = generateJson(); - // We probably should escape backslashes here? - - file << "" << '\n' - << "" << '\n' - << "\t" << "" << '\n'; - - for (const HandlebarTemplate& t : _handlebarTemplates) { - const char* Type = "text/x-handlebars-template"; - file << "\t\t" - << "" << '\n'; - } - - const std::string DataId = "data"; - - const std::string Version = - "[" + - std::to_string(OPENSPACE_VERSION_MAJOR) + "," + - std::to_string(OPENSPACE_VERSION_MINOR) + "," + - std::to_string(OPENSPACE_VERSION_PATCH) + - "]"; - - file - << "\t" << "" << '\n'; - - - file - << "\t" << "" << '\n' - << "\t" << "" << '\n' - << "\t\t" << "" << _name << "" << '\n' - << "\t" << "" << '\n' - << "\t" << "" << '\n' - << "\t" << "" << '\n' - << "" << '\n'; +std::string DocumentationGenerator::jsonName() { + return _jsonName; } std::string escapedJson(const std::string& text) { diff --git a/src/engine/configuration.cpp b/src/engine/configuration.cpp index 6d80a43f47..ee9264e4ad 100644 --- a/src/engine/configuration.cpp +++ b/src/engine/configuration.cpp @@ -51,13 +51,9 @@ namespace { constexpr const char* KeyImmediateFlush = "ImmediateFlush"; constexpr const char* KeyLogs = "Logs"; constexpr const char* KeyCapabilitiesVerbosity = "CapabilitiesVerbosity"; - constexpr const char* KeyLuaDocumentation = "LuaDocumentation"; - constexpr const char* KeyPropertyDocumentation = "PropertyDocumentation"; - constexpr const char* KeyScriptLog = "ScriptLog"; - constexpr const char* KeyKeyboardShortcuts = "KeyboardShortcuts"; + constexpr const char* KeyDocumentationPath = "Path"; constexpr const char* KeyDocumentation = "Documentation"; - constexpr const char* KeyFactoryDocumentation = "FactoryDocumentation"; - constexpr const char* KeyLicenseDocumentation = "LicenseDocumentation"; + constexpr const char* KeyScriptLog = "ScriptLog"; constexpr const char* KeyShutdownCountdown = "ShutdownCountdown"; constexpr const char* KeyPerSceneCache = "PerSceneCache"; constexpr const char* KeyOnScreenTextScaling = "OnScreenTextScaling"; @@ -196,13 +192,7 @@ namespace { static_cast(value); ghoul::Dictionary d = ghoul::lua::value(L); - d.getValue(KeyLuaDocumentation, v.lua); - d.getValue(KeyPropertyDocumentation, v.property); - d.getValue("ScenePropertyDocumentation", v.sceneProperty); - d.getValue(KeyKeyboardShortcuts, v.keyboard); - d.getValue(KeyDocumentation, v.documentation); - d.getValue(KeyFactoryDocumentation, v.factory); - d.getValue(KeyLicenseDocumentation, v.license); + d.getValue(KeyDocumentationPath, v.path); } // NOLINTNEXTLINE else if constexpr (std::is_same_v) { diff --git a/src/engine/configuration_doc.inl b/src/engine/configuration_doc.inl index 184d357b8d..747fffdb87 100644 --- a/src/engine/configuration_doc.inl +++ b/src/engine/configuration_doc.inl @@ -153,61 +153,17 @@ documentation::Documentation Configuration::Documentation = { "the results from previous runs) will be silently overwritten." }, { - KeyDocumentation, + KeyDocumentationPath, new TableVerifier({ { - KeyLuaDocumentation, + KeyDocumentationPath, new StringVerifier, Optional::Yes, - "The filename that will be created on startup containing the " - "documentation of available Lua functions that can be executed in " - "scene files or per console. Any existing file will be silently " - "overwritten." - }, - { - KeyPropertyDocumentation, - new StringVerifier, - Optional::Yes, - "The file that will be created on startup containing a list of all " - "properties in the scene. Any existing file will be silently " - "overwritten." - }, - { - KeyKeyboardShortcuts, - new StringVerifier, - Optional::Yes, - "The file that will be created on startup containing the list of all " - "keyboard bindings with their respective Lua scripts. For each key, " - "it mentions which scripts will be executed in the current session." - }, - { - KeyDocumentation, - new StringVerifier, - Optional::Yes, - "The file that will be created on startup containing this " - "documentation. Any previous file in this location will be silently " - "overwritten." - }, - { - KeyFactoryDocumentation, - new StringVerifier, - Optional::Yes, - "The file that will be created on startup containing the factory " - "documentation which shows the different types of objects that can " - "be created in the current application configuration. Any previous " - "file in this location will be silently overritten." - }, - { - KeyLicenseDocumentation, - new StringVerifier, - Optional::Yes, - "The file that will be created on startup containing the scene " - "license information. Any previous file in this location will be " - "silently overwritten." + "The path where the documentation files will be stored." }, }), Optional::Yes, - "All documentations that are generated at application startup." + "Right now only contains the path where the documentation is written to." }, { KeyShutdownCountdown, diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index 7bcc3c47aa..31eede9da1 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -58,6 +58,7 @@ #include #include #include +#include #include #include #include @@ -319,6 +320,10 @@ void OpenSpaceEngine::initialize() { global::scriptEngine.initialize(); + // To be concluded + _documentationJson.clear(); + _documentationJson += "{\"documentation\":["; + writeStaticDocumentation(); _shutdown.waitTime = global::configuration.shutdownCountdown; @@ -836,24 +841,27 @@ void OpenSpaceEngine::deinitializeGL() { } void OpenSpaceEngine::writeStaticDocumentation() { - // If a LuaDocumentationFile was specified, generate it now - if (!global::configuration.documentation.lua.empty()) { - global::scriptEngine.writeDocumentation( - absPath(global::configuration.documentation.lua) - ); - } + std::string path = global::configuration.documentation.path; + if (!path.empty()) { - // If a general documentation was specified, generate it now - if (!global::configuration.documentation.documentation.empty()) { - DocEng.writeDocumentation( - absPath(global::configuration.documentation.documentation) - ); - } + DocEng.addHandlebarTemplates(global::scriptEngine.templatesToRegister()); + DocEng.addHandlebarTemplates(FactoryManager::ref().templatesToRegister()); + DocEng.addHandlebarTemplates(DocEng.templatesToRegister()); - if (!global::configuration.documentation.factory.empty()) { - FactoryManager::ref().writeDocumentation( - absPath(global::configuration.documentation.factory) - ); + _documentationJson += "{\"name\":\"Scripting\","; + _documentationJson += "\"identifier\":\"" + global::scriptEngine.jsonName(); + _documentationJson += "\",\"data\":" + global::scriptEngine.generateJson(); + _documentationJson += "},"; + + _documentationJson += "{\"name\":\"Top Level\","; + _documentationJson += "\"identifier\":\"" + DocEng.jsonName(); + _documentationJson += "\",\"data\":" + DocEng.generateJson(); + _documentationJson += "},"; + + _documentationJson += "{\"name\":\"Factory\","; + _documentationJson += "\"identifier\":\"" + FactoryManager::ref().jsonName(); + _documentationJson += "\",\"data\":" + FactoryManager::ref().generateJson(); + _documentationJson += "},"; } } @@ -913,30 +921,47 @@ void OpenSpaceEngine::loadFonts() { } void OpenSpaceEngine::writeSceneDocumentation() { - // Write keyboard documentation. - if (!global::configuration.documentation.keyboard.empty()) { - global::keybindingManager.writeDocumentation( - absPath(global::configuration.documentation.keyboard) - ); - } + // Write documentation to json files if config file supplies path for doc files to be placed. - if (!global::configuration.documentation.license.empty()) { - _scene->writeSceneLicenseDocumentation( - absPath(global::configuration.documentation.license) - ); - } + std::string path = global::configuration.documentation.path; + if (!path.empty()) { + path = absPath(path) + "/"; + _documentationJson += "{\"name\":\"Keybindings\",\"identifier\":\""; + _documentationJson += global::keybindingManager.jsonName() + "\","; + _documentationJson += "\"data\":"; + _documentationJson += global::keybindingManager.generateJson(); + _documentationJson += "},"; + _documentationJson += "{\"name\":\"Scene License Information\","; + _documentationJson += "\"identifier\":\"sceneLicense"; + _documentationJson += "\",\"data\":"; + _documentationJson += _scene->generateSceneLicenseDocumentationJson(); + _documentationJson += "},"; + _documentationJson += "{\"name\":\"Scene Properties\","; + _documentationJson += "\"identifier\":\"propertylist";// + _scene->jsonName(); + _documentationJson += "\",\"data\":" + global::rootPropertyOwner.generateJson(); + _documentationJson += "},"; + _documentationJson += "{\"name\":\"Scene Graph Information\","; + _documentationJson += "\"identifier\":\"propertylist"; + _documentationJson += "\",\"data\":" + _scene->generateJson(); + _documentationJson += "}"; - if (!global::configuration.documentation.sceneProperty.empty()) { - _scene->writeDocumentation( - absPath(global::configuration.documentation.sceneProperty) - ); - } + //add templates for the jsons we just registered + DocEng.addHandlebarTemplates(global::keybindingManager.templatesToRegister()); + //TODO this is in efficaiant, here i am just instaning the class to get + //at a member variable which is staticly defined. How do i just get that + const std::vector licenses; + SceneLicenseWriter writer(licenses); + DocEng.addHandlebarTemplates(writer.templatesToRegister()); + DocEng.addHandlebarTemplates(global::rootPropertyOwner.templatesToRegister()); - if (!global::configuration.documentation.property.empty()) { - global::rootPropertyOwner.writeDocumentation( - absPath(global::configuration.documentation.property) - ); + //the static documentation shoudl be finished already + //so now that we wrote the static and secene json files + //we should write the html file that uses them. + _documentationJson += "]}"; + + DocEng.writeDocumentationHtml(path, _documentationJson); } + //no else, if path was empty, that means that no documentation is requested } void OpenSpaceEngine::preSynchronization() { diff --git a/src/interaction/keybindingmanager.cpp b/src/interaction/keybindingmanager.cpp index 1ce8c22a23..4b02056f76 100644 --- a/src/interaction/keybindingmanager.cpp +++ b/src/interaction/keybindingmanager.cpp @@ -36,13 +36,11 @@ namespace openspace::interaction { KeybindingManager::KeybindingManager() : DocumentationGenerator( - "Documentation", - "keybindings", + "Keybindings", + "keybinding", { - { "keybindingTemplate", "${WEB}/keybindings/keybinding.hbs" }, - { "mainTemplate", "${WEB}/keybindings/main.hbs" } - }, - "${WEB}/keybindings/script.js" + { "keybindingTemplate", "${WEB}/documentation/keybinding.hbs" } + } ) {} diff --git a/src/properties/propertyowner.cpp b/src/properties/propertyowner.cpp index c2773a63e8..e6baba0187 100644 --- a/src/properties/propertyowner.cpp +++ b/src/properties/propertyowner.cpp @@ -25,6 +25,7 @@ #include #include +#include #include #include #include @@ -40,23 +41,13 @@ namespace openspace::properties { PropertyOwner::PropertyOwner(PropertyOwnerInfo info) : DocumentationGenerator( - "Documented", + "Property Owners", "propertyOwners", { - { - "mainTemplate", - "${WEB}/properties/main.hbs" - }, - { - "propertyOwnerTemplate", - "${WEB}/properties/propertyowner.hbs" - }, - { - "propertyTemplate", - "${WEB}/properties/property.hbs" - } - }, - "${WEB}/properties/script.js" + { "propertyOwnersTemplate","${WEB}/documentation/propertyowners.hbs" }, + { "propertyTemplate","${WEB}/documentation/property.hbs" }, + { "propertylistTemplate","${WEB}/documentation/propertylist.hbs" } + } ) , _identifier(std::move(info.identifier)) , _guiName(std::move(info.guiName)) @@ -412,6 +403,8 @@ std::string PropertyOwner::generateJson() const { subOwners.end(), createJson(*subOwners.begin()), [createJson](std::string a, PropertyOwner* n) { + //TODO figure out how to ignore scene when its not the root + //right now will be done on client side return a + "," + createJson(n); } ); diff --git a/src/scene/scene.cpp b/src/scene/scene.cpp index dcb5be76ee..b753be7eb8 100644 --- a/src/scene/scene.cpp +++ b/src/scene/scene.cpp @@ -550,9 +550,9 @@ const std::vector& Scene::interestingTimes() const { return _interestingTimes; } -void Scene::writeSceneLicenseDocumentation(const std::string& path) const { +std::string Scene::generateSceneLicenseDocumentationJson() { SceneLicenseWriter writer(_licenses); - writer.writeDocumentation(path); + return writer.generateJson(); } scripting::LuaLibrary Scene::luaLibrary() { diff --git a/src/scene/scenelicensewriter.cpp b/src/scene/scenelicensewriter.cpp index a9ff92d1e0..fed31fb4b6 100644 --- a/src/scene/scenelicensewriter.cpp +++ b/src/scene/scenelicensewriter.cpp @@ -28,24 +28,15 @@ #include #include -namespace { - constexpr const char* MainTemplateFilename = "${WEB}/scenelicense/main.hbs"; - constexpr const char* SceneLicenseTemplateFilename = - "${WEB}/scenelicense/scenelicense.hbs"; - constexpr const char* JsFilename = "${WEB}/scenelicense/script.js"; -} // namespace - namespace openspace { SceneLicenseWriter::SceneLicenseWriter(std::vector licenses) : DocumentationGenerator( - "Documentation", - "sceneLicenses", + "Scene Licenses", + "sceneLicense", { - { "sceneLicenseTemplate", SceneLicenseTemplateFilename }, - { "mainTemplate", MainTemplateFilename } - }, - JsFilename + { "sceneLicenseTemplate", "${WEB}/documentation/scenelicense.hbs" } + } ) , _licenses(std::move(licenses)) {} diff --git a/src/scripting/scriptengine.cpp b/src/scripting/scriptengine.cpp index 05491a37db..baf10eea25 100644 --- a/src/scripting/scriptengine.cpp +++ b/src/scripting/scriptengine.cpp @@ -49,16 +49,8 @@ ScriptEngine::ScriptEngine() "Script Documentation", "scripting", { - { - "mainTemplate", - "${WEB}/luascripting/main.hbs" - }, - { - "scriptingTemplate", - "${WEB}/luascripting/scripting.hbs" - } - }, - "${WEB}/luascripting/script.js" + { "scriptingTemplate","${WEB}/documentation/scripting.hbs" }, + } ) {} diff --git a/src/util/factorymanager.cpp b/src/util/factorymanager.cpp index 5b626c0cdb..727dcdaf0f 100644 --- a/src/util/factorymanager.cpp +++ b/src/util/factorymanager.cpp @@ -26,12 +26,6 @@ #include -namespace { - constexpr const char* MainTemplateFilename = "${WEB}/factories/main.hbs"; - constexpr const char* FactoryTemplateFilename = "${WEB}/factories/factory.hbs"; - constexpr const char* JsFilename = "${WEB}/factories/script.js"; -} // namespace - namespace openspace { FactoryManager* FactoryManager::_manager = nullptr; @@ -46,12 +40,10 @@ FactoryManager::FactoryNotFoundError::FactoryNotFoundError(std::string t) FactoryManager::FactoryManager() : DocumentationGenerator( "Factory Documentation", - "factories", + "factory", { - { "mainTemplate", MainTemplateFilename }, - { "factoryTemplate", FactoryTemplateFilename } - }, - JsFilename + { "factoryTemplate", "${WEB}/documentation/factory.hbs" } + } ) {}