Name | jinja2-pdoc JSON |
Version |
0.2.2
JSON |
| download |
home_page | |
Summary | jinja2 extension to embedd python code directly from module using pdoc |
upload_time | 2024-01-21 19:45:58 |
maintainer | |
docs_url | None |
author | Christoph Dörrer |
requires_python | >=3.8.1,<3.13 |
license | MIT |
keywords |
jinja2
pdoc
jinja2 extension
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# jinja2-pdoc
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/jinja2_pdoc)](https://pypi.org/project/jinja2_pdoc/)
[![PyPI](https://img.shields.io/pypi/v/jinja2_pdoc)](https://pypi.org/project/jinja2_pdoc/)
[![PyPI - Downloads](https://img.shields.io/pypi/dm/jinja2_pdoc)](https://pypi.org/project/jinja2_pdoc/)
[![PyPI - License](https://img.shields.io/pypi/l/jinja2_pdoc)](https://raw.githubusercontent.com/d-chris/jinja2_pdoc/main/LICENSE)
[![GitHub Workflow Test)](https://img.shields.io/github/actions/workflow/status/d-chris/jinja2_pdoc/pytest.yml?logo=github&label=pytest)](https://github.com/d-chris/jinja2_pdoc/actions/workflows/pytest.yml)
[![GitHub tag (with filter)](https://img.shields.io/github/v/tag/d-chris/jinja2_pdoc?logo=github&label=github)](https://github.com/d-chris/jinja2_pdoc)
---
[`jinja2`](https://www.pypi.org/project/jinja2) extension based on [`pdoc`](https://pypi.org/project/pdoc/) to embedd python code directly from modules or files into your `jinja` template.
## Installation
```cmd
pip install jinja2_pdoc
```
## Usage
- [CLI](#command-line)
- [Library](#library)
## Syntax
```jinja2
{% pdoc <module>:<object>:<pdoc_attr[.str_attr]> %}
```
see also [Example](#library)
### `<module>`
module name or path to python file
- `pathlib`
- `examples/example.py`
Example:
```jinja2
{% pdoc pathlib %}
```
### `<object>`
class and/or function names, eg. from `pathlib`
- `Path`
- `Path.open`
Example:
```jinja2
{% pdoc pathlib:Path %}
```
### `<pdoc_attr>`
`pdoc` attributes
- `docstring` - docstring of the object
- `source` - source code of the object
- `code` - plane code from functions, without def and docstring
Example:
```jinja2
{% pdoc pathlib:Path:docstring %}
```
### `[.str_attr]`
optional `str` functions can be added to `<pdoc_attr>` with a dot
- `dedent` - removes common leading whitespace, see `textwrap.dedent`
- `indent` - format code with 2 spaces for indentation, see `autopep8.fix_code`
- `upper` - converts to upper case
- `lower` - converts to lower case
Example:
```jinja2
{% pdoc pathlib:Path.open:code.dedent %}
```
## Examples
### Command Line
```cmd
>>> jinja2pdoc .\examples\ --force
rendering.. example.md
```
```cmd
>>> jinja2pdoc --help
Usage: jinja2pdoc [OPTIONS] INPUT [OUTPUT]
Render jinja2 templates from a input directory or file and write to a output
directory.
if the `input` is a directory, all files with a matching `pattern` are
renderd.
if no `output` is given, the current working directory is used.
Options:
-p, --pattern TEXT template search pattern for directories
-f, --force overwrite existing files
-n, --newline TEXT newline character
--help Show this message and exit..
```
### Library
python code to render a template directly from a string
````python
from jinja2_pdoc import jinja2, Jinja2Pdoc
env = jinja2.Environment(extensions=[Jinja2Pdoc])
s = """
# jinja2-pdoc
embedd python code directly from pathlib using a jinja2 extension based on pdoc
## docstring from pathlib.Path
{% pdoc pathlib:Path:docstring %}
## source from pathlib.Path.open
```python
{% pdoc pathlib:Path.open:source.indent -%}
```
"""
code = env.from_string(textwrap.dedent(s)).render()
Path("example.md").write_text(code)
````
### Result
output of the [code](#library) above
````markdown
# jinja2-pdoc
embedd python code directly from pathlib using a jinja2 extension based on pdoc
## docstring from pathlib.Path
PurePath subclass that can make system calls.
Path represents a filesystem path but unlike PurePath, also offers
methods to do system calls on path objects. Depending on your system,
instantiating a Path will return either a PosixPath or a WindowsPath
object. You can also instantiate a PosixPath or WindowsPath directly,
but cannot instantiate a WindowsPath on a POSIX system or vice versa.
## source from pathlib.Path.open
```python
def open(self, mode='r', buffering=-1, encoding=None,
errors=None, newline=None):
"""
Open the file pointed by this path and return a file object, as
the built-in open() function does.
"""
if "b" not in mode:
encoding = io.text_encoding(encoding)
return io.open(self, mode, buffering, encoding, errors, newline)
```
````
Raw data
{
"_id": null,
"home_page": "",
"name": "jinja2-pdoc",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.8.1,<3.13",
"maintainer_email": "",
"keywords": "jinja2,pdoc,jinja2 extension",
"author": "Christoph D\u00f6rrer",
"author_email": "d-chris@web.d",
"download_url": "https://files.pythonhosted.org/packages/e8/88/fbbe50a02c91a80119f8e2fd3fe50419b999f93043ba60a3cbbb55d32abe/jinja2_pdoc-0.2.2.tar.gz",
"platform": null,
"description": "# jinja2-pdoc\n\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/jinja2_pdoc)](https://pypi.org/project/jinja2_pdoc/)\n[![PyPI](https://img.shields.io/pypi/v/jinja2_pdoc)](https://pypi.org/project/jinja2_pdoc/)\n[![PyPI - Downloads](https://img.shields.io/pypi/dm/jinja2_pdoc)](https://pypi.org/project/jinja2_pdoc/)\n[![PyPI - License](https://img.shields.io/pypi/l/jinja2_pdoc)](https://raw.githubusercontent.com/d-chris/jinja2_pdoc/main/LICENSE)\n[![GitHub Workflow Test)](https://img.shields.io/github/actions/workflow/status/d-chris/jinja2_pdoc/pytest.yml?logo=github&label=pytest)](https://github.com/d-chris/jinja2_pdoc/actions/workflows/pytest.yml)\n[![GitHub tag (with filter)](https://img.shields.io/github/v/tag/d-chris/jinja2_pdoc?logo=github&label=github)](https://github.com/d-chris/jinja2_pdoc)\n\n---\n\n[`jinja2`](https://www.pypi.org/project/jinja2) extension based on [`pdoc`](https://pypi.org/project/pdoc/) to embedd python code directly from modules or files into your `jinja` template.\n\n## Installation\n\n```cmd\npip install jinja2_pdoc\n```\n\n## Usage\n\n- [CLI](#command-line)\n- [Library](#library)\n\n## Syntax\n\n```jinja2\n{% pdoc <module>:<object>:<pdoc_attr[.str_attr]> %}\n```\n\nsee also [Example](#library)\n\n### `<module>`\n\nmodule name or path to python file\n\n- `pathlib`\n- `examples/example.py`\n\nExample:\n\n```jinja2\n{% pdoc pathlib %}\n```\n\n### `<object>`\n\nclass and/or function names, eg. from `pathlib`\n\n- `Path`\n- `Path.open`\n\nExample:\n\n```jinja2\n{% pdoc pathlib:Path %}\n```\n\n### `<pdoc_attr>`\n\n`pdoc` attributes\n\n- `docstring` - docstring of the object\n- `source` - source code of the object\n- `code` - plane code from functions, without def and docstring\n\nExample:\n\n```jinja2\n{% pdoc pathlib:Path:docstring %}\n```\n\n### `[.str_attr]`\n\noptional `str` functions can be added to `<pdoc_attr>` with a dot\n\n- `dedent` - removes common leading whitespace, see `textwrap.dedent`\n- `indent` - format code with 2 spaces for indentation, see `autopep8.fix_code`\n- `upper` - converts to upper case\n- `lower` - converts to lower case\n\nExample:\n\n```jinja2\n{% pdoc pathlib:Path.open:code.dedent %}\n```\n\n## Examples\n\n### Command Line\n\n```cmd\n>>> jinja2pdoc .\\examples\\ --force\n\nrendering.. example.md\n```\n\n```cmd\n\n>>> jinja2pdoc --help\n\nUsage: jinja2pdoc [OPTIONS] INPUT [OUTPUT]\n\n Render jinja2 templates from a input directory or file and write to a output\n directory.\n\n if the `input` is a directory, all files with a matching `pattern` are\n renderd.\n\n if no `output` is given, the current working directory is used.\n\nOptions:\n -p, --pattern TEXT template search pattern for directories\n -f, --force overwrite existing files\n -n, --newline TEXT newline character\n --help Show this message and exit..\n```\n\n### Library\n\npython code to render a template directly from a string\n\n````python\n\nfrom jinja2_pdoc import jinja2, Jinja2Pdoc\n\nenv = jinja2.Environment(extensions=[Jinja2Pdoc])\n\ns = \"\"\"\n # jinja2-pdoc\n\n embedd python code directly from pathlib using a jinja2 extension based on pdoc\n\n ## docstring from pathlib.Path\n\n {% pdoc pathlib:Path:docstring %}\n\n ## source from pathlib.Path.open\n\n ```python\n {% pdoc pathlib:Path.open:source.indent -%}\n ```\n \"\"\"\n\ncode = env.from_string(textwrap.dedent(s)).render()\n\nPath(\"example.md\").write_text(code)\n\n````\n\n### Result\n\noutput of the [code](#library) above\n\n````markdown\n\n# jinja2-pdoc\n\nembedd python code directly from pathlib using a jinja2 extension based on pdoc\n\n## docstring from pathlib.Path\n\nPurePath subclass that can make system calls.\n\nPath represents a filesystem path but unlike PurePath, also offers\nmethods to do system calls on path objects. Depending on your system,\ninstantiating a Path will return either a PosixPath or a WindowsPath\nobject. You can also instantiate a PosixPath or WindowsPath directly,\nbut cannot instantiate a WindowsPath on a POSIX system or vice versa.\n\n## source from pathlib.Path.open\n\n```python\ndef open(self, mode='r', buffering=-1, encoding=None,\n errors=None, newline=None):\n \"\"\"\n Open the file pointed by this path and return a file object, as\n the built-in open() function does.\n \"\"\"\n if \"b\" not in mode:\n encoding = io.text_encoding(encoding)\n return io.open(self, mode, buffering, encoding, errors, newline)\n```\n\n````\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "jinja2 extension to embedd python code directly from module using pdoc",
"version": "0.2.2",
"project_urls": {
"homepage": "https://d-chris.github.io/jinja2_pdoc",
"repository": "https://github.com/d-chris/jinja2_pdoc"
},
"split_keywords": [
"jinja2",
"pdoc",
"jinja2 extension"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "c5ba645cf3d32b9e0a7432ab92fbae94e719c8cc6b0060158a71940afac16667",
"md5": "fcc53ba98d71f2f5e7e9adde80c47aca",
"sha256": "158de585abe2ff8db619abf25ed05e9f9e7946f10fbbe616b544a48765828d29"
},
"downloads": -1,
"filename": "jinja2_pdoc-0.2.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "fcc53ba98d71f2f5e7e9adde80c47aca",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8.1,<3.13",
"size": 8011,
"upload_time": "2024-01-21T19:45:57",
"upload_time_iso_8601": "2024-01-21T19:45:57.130146Z",
"url": "https://files.pythonhosted.org/packages/c5/ba/645cf3d32b9e0a7432ab92fbae94e719c8cc6b0060158a71940afac16667/jinja2_pdoc-0.2.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "e888fbbe50a02c91a80119f8e2fd3fe50419b999f93043ba60a3cbbb55d32abe",
"md5": "fe96e5e90784bed977fcdf660e60a6fd",
"sha256": "7ad24aef38c0c7f63234d788e070e8994ba42d62e14d8a7187785c5f0c646983"
},
"downloads": -1,
"filename": "jinja2_pdoc-0.2.2.tar.gz",
"has_sig": false,
"md5_digest": "fe96e5e90784bed977fcdf660e60a6fd",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8.1,<3.13",
"size": 6595,
"upload_time": "2024-01-21T19:45:58",
"upload_time_iso_8601": "2024-01-21T19:45:58.709934Z",
"url": "https://files.pythonhosted.org/packages/e8/88/fbbe50a02c91a80119f8e2fd3fe50419b999f93043ba60a3cbbb55d32abe/jinja2_pdoc-0.2.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-01-21 19:45:58",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "d-chris",
"github_project": "jinja2_pdoc",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"tox": true,
"lcname": "jinja2-pdoc"
}