TemplateSv

class clink.service.TemplateSv(app_conf, auth_conf)[source]

Simple template engine

Parameters:
build_file(file_path, values)[source]

Read data from file then build it as a template

Parameters:
  • file_path (str) –
  • values (dict) –
Return type:

str

build_str(data, values)[source]

Build string template

Parameters:
Return type:

str

Example

template_sv.py
from clink.service import TemplateSv
from clink.type import AppConf, AuthConf


app_conf = AppConf('dead-book', 'Hell Corporation', '1st Hell Street')

root_pwd = 'root-pwd'
root_email = 'root@email.com'
root_email_pwd = 'root-email-pwd'
root_email_server = 'smtp.email.com'
root_email_server_port = 587
auth_conf = AuthConf(
    root_pwd, root_email, root_email_pwd, root_email_server,
    root_email_server_port, 'jwt-key'
)

template_sv = TemplateSv(app_conf, auth_conf)

report_tpl = (
    'REPORT: MOTOCYCLE SPEC\n'
    'AUTHOR: $author\n\n'
    'Name       : $name\n'
    'Price      : $price\n'
    'Color      : $color\n'
    'Power      : $power'
)
values = {
    'author': 'Johnny Blaze',
    'name': 'Hell Cycle',
    'price': 'Not for Sale',
    'color': 'Black - Red Fire',
    'power': 'Unlimited'
}
report = template_sv.build_str(report_tpl, values)
print(report)

Testing

$ python template_sv.py
REPORT: MOTOCYCLE SPEC
AUTHOR: Johnny Blaze

Name       : Hell Cycle
Price      : Not for Sale
Color      : Black - Red Fire
Power      : Unlimit