/***************************************************************************************** * * * OpenSpace * * * * Copyright (c) 2014-2025 * * * * Permission is hereby granted, free of charge, to any person obtaining a copy of this * * software and associated documentation files (the "Software"), to deal in the Software * * without restriction, including without limitation the rights to use, copy, modify, * * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * * permit persons to whom the Software is furnished to do so, subject to the following * * conditions: * * * * The above copyright notice and this permission notice shall be included in all copies * * or substantial portions of the Software. * * * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace { constexpr std::string_view MainTemplateFilename = "${WEB}/kameleondocumentation/main.hbs"; constexpr std::string_view HandlebarsFilename = "${WEB}/common/handlebars-v4.0.5.js"; constexpr std::string_view JsFilename = "${WEB}/kameleondocumentation/script.js"; constexpr std::string_view BootstrapFilename = "${WEB}/common/bootstrap.min.css"; constexpr std::string_view CssFilename = "${WEB}/common/style.css"; struct [[codegen::Dictionary(KameleonDocumentationTask)]] Parameters { // The CDF file to extract data from std::filesystem::path input; // The HTML file to write documentation to std::string output [[codegen::annotation("A valid filepath")]]; }; #include "kameleondocumentationtask_codegen.cpp" } // namespace namespace openspace::kameleonvolume { documentation::Documentation KameleonDocumentationTask::documentation() { return codegen::doc("kameleon_documentation_task"); } KameleonDocumentationTask::KameleonDocumentationTask(const ghoul::Dictionary& dictionary) { const Parameters p = codegen::bake(dictionary); _inputPath = absPath(p.input); _outputPath = absPath(p.output); } std::string KameleonDocumentationTask::description() { return std::format( "Extract metadata from CDF file '{}' and output HTML documentation to '{}'", _inputPath, _outputPath ); } void KameleonDocumentationTask::perform(const Task::ProgressCallback & progressCallback) { KameleonVolumeReader reader = KameleonVolumeReader(_inputPath.string()); ghoul::Dictionary kameleonDictionary = reader.readMetaData(); progressCallback(0.33f); ghoul::Dictionary dictionary; dictionary.setValue("kameleon", std::move(kameleonDictionary)); dictionary.setValue("version", std::string(OPENSPACE_VERSION)); dictionary.setValue("input", _inputPath.string()); std::string json = ghoul::formatJson(dictionary); progressCallback(0.66f); 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::ofstream file; file.exceptions(~std::ofstream::goodbit); file.open(_outputPath); 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(); progressCallback(1.f); } } // namespace openspace::kameleonvolume