-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add fastapi template and api extra field
- Loading branch information
zumuta
committed
Nov 22, 2024
1 parent
cb5ad4a
commit 1253a62
Showing
8 changed files
with
100 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "griffe-fastapi" | ||
version = "0.1.3" | ||
version = "0.1.4" | ||
description = "Griffe extension for FastAPI." | ||
authors = ["fbraem <[email protected]>"] | ||
readme = "README.md" | ||
|
@@ -24,3 +24,6 @@ black = "^24.10.0" | |
[build-system] | ||
requires = ["poetry-core"] | ||
build-backend = "poetry.core.masonry.api" | ||
|
||
[project.entry-points."mkdocstrings.python.templates"] | ||
griffe-fastapi = "griffe_fastapi:get_templates_path" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
src/griffe_fastapi/templates/material/_base/fastapi.html.jinja
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
{#- Template for Python FastAPI. | ||
This template renders a Python function that is decorated with a FastAPI APIRouter. | ||
Context: | ||
function (griffe.Function): The function that implements the api to render. | ||
root (bool): Whether this is the root object, injected with `:::` in a Markdown page. | ||
heading_level (int): The HTML heading level to use. | ||
config (dict): The configuration options. | ||
-#} | ||
|
||
{% block logs scoped %} | ||
{#- Logging block. | ||
This block can be used to log debug messages, deprecation messages, warnings, etc. | ||
-#} | ||
{{ log.debug("Rendering " + function.path) }} | ||
{% endblock logs %} | ||
|
||
{% import "language"|get_template as lang with context %} | ||
{#- Language module providing the `t` translation method. -#} | ||
|
||
<div class="doc doc-object doc-function"> | ||
{% with obj = function, html_id = function.extra.griffe_fastapi.api %} | ||
|
||
{% set function_name = function.extra.griffe_fastapi.api %} | ||
|
||
{% filter heading( | ||
heading_level, | ||
role="api", | ||
id=html_id, | ||
class="doc doc-heading", | ||
toc_label=(('<code class="doc-symbol doc-symbol-toc doc-symbol-' + symbol_type + '"></code> ')|safe if config.show_symbol_type_toc else '') + function.name, | ||
) %} | ||
{% endfilter %} | ||
|
||
<div class="doc doc-contents"> | ||
{% block contents scoped %} | ||
{#- Contents block. | ||
This block renders the contents of the function. | ||
It contains other blocks that users can override. | ||
Overriding the contents block allows to rearrange the order of the blocks. | ||
-#} | ||
{% block docstring scoped %} | ||
{#- Docstring block. | ||
This block renders the docstring for the function. | ||
-#} | ||
{% with docstring_sections = function.docstring.parsed %} | ||
{% include "docstring"|get_template with context %} | ||
{% endwith %} | ||
{% endblock docstring %} | ||
|
||
{% endblock contents %} | ||
</div> | ||
|
||
{% endwith %} | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{% extends "_base/fastapi.html.jinja" %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters