| 95 | } |
| 96 | |
| 97 | void Generator::generate(llvm::StringRef outputPrefix, std::string dataPath, const std::string &filename, |
| 98 | const char* begin, const char* end, llvm::StringRef footer, llvm::StringRef warningMessage, |
| 99 | const std::set<std::string> &interestingDefinitions) |
| 100 | { |
| 101 | std::string real_filename = outputPrefix % "/" % filename % ".html"; |
| 102 | // Make sure the parent directory exist: |
| 103 | create_directories(llvm::StringRef(real_filename).rsplit('/').first); |
| 104 | |
| 105 | #if CLANG_VERSION_MAJOR==3 && CLANG_VERSION_MINOR<=5 |
| 106 | std::string error; |
| 107 | llvm::raw_fd_ostream myfile(real_filename.c_str(), error, llvm::sys::fs::F_None); |
| 108 | if (!error.empty()) { |
| 109 | std::cerr << "Error generating " << real_filename << " "; |
| 110 | std::cerr << error<< std::endl; |
| 111 | return; |
| 112 | } |
| 113 | #else |
| 114 | std::error_code error_code; |
| 115 | llvm::raw_fd_ostream myfile(real_filename, error_code, llvm::sys::fs::F_None); |
| 116 | if (error_code) { |
| 117 | std::cerr << "Error generating " << real_filename << " "; |
| 118 | std::cerr << error_code.message() << std::endl; |
| 119 | return; |
| 120 | } |
| 121 | #endif |
| 122 | |
| 123 | int count = std::count(filename.begin(), filename.end(), '/'); |
| 124 | std::string root_path = ".."; |
| 125 | for (int i = 0; i < count - 1; i++) { |
| 126 | root_path += "/.."; |
| 127 | } |
| 128 | |
| 129 | if (dataPath.size() && dataPath[0] == '.') |
| 130 | dataPath = root_path % "/" % dataPath; |
| 131 | |
| 132 | myfile << "<!doctype html>\n" // Use HTML 5 doctype |
| 133 | "<html>\n<head>\n"; |
| 134 | myfile << "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">"; |
| 135 | myfile << "<title>" << llvm::StringRef(filename).rsplit('/').second.str() << " source code [" << filename << "] - Woboq Code Browser</title>\n"; |
| 136 | if (interestingDefinitions.size() > 0) { |
| 137 | std::string interestingDefitionsStr = llvm::join(interestingDefinitions.begin(), interestingDefinitions.end(), ","); |
| 138 | myfile << "<meta name=\"woboq:interestingDefinitions\" content=\"" << interestingDefitionsStr << " \"/>\n"; |
| 139 | } |
| 140 | myfile << "<link rel=\"stylesheet\" href=\"" << dataPath << "/qtcreator.css\" title=\"QtCreator\"/>\n"; |
| 141 | myfile << "<link rel=\"alternate stylesheet\" href=\"" << dataPath << "/kdevelop.css\" title=\"KDevelop\"/>\n"; |
| 142 | myfile << "<script type=\"text/javascript\" src=\"" << dataPath << "/jquery/jquery.min.js\"></script>\n"; |
| 143 | myfile << "<script type=\"text/javascript\" src=\"" << dataPath << "/jquery/jquery-ui.min.js\"></script>\n"; |
| 144 | myfile << "<script>var file = '"<< filename <<"'; var root_path = '"<< root_path <<"'; var data_path = '"<< dataPath <<"';"; |
| 145 | if (!projects.empty()) { |
| 146 | myfile << "var projects = {"; |
| 147 | bool first = true; |
| 148 | for (auto it: projects) { |
| 149 | if (!first) myfile << ", "; |
| 150 | first = false; |
| 151 | myfile << "\"" << it.first << "\" : \"" << it.second << "\""; |
| 152 | } |
| 153 | myfile << "};"; |
| 154 | } |
no test coverage detected