Code cleanup

This commit is contained in:
Alexander Bock
2017-05-11 18:51:42 -04:00
parent 5ebf2a4913
commit b660a84464
7 changed files with 53 additions and 176 deletions

View File

@@ -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<HandlebarTemplate> handlebarTemplates,

View File

@@ -38,13 +38,11 @@
#include <fmt/format.h>
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<std::string> jsInserter(jsContent);
//
// std::copy(std::istreambuf_iterator<char>{handlebarsInput}, std::istreambuf_iterator<char>(), jsInserter);
// std::copy(std::istreambuf_iterator<char>{jsInput}, std::istreambuf_iterator<char>(), jsInserter);
//
// std::ifstream bootstrapInput(absPath(BootstrapFilename));
// std::ifstream cssInput(absPath(CssFilename));
//
// std::string cssContent;
// std::back_insert_iterator<std::string> cssInserter(cssContent);
//
// std::copy(std::istreambuf_iterator<char>{bootstrapInput}, std::istreambuf_iterator<char>(), cssInserter);
// std::copy(std::istreambuf_iterator<char>{cssInput}, std::istreambuf_iterator<char>(), cssInserter);
//
// std::ifstream mainTemplateInput(absPath(MainTemplateFilename));
// std::string mainTemplateContent{ std::istreambuf_iterator<char>{mainTemplateInput},
// std::istreambuf_iterator<char>{}};
//
// std::ifstream documentationTemplateInput(absPath(DocumentationTemplateFilename));
// std::string documentationTemplateContent{ std::istreambuf_iterator<char>{documentationTemplateInput},
// std::istreambuf_iterator<char>{} };
//
// 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 << "<!DOCTYPE html>\n"
// << "<html>\n"
// << "\t<head>\n"
// << "\t\t<script id=\"mainTemplate\" type=\"text/x-handlebars-template\">\n"
// << mainTemplateContent << "\n"
// << "\t\t</script>\n"
// << "\t\t<script id=\"documentationTemplate\" type=\"text/x-handlebars-template\">\n"
// << documentationTemplateContent << "\n"
// << "\t\t</script>\n"
// << "\t<script>\n"
// << "var documentation = JSON.parse('" << jsonString << "');\n"
// << "var version = [" << OPENSPACE_VERSION_MAJOR << ", " << OPENSPACE_VERSION_MINOR << ", " << OPENSPACE_VERSION_PATCH << "];\n"
// << jsContent << "\n"
// << "\t</script>\n"
// << "\t<style type=\"text/css\">\n"
// << cssContent << "\n"
// << "\t</style>\n"
// << "\t\t<title>Documentation</title>\n"
// << "\t</head>\n"
// << "\t<body>\n"
// << "\t<body>\n"
// << "</html>\n";
//
// file << html.str();
//
///*
// Use this for generating documentation in raw html:
//
// html << "<table>\n"
// << "\t<caption>Documentation</caption>\n\n"
// << "\t<thead>\n"
// << "\t\t<tr>\n"
// << "\t\t\t<th rowspan=2>Name</th>\n"
// << "\t\t</tr>\n"
// << "\t\t<tr>\n"
// << "\t\t\t<th>Key</th>\n"
// << "\t\t\t<th>Optional</th>\n"
// << "\t\t\t<th>Type</th>\n"
// << "\t\t\t<th>Restrictions</th>\n"
// << "\t\t\t<th>Documentation</th>\n"
// << "\t\t</tr>\n"
// << "\t</thead>\n"
// << "\t<tbody>\n";
//
// for (const Documentation& d : _documentations) {
// html << generateHtmlDocumentation(d);
//
// html << "\t<tr><td style=\"line-height: 50px;\" colspan=6></br></td></tr>\n";
// }
//
// html << "\t</tbody>\n"
// << "</table>\n";
//*/
// }
//}
void DocumentationEngine::addDocumentation(Documentation doc) {
for (const DocumentationEntry& e : doc.entries) {
ghoul_assert(

View File

@@ -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<std::string> jsInserter(jsContent);
std::copy(std::istreambuf_iterator<char>{handlebarsInput}, std::istreambuf_iterator<char>(), jsInserter);
std::copy(std::istreambuf_iterator<char>{jsInput}, std::istreambuf_iterator<char>(), 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<char>(handlebarsInput),
std::istreambuf_iterator<char>()
);
std::string cssContent;
std::back_insert_iterator<std::string> cssInserter(cssContent);
std::copy(std::istreambuf_iterator<char>{bootstrapInput}, std::istreambuf_iterator<char>(), cssInserter);
std::copy(std::istreambuf_iterator<char>{cssInput}, std::istreambuf_iterator<char>(), cssInserter);
std::ifstream jsInput;
jsInput.exceptions(~std::ofstream::goodbit);
jsInput.open(absPath(_javascriptFile));
const std::string jsContent = std::string(
std::istreambuf_iterator<char>(jsInput),
std::istreambuf_iterator<char>()
);
std::ifstream bootstrapInput;
bootstrapInput.exceptions(~std::ofstream::goodbit);
bootstrapInput.open(absPath(BootstrapFilename));
const std::string bootstrapContent = std::string(
std::istreambuf_iterator<char>(bootstrapInput),
std::istreambuf_iterator<char>()
);
std::ifstream cssInput;
cssInput.exceptions(~std::ofstream::goodbit);
cssInput.open(absPath(CssFilename));
const std::string cssContent = std::string(
std::istreambuf_iterator<char>(cssInput),
std::istreambuf_iterator<char>()
);
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" << "</script>" << '\n'
<< "\t" << "<style type=\"text/css\">" << '\n'
<< "\t\t" << cssContent << '\n'
<< "\t\t" << bootstrapContent << '\n'
<< "\t" << "</style>" << '\n'
<< "\t\t" << "<title>" << _name << "</title>" << '\n'
<< "\t" << "</head>" << '\n'

View File

@@ -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"

View File

@@ -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 {

View File

@@ -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";

View File

@@ -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 {