Template and Macros Expansion for Path names.
Project description
tmep
Template and Macros Expansion for Path names.
Installation
From PyPI
pip install tmep
Usage
>>> import tmep
>>> template = '$prename $lastname'
>>> values = {'prename': 'Franz', 'lastname': 'Schubert'}
>>> out = tmep.parse(template, values)
>>> print(out)
Franz Schubert
This module implements a string formatter based on the standard PEP 292 string.Template class extended with function calls. Variables, as with string.Template, are indicated with $ and functions are delimited with %.
This module assumes that everything is Unicode: the template and the substitution values. Bytestrings are not supported. Also, the templates always behave like the safe_substitute method in the standard library: unknown symbols are left intact.
This is sort of like a tiny, horrible degeneration of a real templating engine like Jinja2 or Mustache.
Development
Test
tox
Publish a new version
git tag 1.1.1 git push --tags poetry build poetry publish
Package documentation
The package documentation is hosted on readthedocs.
Generate the package documentation:
python setup.py build_sphinx
Functions
alpha
-----
%alpha{text}
This function first ASCIIfies the given text, then all non alphabet
characters are replaced with whitespaces.
alphanum
--------
%alphanum{text}
This function first ASCIIfies the given text, then all non alpanumeric
characters are replaced with whitespaces.
asciify
-------
%asciify{text}
Translate non-ASCII characters to their ASCII equivalents. For
example, “café” becomes “cafe”. Uses the mapping provided by the
unidecode module.
delchars
--------
%delchars{text,chars}
Delete every single character of “chars“ in “text”.
deldupchars
-----------
%deldupchars{text,chars}
Search for duplicate characters and replace with only one occurrance
of this characters.
first
-----
%first{text} or %first{text,count,skip} or
%first{text,count,skip,sep,join}
Returns the first item, separated by ; . You can use
%first{text,count,skip}, where count is the number of items (default
1) and skip is number to skip (default 0). You can also use
%first{text,count,skip,sep,join} where sep is the separator, like ; or
/ and join is the text to concatenate the items.
if
--
%if{condition,truetext} or %if{condition,truetext,falsetext}
If condition is nonempty (or nonzero, if it’s a number), then returns
the second argument. Otherwise, returns the third argument if
specified (or nothing if falsetext is left off).
ifdef
-----
%ifdef{field}, %ifdef{field,text} or %ifdef{field,text,falsetext}
If field exists, then return truetext or field (default). Otherwise,
returns falsetext. The field should be entered without $.
ifdefempty
----------
%ifdefempty{field,text} or %ifdefempty{field,text,falsetext}
If field exists and is empty, then return truetext. Otherwise, returns
falsetext. The field should be entered without $.
ifdefnotempty
-------------
%ifdefnotempty{field,text} or %ifdefnotempty{field,text,falsetext}
If field is not empty, then return truetext. Otherwise, returns
falsetext. The field should be entered without $.
initial
-------
%initial{text}
Get the first character of a text in lowercase. The text is converted
to ASCII. All non word characters are erased.
left
----
%left{text,n}
Return the first “n” characters of “text”.
lower
-----
%lower{text}
Convert “text” to lowercase.
nowhitespace
------------
%nowhitespace{text,replace}
Replace all whitespace characters with replace. By default: a dash (-)
%nowhitespace{$track,_}
num
---
%num{number,count}
Pad decimal number with leading zeros.
%num{$track,3}
replchars
---------
%replchars{text,chars,replace}
Replace the characters “chars” in “text” with “replace”.
%replchars{text,ex,-} > t--t
right
-----
%right{text,n}
Return the last “n” characters of “text”.
sanitize
--------
%sanitize{text}
Delete in most file systems not allowed characters.
shorten
-------
%shorten{text} or %shorten{text,max_size}
Shorten “text” on word boundarys.
%shorten{$title,32}
time
----
%time{date_time,format,curformat}
Return the date and time in any format accepted by strftime. For
example, to get the year some music was added to your library, use
%time{$added,%Y}.
title
-----
%title{text}
Convert “text” to Title Case.
upper
-----
%upper{text}
Convert “text” to UPPERCASE.
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
Built Distribution
File details
Details for the file tmep-0.0.0.tar.gz
.
File metadata
- Download URL: tmep-0.0.0.tar.gz
- Upload date:
- Size: 16.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.14 CPython/3.10.2 Linux/5.13.0-1031-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f5d7f9621b2111b33cd9fe3c4c47519f88c1854a1f6922a9f3db86d12164e0e2 |
|
MD5 | 31e7712c8f1a64d6b977b4e91c0bf83a |
|
BLAKE2b-256 | fefce977930c01b99ee4afdabf06650337c6d9425b455a6f837a1dacdd4a3359 |
File details
Details for the file tmep-0.0.0-py3-none-any.whl
.
File metadata
- Download URL: tmep-0.0.0-py3-none-any.whl
- Upload date:
- Size: 16.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.14 CPython/3.10.2 Linux/5.13.0-1031-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce0ae65e6c3e2638a36e85c26f13f4cc87c8346ecd3d14b28299de98e7cdb1ec |
|
MD5 | 38ec10b7d86e1067b4ef60ca92b9483b |
|
BLAKE2b-256 | de97708ac0086c2bf505ad993d3f50225f73a445f71e575e2d5b1dbfa6cb4be3 |