module.html.jinja2 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. {% extends "frame.html.jinja2" %}
  2. {% block title %}{{ module.modulename }} API documentation{% endblock %}
  3. {% block nav %}
  4. {% block module_list_link %}
  5. {% set parentmodule = ".".join(module.modulename.split(".")[:-1]) %}
  6. {% if parentmodule and parentmodule in all_modules %}
  7. <a class="pdoc-button module-list-button" href="../{{ parentmodule.split(".")[-1] }}.html">
  8. {% include "resources/box-arrow-in-left.svg" %}
  9. &nbsp;
  10. {{- parentmodule -}}
  11. </a>
  12. {% elif not root_module_name %}
  13. <a class="pdoc-button module-list-button" href="{{ "../" * module.modulename.count(".") }}index.html">
  14. {% include "resources/box-arrow-in-left.svg" %}
  15. &nbsp;
  16. Module Index
  17. </a>
  18. {% endif %}
  19. {% endblock %}
  20. {% block nav_title %}
  21. {% if logo %}
  22. {% if logo_link %}<a href="{{ logo_link }}">{% endif %}
  23. <img src="{{ logo }}" class="logo" alt="project logo"/>
  24. {% if logo_link %}</a>{% endif %}
  25. {% endif %}
  26. {% endblock %}
  27. {% if module.members %}
  28. <h2>API Documentation</h2>
  29. {% endif %}
  30. {% block search_box %}
  31. {% if search and all_modules|length > 1 %}
  32. {# we set a pattern here so that we can use the :valid CSS selector #}
  33. <input type="search" placeholder="Search..." role="searchbox" aria-label="search"
  34. pattern=".+" required>
  35. {% endif %}
  36. <br>
  37. {% endblock %}
  38. {% set index = module.docstring | to_markdown | to_html | attr("toc_html") %}
  39. {% if index %}
  40. <h2>Contents</h2>
  41. {{ index | safe }}
  42. {% endif %}
  43. {% if module.submodules %}
  44. <h2>Submodules</h2>
  45. <ul>
  46. {% for submodule in module.submodules if is_public(submodule) | trim %}
  47. {% if "cmaps" not in submodule.name and "vtkclasses" not in submodule.name and "cli" not in submodule.name %}
  48. {% if "version" not in submodule.name and "backends" not in submodule.name %}
  49. <li>{{ submodule.taken_from | link(text=submodule.name) }}</li>
  50. {% endif %}
  51. {% endif %}
  52. {% endfor %}
  53. </ul>
  54. {% endif %}
  55. {% if module.members %}
  56. <br>
  57. {{ nav_members(module.members.values()) }}
  58. {% endif %}
  59. {% block nav_footer %}
  60. {% if footer_text %}
  61. <footer>{{ footer_text }}</footer>
  62. {% endif %}
  63. {% endblock %}
  64. {% block attribution %}
  65. <a class="attribution" title="pdoc: Python API documentation generator" href="https://pdoc.dev" target="_blank">
  66. built with <span class="visually-hidden">pdoc</span><img
  67. alt="pdoc logo"
  68. src="data:image/svg+xml,
  69. {%- filter urlencode %}{% include "resources/pdoc-logo.svg" %}{% endfilter %}"/>
  70. </a>
  71. {% endblock %}
  72. {% endblock nav %}
  73. {% block content %}
  74. <main class="pdoc">
  75. {% block module_info %}
  76. <section class="module-info">
  77. {% block edit_button %}
  78. {% if edit_url %}
  79. {% if "github.com" in edit_url %}
  80. {% set edit_text = "Edit on GitHub" %}
  81. {% elif "gitlab" in edit_url %}
  82. {% set edit_text = "Edit on GitLab" %}
  83. {% else %}
  84. {% set edit_text = "Edit Source" %}
  85. {% endif %}
  86. <a class="pdoc-button git-button" href="{{ edit_url }}">{{ edit_text }}</a>
  87. {% endif %}
  88. {% endblock %}
  89. {{ module_name() }}
  90. {{ docstring(module) }}
  91. {{ view_source_state(module) }}
  92. {{ view_source_button(module) }}
  93. {{ view_source_code(module) }}
  94. </section>
  95. {% endblock %}
  96. {% block module_contents %}
  97. {% for m in module.flattened_own_members if is_public(m) | trim %}
  98. <section id="{{ m.qualname or m.name }}">
  99. {{ member(m) }}
  100. {% if m.kind == "class" %}
  101. {% for m in m.own_members if m.kind != "class" and is_public(m) | trim %}
  102. <div id="{{ m.qualname }}" class="classattr">
  103. {{ member(m) }}
  104. </div>
  105. {% endfor %}
  106. {% if "shapes" not in module_name() %}
  107. {% set inherited_members = inherited(m) | trim %}
  108. {% if inherited_members %}
  109. <div class="inherited">
  110. <h5>Inherited Members</h5>
  111. <dl>
  112. {{ inherited_members }}
  113. </dl>
  114. </div>
  115. {% endif %}
  116. {% endif %}
  117. {% endif %}
  118. </section>
  119. {% endfor %}
  120. {% endblock %}
  121. </main>
  122. {% if mtime %}
  123. {% include "livereload.html.jinja2" %}
  124. {% endif %}
  125. {% block search_js %}
  126. {% if search and all_modules|length > 1 %}
  127. {% include "search.html.jinja2" %}
  128. {% endif %}
  129. {% endblock %}
  130. {% endblock content %}
  131. {#
  132. End of content, beginning of helper macros.
  133. See https://pdoc.dev/docs/pdoc/render_helpers.html#DefaultMacroExtension for an explanation of defaultmacro.
  134. #}
  135. {% defaultmacro bases(cls) %}
  136. {%- if cls.bases -%}
  137. <wbr>(
  138. {%- for base in cls.bases -%}
  139. <span class="base">{{ base[:2] | link(text=base[2]) }}</span>
  140. {%- if loop.nextitem %}, {% endif %}
  141. {%- endfor -%}
  142. )
  143. {%- endif -%}
  144. {% enddefaultmacro %}
  145. {% defaultmacro default_value(var) -%}
  146. {%- if var.default_value_str -%}
  147. <span class="default_value">{{ var.default_value_str | escape | linkify }}</span>
  148. {%- endif -%}
  149. {% enddefaultmacro %}
  150. {% defaultmacro annotation(var) %}
  151. {%- if var.annotation_str -%}
  152. <span class="annotation">{{ var.annotation_str | escape | linkify }}</span>
  153. {%- endif -%}
  154. {% enddefaultmacro %}
  155. {% defaultmacro decorators(doc) %}
  156. {% for d in doc.decorators if not d.startswith("@_") %}
  157. <div class="decorator">{{ d }}</div>
  158. {% endfor %}
  159. {% enddefaultmacro %}
  160. {% defaultmacro function(fn) -%}
  161. {{ decorators(fn) }}
  162. {% if fn.name == "__init__" %}
  163. <span class="name">{{ ".".join(fn.qualname.split(".")[:-1]) }}</span>
  164. {{- fn.signature_without_self | format_signature(colon=False) | linkify }}
  165. {% else %}
  166. <span class="def">{{ fn.funcdef }}</span>
  167. <span class="name">{{ fn.name }}</span>
  168. {{- fn.signature | format_signature(colon=True) | linkify }}
  169. {% endif %}
  170. {% enddefaultmacro %}
  171. {% defaultmacro variable(var) -%}
  172. <span class="name">{{ var.name }}</span>{{ annotation(var) }}{{ default_value(var) }}
  173. {% enddefaultmacro %}
  174. {% defaultmacro submodule(mod) -%}
  175. <span class="name">{{ mod.taken_from | link }}</span>
  176. {% enddefaultmacro %}
  177. {% defaultmacro class(cls) -%}
  178. {{ decorators(cls) }}
  179. <span class="def">class</span>
  180. <span class="name">{{ cls.qualname }}</span>
  181. {{- bases(cls) -}}:
  182. {% enddefaultmacro %}
  183. {% defaultmacro member(doc) %}
  184. {{- view_source_state(doc) -}}
  185. <div class="attr {{ doc.kind }}">
  186. {% if doc.kind == "class" %}
  187. {{ class(doc) }}
  188. {% elif doc.kind == "function" %}
  189. {{ function(doc) }}
  190. {% elif doc.kind == "module" %}
  191. {{ submodule(doc) }}
  192. {% else %}
  193. {{ variable(doc) }}
  194. {% endif %}
  195. {{ view_source_button(doc) }}
  196. </div>
  197. <a class="headerlink" href="#{{ doc.qualname or doc.name }}"></a>
  198. {{ view_source_code(doc) }}
  199. {{ docstring(doc) }}
  200. {% enddefaultmacro %}
  201. {% defaultmacro docstring(var) %}
  202. {% if var.docstring %}
  203. <div class="docstring">{{ var.docstring | to_markdown | to_html | linkify(namespace=var.qualname) }}</div>
  204. {% endif %}
  205. {% enddefaultmacro %}
  206. {% defaultmacro nav_members(members) %}
  207. <ul class="memberlist">
  208. {#% for m in members if is_public(m) | trim %#}
  209. {% for m in members|sort(attribute='qualname') if is_public(m) | trim %}
  210. <li>
  211. {% if m.kind == "class" %}
  212. {% if m.own_members and "shapes" not in module_name() %}
  213. <hr>
  214. {% endif %}
  215. <a class="class" href="#{{ m.qualname }}">{{ m.qualname }}</a>
  216. {% if m.own_members %}
  217. {{ nav_members(m.own_members) | indent(12) }}
  218. {% endif %}
  219. {% if m.own_members and "shapes" not in module_name() %}
  220. <br>
  221. {% endif %}
  222. {% elif m.kind == "module" %}
  223. <a class="module" href="#{{ m.name }}">{{ m.name }}</a>
  224. {% elif m.name == "__init__" %}
  225. {% else %}
  226. {% if m.name.lower() == m.name %}
  227. <a class="module" href="#{{ m.qualname }}">{{ m.name }}</a>
  228. {% endif %}
  229. {% endif %}
  230. </li>
  231. {% endfor %}
  232. </ul>
  233. {% enddefaultmacro %}
  234. {% defaultmacro is_public(doc) %}
  235. {#
  236. This macro is a bit unconventional in that its output is not rendered, but treated as a boolean:
  237. Returning no text is interpreted as false, returning any other text is iterpreted as true.
  238. Implementing this as a macro makes it very easy to override with a custom template, see
  239. https://github.com/mitmproxy/pdoc/tree/main/examples/custom-template.
  240. #}
  241. {% if doc.name == "__init__" %}
  242. {# show all constructors #}
  243. true
  244. {% elif doc.name == "__doc__" %}
  245. {# We don't want to document __doc__ itself, https://github.com/mitmproxy/pdoc/issues/235 #}
  246. {% elif doc.kind == "module" and doc.fullname not in all_modules %}
  247. {# Skip modules that were manually excluded, https://github.com/mitmproxy/pdoc/issues/334 #}
  248. {% elif (doc.qualname or doc.name) is in(module.obj.__all__ or []) %}
  249. {# members starting with an underscore are still public if mentioned in __all__ #}
  250. true
  251. {% elif not doc.name.startswith("_") and (doc.kind != "variable" or doc.is_enum_member or doc.docstring) %}
  252. {# members not starting with an underscore are considered public by default #}
  253. true
  254. {% endif %}
  255. {% enddefaultmacro %}
  256. {# fmt: off #}
  257. {% defaultmacro inherited(cls) %}
  258. {% for base, members in cls.inherited_members.items() %}
  259. {% set m = None %}{# workaround for https://github.com/pallets/jinja/issues/1427 #}
  260. {% set member_html %}
  261. {% for m in members if is_public(m) | trim %}
  262. <dd id="{{ m.qualname }}" class="{{ m.kind }}">
  263. {{- m.taken_from | link(text=m.name.replace("__init__",base[1])) -}}
  264. </dd>
  265. {% endfor %}
  266. {% endset %}
  267. {# we may not have any public members, in which case we don't want to print anything. #}
  268. {% if member_html and "vtkmodules" not in base | link %}
  269. <div><dt>{{ base | link }}</dt>
  270. {{ member_html }}
  271. </div>
  272. {% endif %}
  273. {% endfor %}
  274. {% enddefaultmacro %}
  275. {# fmt: on #}
  276. {% defaultmacro view_source_state(doc) %}
  277. {% if show_source and doc.source %}
  278. <input id="{{ doc.qualname or "mod-" + doc.name }}-view-source" class="view-source-toggle-state" type="checkbox" aria-hidden="true" tabindex="-1">
  279. {% endif %}
  280. {% enddefaultmacro %}
  281. {% defaultmacro view_source_button(doc) %}
  282. {% if show_source and doc.source %}
  283. <label class="view-source-button" for="{{ doc.qualname or "mod-" + doc.name }}-view-source"><span>View Source</span></label>
  284. {% endif %}
  285. {% enddefaultmacro %}
  286. {% defaultmacro view_source_code(doc) %}
  287. {% if show_source and doc.source %}
  288. {{ doc | highlight }}
  289. {% endif %}
  290. {% enddefaultmacro %}
  291. {% defaultmacro module_name() %}
  292. <h1 class="modulename">
  293. {% set parts = module.modulename.split(".") %}
  294. {% for part in parts %}
  295. {%- set fullname = ".".join(parts[:loop.index]) -%}
  296. {%- if fullname in all_modules and fullname != module.modulename -%}
  297. <a href="./{{ "../" * loop.revindex0 }}{{ part }}.html">{{ part }}</a>
  298. {%- else -%}
  299. {{ part }}
  300. {%- endif -%}
  301. {%- if loop.nextitem -%}
  302. <wbr>.
  303. {%- endif -%}
  304. {% endfor %}
  305. </h1>
  306. {% enddefaultmacro %}