Skip to content

Commit

Permalink
Fix #3
Browse files Browse the repository at this point in the history
  • Loading branch information
miek770 committed Nov 20, 2024
1 parent 1a54de8 commit 9deb4b7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 21 deletions.
42 changes: 23 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ Any number of keyword arguments can be provided to match and replace `{{keyword}

### Example

#### From Static Template File

This is the `test_pandas_pdf()` test from [tests/test_renderers.py](tests/test_renderers.py); it replaces the `{{calculations}}` keyword with a [pandas DataFrame](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.html) to generate a PDF report.

```python
Expand Down Expand Up @@ -73,34 +75,36 @@ Here is the PDF result (margins were cropped for this picture, and the `{{introd

![example](https://raw.githubusercontent.com/miek770/eznbtemplater/refs/heads/main/media/test_pandas_pdf.png)

This is the `test_nb_programatically()` test from [tests/test_nb_programatically.py](tests/test_nb_programatically.py); it works with a notebook template created with [nbformat](https://pypi.org/project/nbformat/) inspired by [this example](https://gist.github.com/fperez/9716279) instead of a notebook file:
#### From Dynamically Defined Template

This is the `test_nb_programatically()` test from [tests/test_nb_programatically.py](tests/test_nb_programatically.py); it works with a notebook template created with [nbformat](https://pypi.org/project/nbformat/), inspired by [this example](https://gist.github.com/fperez/9716279), instead of a static notebook template file:

```python
from eznbtemplater.eznbtemplater import render_nb
import nbformat as nbf
from pathlib import Path


def test_nb_programatically() -> None:
nb: nbf.NotebookNode = nbf.v4.new_notebook()
nb["cells"] = [
nbf.v4.new_raw_cell(r"\renewcommand{\contentsname}{Table of Contents}"),
nbf.v4.new_raw_cell(r"\tableofcontents"),
nbf.v4.new_markdown_cell("# Introduction"),
nbf.v4.new_markdown_cell("{{introduction}}"),
]

output_path: Path = Path("tests/test_nb_programatically.ipynb")

introduction: str = "This is a ***test***, don't mind me."
render_nb(
template_nb=nb,
output_path=output_path,
introduction=introduction,
)
assert output_path.exists()
nb: nbf.NotebookNode = nbf.v4.new_notebook()
nb["cells"] = [
nbf.v4.new_raw_cell(r"\renewcommand{\contentsname}{Table of Contents}"),
nbf.v4.new_raw_cell(r"\tableofcontents"),
nbf.v4.new_markdown_cell("# Introduction"),
nbf.v4.new_markdown_cell("{{introduction}}"),
]

output_path: Path = Path("tests/test_nb_programatically.ipynb")

introduction: str = "This is a ***test***, don't mind me."
render_nb(
template_nb=nb,
output_path=output_path,
introduction=introduction,
)
```

#### Additional Examples

See [tests/test_renderers.py](tests/test_renderers.py) for a few additional examples.

## Contributing
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "eznbtemplater"
version = "0.1.4"
version = "0.1.5"
authors = [
{ name="Michel Lavoie", email="[email protected]" },
]
Expand Down
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9deb4b7

Please sign in to comment.