Create and process templates with ease
Project description
Easy Template
Process templates with ease.
You can process template files (process_file()
) or text templates (process_template()
).
Templating
process_file('foobar.md', values={'name': 'Hans'}, lookup_dir='scripts')
{{=key}}
gets replaced with the value looked up in the provided value dict{{=key.nested_key1.nested_key2}}
gets replaced with the value looked up in the provided value dict:values['key']['nested_key1']['nested_key2']
{{foobar.py}}
gets replaced with the content of the file located in thelookup_dir
folder or a subfolder.{{%py% foobar.py}}
wraps the content with a markdown code block.{{%py%= key}}
wraps the content as a markdown code block.
helper functions
Side-By-Side Code
Sometimes it is useful to have a side-by-side view of some code, especially for correcting examns...
See the examples for more details. The bewlow returns a Table as follows:
side_by_side_code(q2_answer, q2_solution, titles=['Answer', 'Solution'], max_line_length=80)
Result:
Answer | Solution
------------------------------------------------------
def collatz(a): | def collatz(number):
if a % 2 == 0: | if number % 2 == 0:
return int(a / 2) | return number // 2
else: | return 3 * number + 1
return 3 * a + 1 |
|
| zahl = 9
z = 9 | result = []
r = [] | while zahl > 1:
while z > 1: | zahl = collatz(zahl)
z = collatz(z) | result.append(zahl)
r.append(z) | print(result)
print(r) |
Package and upload to pip
@see this tutorial
rm -rf build/ dist/ easy_template.egg-info/ && \
python3 setup.py sdist bdist_wheel && \
python3 -m twine upload dist/*
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
easy_template-0.0.1.tar.gz
(4.5 kB
view hashes)
Built Distribution
Close
Hashes for easy_template-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 37592d3682beb819ddc8b0ae93506068c5ab2fb6f2c6dcca581beb03195056cd |
|
MD5 | fefac93effdc32b213d3662ab3fc892a |
|
BLAKE2b-256 | b541b9e79d221507294f49588facc718843d60643aee0ee4318c6f7fc0312c37 |