diff --git a/include/openspace/documentation/documentationgenerator.h b/include/openspace/documentation/documentationgenerator.h index 4b3b5f4d2d..ca91bc9eff 100644 --- a/include/openspace/documentation/documentationgenerator.h +++ b/include/openspace/documentation/documentationgenerator.h @@ -63,8 +63,8 @@ public: * documentation and that can contain additional functionality * \pre name must not be empty * \pre jsonName must not be empty - * \pre Each handlebarTemplates' \c name must not be empty and \c filename must exist - * \pre javascriptFilename must not be empty must exist + * \pre Each handlebarTemplates' \c name must not be empty + * \pre javascriptFilename must not be empty */ DocumentationGenerator(std::string name, std::string jsonName, std::vector handlebarTemplates, diff --git a/src/documentation/documentationengine.cpp b/src/documentation/documentationengine.cpp index 73aebdf0e7..92f48e26ae 100644 --- a/src/documentation/documentationengine.cpp +++ b/src/documentation/documentationengine.cpp @@ -38,13 +38,11 @@ #include namespace { - const std::string MainTemplateFilename = "${OPENSPACE_DATA}/web/documentation/main.hbs"; - const std::string DocumentationTemplateFilename = "${OPENSPACE_DATA}/web/documentation/documentation.hbs"; - const std::string HandlebarsFilename = "${OPENSPACE_DATA}/web/common/handlebars-v4.0.5.js"; - const std::string JsFilename = "${OPENSPACE_DATA}/web/documentation/script.js"; - const std::string BootstrapFilename = "${OPENSPACE_DATA}/web/common/bootstrap.min.css"; - const std::string CssFilename = "${OPENSPACE_DATA}/web/common/style.css"; -} + const char* MainTemplateFilename = "${OPENSPACE_DATA}/web/documentation/main.hbs"; + const char* DocumentationTemplateFilename = + "${OPENSPACE_DATA}/web/documentation/documentation.hbs"; + const char* JsFilename = "${OPENSPACE_DATA}/web/documentation/script.js"; +} // namespace namespace openspace { namespace documentation { @@ -126,7 +124,10 @@ std::string generateTextDocumentation(const Documentation& d, int& indentLevel) } else if (tv) { // We have a TableVerifier, so we need to recurse ++indentLevel; - result += generateTextDocumentation({ "", "", tv->documentations }, indentLevel); + result += generateTextDocumentation( + { "", "", tv->documentations }, + indentLevel + ); result = result.substr(0, result.size() - 2); --indentLevel; } @@ -295,126 +296,6 @@ std::string DocumentationEngine::generateJson() const { return jsonString; } -//void DocumentationEngine::writeDocumentation(const std::string& f, const std::string& t) { -// if (t == "text") { -// std::ofstream file; -// file.exceptions(~std::ofstream::goodbit); -// file.open(f); -// -// for (const Documentation& d : _documentations) { -// int indent = 0; -// file << documentation::generateTextDocumentation(d, indent) << "\n\n"; -// } -// } -// else if (t == "html") { -// std::ifstream handlebarsInput(absPath(HandlebarsFilename)); -// std::ifstream jsInput(absPath(JsFilename)); -// -// std::string jsContent; -// std::back_insert_iterator jsInserter(jsContent); -// -// std::copy(std::istreambuf_iterator{handlebarsInput}, std::istreambuf_iterator(), jsInserter); -// std::copy(std::istreambuf_iterator{jsInput}, std::istreambuf_iterator(), jsInserter); -// -// std::ifstream bootstrapInput(absPath(BootstrapFilename)); -// std::ifstream cssInput(absPath(CssFilename)); -// -// std::string cssContent; -// std::back_insert_iterator cssInserter(cssContent); -// -// std::copy(std::istreambuf_iterator{bootstrapInput}, std::istreambuf_iterator(), cssInserter); -// std::copy(std::istreambuf_iterator{cssInput}, std::istreambuf_iterator(), cssInserter); -// -// std::ifstream mainTemplateInput(absPath(MainTemplateFilename)); -// std::string mainTemplateContent{ std::istreambuf_iterator{mainTemplateInput}, -// std::istreambuf_iterator{}}; -// -// std::ifstream documentationTemplateInput(absPath(DocumentationTemplateFilename)); -// std::string documentationTemplateContent{ std::istreambuf_iterator{documentationTemplateInput}, -// std::istreambuf_iterator{} }; -// -// std::ofstream file; -// file.exceptions(~std::ofstream::goodbit); -// file.open(f); -// -// std::stringstream json; -// json << "["; -// -// for (const Documentation& d : _documentations) { -// json << generateJsonDocumentation(d); -// if (&d != &_documentations.back()) { -// json << ", "; -// } -// } -// -// json << "]"; -// -// std::string jsonString = ""; -// for (const char& c : json.str()) { -// if (c == '\'') { -// jsonString += "\\'"; -// } else { -// jsonString += c; -// } -// } -// -// std::stringstream html; -// html << "\n" -// << "\n" -// << "\t\n" -// << "\t\t\n" -// << "\t\t\n" -// << "\t\n" -// << "\t\n" -// << "\t\tDocumentation\n" -// << "\t\n" -// << "\t\n" -// << "\t\n" -// << "\n"; -// -// file << html.str(); -// -///* -// Use this for generating documentation in raw html: -// -// html << "\n" -// << "\t\n\n" -// << "\t\n" -// << "\t\t\n" -// << "\t\t\t\n" -// << "\t\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\n" -// << "\t\n" -// << "\t\n"; -// -// for (const Documentation& d : _documentations) { -// html << generateHtmlDocumentation(d); -// -// html << "\t\n"; -// } -// -// html << "\t\n" -// << "
Documentation
Name
KeyOptionalTypeRestrictionsDocumentation

\n"; -//*/ -// } -//} - void DocumentationEngine::addDocumentation(Documentation doc) { for (const DocumentationEntry& e : doc.entries) { ghoul_assert( diff --git a/src/documentation/documentationgenerator.cpp b/src/documentation/documentationgenerator.cpp index 697a70c8a2..ac27f90b67 100644 --- a/src/documentation/documentationgenerator.cpp +++ b/src/documentation/documentationgenerator.cpp @@ -54,33 +54,42 @@ DocumentationGenerator::DocumentationGenerator(std::string name, for (const HandlebarTemplate& t : _handlebarTemplates) { ghoul_precondition(!t.name.empty(), "name must not be empty"); ghoul_precondition(!t.filename.empty(), "filename must not be empty"); - ghoul_precondition(FileSys.fileExists(t.filename), "filename must exist"); } ghoul_precondition(!_javascriptFile.empty(), "javascriptFilename must not be empty"); - ghoul_precondition( - FileSys.fileExists(_javascriptFile), - "javascriptFilename must exist" - ); } void DocumentationGenerator::writeDocumentation(const std::string& filename) { - std::ifstream handlebarsInput(absPath(HandlebarsFilename)); - std::ifstream jsInput(absPath(_javascriptFile)); - - std::string jsContent; - std::back_insert_iterator jsInserter(jsContent); - - std::copy(std::istreambuf_iterator{handlebarsInput}, std::istreambuf_iterator(), jsInserter); - std::copy(std::istreambuf_iterator{jsInput}, std::istreambuf_iterator(), jsInserter); - - std::ifstream bootstrapInput(absPath(BootstrapFilename)); - std::ifstream cssInput(absPath(CssFilename)); + 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::string cssContent; - std::back_insert_iterator cssInserter(cssContent); - - std::copy(std::istreambuf_iterator{bootstrapInput}, std::istreambuf_iterator(), cssInserter); - std::copy(std::istreambuf_iterator{cssInput}, std::istreambuf_iterator(), cssInserter); + 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); @@ -126,10 +135,12 @@ void DocumentationGenerator::writeDocumentation(const std::string& filename) { << "\t\t" << "var " << _jsonName << " = JSON.parse('" << json << "');" << '\n' << "\t\t" << "var version = " << Version << ";" << '\n' << "\t\t" << "var generationTime = '" << generationTime << "';" << '\n' + << "\t\t" << handlebarsContent << '\n' << "\t\t" << jsContent << '\n' << "\t" << "" << '\n' << "\t" << "" << '\n' << "\t\t" << "" << _name << "" << '\n' << "\t" << "" << '\n' diff --git a/src/interaction/interactionhandler.cpp b/src/interaction/interactionhandler.cpp index f10f7238de..82d8311d1a 100644 --- a/src/interaction/interactionhandler.cpp +++ b/src/interaction/interactionhandler.cpp @@ -59,10 +59,7 @@ namespace { const char* MainTemplateFilename = "${OPENSPACE_DATA}/web/keybindings/main.hbs"; const char* KeybindingTemplateFilename = "${OPENSPACE_DATA}/web/keybindings/keybinding.hbs"; -// const char* HandlebarsFilename = "${OPENSPACE_DATA}/web/common/handlebars-v4.0.5.js"; const char* JsFilename = "${OPENSPACE_DATA}/web/keybindings/script.js"; -// const char* BootstrapFilename = "${OPENSPACE_DATA}/web/common/bootstrap.min.css"; -// const char* CssFilename = "${OPENSPACE_DATA}/web/common/style.css"; } // namespace #include "interactionhandler_lua.inl" diff --git a/src/scene/scene.cpp b/src/scene/scene.cpp index 11ac7c2048..178d691708 100644 --- a/src/scene/scene.cpp +++ b/src/scene/scene.cpp @@ -74,10 +74,7 @@ namespace { const char* MainTemplateFilename = "${OPENSPACE_DATA}/web/properties/main.hbs"; const char* PropertyOwnerTemplateFilename = "${OPENSPACE_DATA}/web/properties/propertyowner.hbs"; const char* PropertyTemplateFilename = "${OPENSPACE_DATA}/web/properties/property.hbs"; - const char* HandlebarsFilename = "${OPENSPACE_DATA}/web/common/handlebars-v4.0.5.js"; const char* JsFilename = "${OPENSPACE_DATA}/web/properties/script.js"; - const char* BootstrapFilename = "${OPENSPACE_DATA}/web/common/bootstrap.min.css"; - const char* CssFilename = "${OPENSPACE_DATA}/web/common/style.css"; } // namespace namespace openspace { diff --git a/src/scripting/scriptengine.cpp b/src/scripting/scriptengine.cpp index 84a6b44fb1..69a677ad26 100644 --- a/src/scripting/scriptengine.cpp +++ b/src/scripting/scriptengine.cpp @@ -40,28 +40,22 @@ #include "scriptengine_lua.inl" -namespace { - const char* MainTemplateFilename = "${OPENSPACE_DATA}/web/luascripting/main.hbs"; - const char* ScriptingTemplateFilename = "${OPENSPACE_DATA}/web/luascripting/scripting.hbs"; - const char* HandlebarsFilename = "${OPENSPACE_DATA}/web/common/handlebars-v4.0.5.js"; - const char* JsFilename = "${OPENSPACE_DATA}/web/luascripting/script.js"; - const char* BootstrapFilename = "${OPENSPACE_DATA}/web/common/bootstrap.min.css"; - const char* CssFilename = "${OPENSPACE_DATA}/web/common/style.css"; -} - -namespace openspace { - -namespace scripting { - namespace { const std::string _loggerCat = "ScriptEngine"; - + const char* LuaGlobalNamespace = "_G"; const char* PrintFunctionName = "print"; //const lua_CFunction _printFunctionReplacement = luascriptfunctions::printInfo; - + const int TableOffset = -3; // -1 (top) -1 (first argument) -1 (second argument) -} + + const char* MainTemplateFilename = "${OPENSPACE_DATA}/web/luascripting/main.hbs"; + const char* ScriptingTemplateFilename = "${OPENSPACE_DATA}/web/luascripting/scripting.hbs"; + const char* JsFilename = "${OPENSPACE_DATA}/web/luascripting/script.js"; +} // namespace + +namespace openspace { +namespace scripting { std::string ScriptEngine::OpenSpaceLibraryName = "openspace"; diff --git a/src/util/factorymanager.cpp b/src/util/factorymanager.cpp index 6582d82f1a..118b43ac35 100644 --- a/src/util/factorymanager.cpp +++ b/src/util/factorymanager.cpp @@ -35,10 +35,7 @@ namespace { const char* MainTemplateFilename = "${OPENSPACE_DATA}/web/factories/main.hbs"; const char* FactoryTemplateFilename = "${OPENSPACE_DATA}/web/factories/factory.hbs"; - const char* HandlebarsFilename = "${OPENSPACE_DATA}/web/common/handlebars-v4.0.5.js"; const char* JsFilename = "${OPENSPACE_DATA}/web/factories/script.js"; - const char* BootstrapFilename = "${OPENSPACE_DATA}/web/common/bootstrap.min.css"; - const char* CssFilename = "${OPENSPACE_DATA}/web/common/style.css"; } // namespace namespace openspace {