Skip to main content

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 the lookup_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/*

Changelog

0.0.2 fix bug which stopped future template replacing when no script was found 0.0.1 initial release

Project details


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.2.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

easy_template-0.0.2-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file easy_template-0.0.2.tar.gz.

File metadata

  • Download URL: easy_template-0.0.2.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.3

File hashes

Hashes for easy_template-0.0.2.tar.gz
Algorithm Hash digest
SHA256 da505f3ca1d175d5d54a8d80f028832528af963501728917f46cca1c5b2b1c00
MD5 f4d88c37b6c4f926783371119e91c209
BLAKE2b-256 a50617fbe5be2ce293d733fb9a2ac244d24cb65886ab36cb47443a955f74b23f

See more details on using hashes here.

File details

Details for the file easy_template-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: easy_template-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.3

File hashes

Hashes for easy_template-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e341c7fb2197a6a5a3c4aec5464c931e975e3d17b186bae4b975f7b122c5c593
MD5 affaedc9c3a140d5dd0b79eff685fefa
BLAKE2b-256 13e60b9bb13be02f398de629ba7d38941a4204274165b45f48e3cfc658094ca3

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page