api_python.php 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. /*
  3. * plugins/api_python.php
  4. *
  5. * Copyright (C) 2022 bzt (bztsrc@gitlab)
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. *
  21. * @brief Look for doctype API specification strings in Python sources
  22. *
  23. */
  24. function gendoc_api_python($str)
  25. {
  26. /* match comments before methods that look like:
  27. *
  28. * ##
  29. * # descripton
  30. * # more description
  31. * # @param parameter definition
  32. * # @return return value definition
  33. * def somemethod():
  34. */
  35. if(preg_match_all("/##[^#](.*?)def(.*?)$/ims", $str, $M, PREG_SET_ORDER)) {
  36. foreach($M as $m) {
  37. /* format the matches */
  38. gendoc::data_list_open();
  39. gendoc::data_topic_open();
  40. gendoc::source_code(trim($m[2]), "python");
  41. gendoc::data_topic_close();
  42. gendoc::data_description_open();
  43. $t = 0;
  44. foreach(explode("\n", $m[1]) as $dsc) {
  45. $dsc = htmlspecialchars(trim(preg_replace("/^[\ \t]*#[\ \t]*/", "", $dsc)));
  46. if(!empty($dsc)) {
  47. if(substr($dsc, 0, 7) == "@param ") {
  48. if(!$t) {
  49. $t = 1;
  50. gendoc::table_open();
  51. gendoc::table_row_open();
  52. gendoc::table_header_open();
  53. gendoc::text(gendoc::$lang["args"]);
  54. gendoc::table_header_close();
  55. gendoc::table_row_close();
  56. }
  57. gendoc::table_row_open();
  58. gendoc::table_cell_open();
  59. gendoc::text(trim(substr($dsc, 7)));
  60. gendoc::table_cell_close();
  61. gendoc::table_row_close();
  62. } else
  63. if(substr($dsc, 0, 8) == "@return ") {
  64. if(!$t) {
  65. $t = 1;
  66. gendoc::table_open();
  67. }
  68. gendoc::table_row_open();
  69. gendoc::table_header_open();
  70. gendoc::text(gendoc::$lang["rval"]);
  71. gendoc::table_header_close();
  72. gendoc::table_row_close();
  73. gendoc::table_row_open();
  74. gendoc::table_cell_open();
  75. gendoc::text(trim(substr($dsc, 8)));
  76. gendoc::table_cell_close();
  77. gendoc::table_row_close();
  78. } else
  79. gendoc::text($dsc." ");
  80. }
  81. }
  82. if($t)
  83. gendoc::table_close();
  84. gendoc::data_description_close();
  85. gendoc::data_list_close();
  86. gendoc::line_break();
  87. }
  88. }
  89. }