Skip to content

Commit

Permalink
unify templates; test toc; improve docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ppatrzyk committed Jan 9, 2023
1 parent accd8ee commit 7fb5839
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 10 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ Options:
-d <db>, --database <db> Specify database location (if missing, in memory SQLite). Valid for SQL scripts.
-o <file>, --output <file> Specify report file (if missing, <script_name>_<date>).
-f <format>, --format <format> Specify report format: html (default), md.
-i, --interactive Make tables interactive (search, sort, paging). Valid for HTML output.
-a <author>, --author <author> Specify author (if missing, user name).
-t <title>, --title <title> Specify report title (if missing, script file name)
-i, --interactive Make tables interactive (search, sort, paging). Valid for HTML output.
-c, --toc Generate Table of Contents
-v, --version Show version and exit.
```

Expand All @@ -64,11 +66,13 @@ Note, in case your report file contains raw html chunks (such as plots or images

## Formatting and plots

In produced report, code will be broken into sections. Each section ends with a statement printing some output (e.g., `print()`). You can give titles to each section by placing _magic comment_ - `#TITLE <your_section_title>` for python, `--TITLE <your_section_title>` for SQL - after line that produces output.

### Python

When it comes to report formatting, there are 3 types of outputs in a Python script: Standard `<code>` block (default), HTML, or Markdown.

By default _merkury_ treats any code printing some output (e.g., `print()`) as one containing code and puts it into `<code>` blocks. If your output is actually HTML or Markdown, you need to indicate that by placing a _magic comment_ after print statement in your script.
By default _merkury_ treats any output as standard code print and puts it into `<code>` blocks. If your output is actually HTML or Markdown, you need to indicate that by placing a _magic comment_ after print statement in your script.

#### HTML

Expand Down Expand Up @@ -102,7 +106,7 @@ List:

### SQL

Unlike Python, there are no special formatting instructions you can specify in comments. Outputs from all queries will be formatted as a HTML table.
Outputs from all queries will be formatted as a HTML tables.

## Acknowledgements

Expand Down
2 changes: 1 addition & 1 deletion merkury/templates/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ <h2>Contents</h2>
{% for chunk in chunks %}
<div class="code-block" id="merkury-chunk-{{ chunk.number }}">
{% if chunk.title is not none %}
<h3>{{ chunk.title }}</h3>
<h2>{{ chunk.title }}</h2>
{% endif %}
<details>
<summary>In [{{ chunk.number }}]</summary>
Expand Down
24 changes: 20 additions & 4 deletions merkury/templates/template.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,29 @@
# {{ file_name }}
# {{ title }}

### {{ timestamp }}

{% if toc %}
## Contents
{% for chunk in chunks %}
\[_In_\]
{% if chunk.title is not none %}
{{ chunk.number }}. {{ chunk.title }}
{% else %}
{{ chunk.number }}. Chunk {{ chunk.number }}
{% endif %}
{% endfor %}
{% endif %}

{% for chunk in chunks %}

{% if chunk.title is not none %}
## {{ chunk.title }}
{% endif %}

_In_ \[{{ chunk.number }}\]
```{{ script_type }}
{{ chunk.in }}
```
\[_Out_\]
_Out_ \[{{ chunk.number }}\]
{% if chunk.html or chunk.markdown %}
{{ chunk.out }}
{% else %}
Expand All @@ -18,6 +34,6 @@
---
{% endfor %}

_Script triggered by {{ author }} on {{ timestamp }}, ran in {{ duration }}ms_
_Script {{ file_name }} triggered by {{ author }} on {{ timestamp }}, ran in {{ duration }}ms_

_Report generated with [Merkury](https://github.com/ppatrzyk/merkury) v{{ version }}._
2 changes: 2 additions & 0 deletions tests/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
s = "some string"

print(f"Test {s}")
#TITLE First section

b = a + 5

for _ in range(2):
print("loop test")
#TITLE Second section
4 changes: 2 additions & 2 deletions tests/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ def test_execute_python():
expected_code = [
(["a = 1 + 2"], ""),
(["""s = \"some string\""""], ""),
(["""print(f"Test {s}")"""], "Test some string\n"),
(["""print(f"Test {s}")""", "#TITLE First section"], "Test some string\n"),
(["b = a + 5"], ""),
(["for _ in range(2):", """ print("loop test")"""], "loop test\nloop test\n")
(["for _ in range(2):", """ print("loop test")""", "#TITLE Second section"], "loop test\nloop test\n")
]
assert list(execute_python(PY_SCRIPT)) == expected_code

Expand Down

0 comments on commit 7fb5839

Please sign in to comment.