writer.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. // SuperTux - Scripting reference generator
  2. // Copyright (C) 2023 Vankata453
  3. //
  4. // This program is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. #include "writer.hpp"
  17. #include <sstream>
  18. #include "util.hpp"
  19. namespace Writer {
  20. std::string write_file_notice(const std::string& template_file)
  21. {
  22. std::stringstream notice;
  23. notice << "> Note: This file is auto-generated from the [SuperTux scripting interface source code](https://github.com/SuperTux/supertux/tree/master/src/scripting), "
  24. << "using the template [" << template_file << "](https://github.com/SuperTux/wiki/tree/master/templates/" << template_file << ")."
  25. << std::endl << std::endl;
  26. return notice.str();
  27. }
  28. std::string write_constants_table(const std::vector<Constant>& constants)
  29. {
  30. if (constants.empty()) return "";
  31. std::stringstream table;
  32. // Table beginning
  33. table << "Constant | Explanation" << std::endl;
  34. table << "---------|---------" << std::endl;
  35. // Table contents (constants)
  36. for (const Constant& con : constants)
  37. {
  38. // Print out type, name and description
  39. table << "`" << con.type << " " << con.name << "` | " << con.description << std::endl;
  40. }
  41. return table.str();
  42. }
  43. std::string write_function_table(const std::vector<Function>& functions)
  44. {
  45. if (functions.empty()) return "";
  46. std::stringstream table;
  47. // Table beginning
  48. table << "Method | Explanation" << std::endl;
  49. table << "-------|-------" << std::endl;
  50. // Table contents (functions)
  51. for (const Function& func : functions)
  52. {
  53. // Print out function
  54. table << "`" << func.name << "(";
  55. for (size_t i = 0; i < func.parameters.size(); i++)
  56. {
  57. if (i != 0) table << ", ";
  58. table << func.parameters[i].type << " " << func.parameters[i].name;
  59. }
  60. table << ")`";
  61. // Print out description of function
  62. table << " | " << func.description;
  63. // Print out descriptions of parameters
  64. bool has_printed_param_desc = false;
  65. for (const Parameter& param : func.parameters)
  66. {
  67. if (param.description.empty()) continue;
  68. table << (has_printed_param_desc ? "" : "<br />") << "<br /> `" << param.name << "` - " << param.description;
  69. has_printed_param_desc = true;
  70. }
  71. // End table entry
  72. table << std::endl;
  73. }
  74. return table.str();
  75. }
  76. std::string write_class_list(const std::vector<Class>& classes)
  77. {
  78. std::stringstream list;
  79. // For each class name, create an list entry
  80. for (const Class& cl : classes)
  81. {
  82. list << "* " << write_class_ref(cl.name) << std::endl;
  83. }
  84. return list.str();
  85. }
  86. std::string write_class_ref(const std::string& name)
  87. {
  88. return "[" + name + "](https://github.com/SuperTux/supertux/wiki/Scripting" + name + ")";
  89. }
  90. } // namespace Writer