pycharmers.cli.render_template module

pycharmers.cli.render_template.add_title_prefix_for_rawmeta(fp, ext='.raw')[source]
pycharmers.cli.render_template.add_extra_keys(keys, data)[source]
pycharmers.cli.render_template.render_template(argv=['-M', 'html', '.', '_build'])[source]

Render templates.

Parameters
  • -I/--input-path (str) – Path to a input json file or directory.

  • -O/--output-path (str) – Path to an output file or directory.

  • -td/--tpl-dir (str) – Path to a templates directory.

  • -ext/--extension (str) – Create a file with this extension.

  • --show-all (bool) – If True, show all template filenames in tmp-dir

  • --quiet (bool) – Whether to make the output quiet.

Note

When you run from the command line, execute as follows:

$ render-template -I sample.json
$ render-template -I dir
$ render-template --show-all

Examples

  • Replace Input file using regular expression:
    $ render-template -I sample.json
    - sample.json -> sample.html
    $ render-template -I dir
    Input directory  : dir
    Output directory : dir
    - dir/sample.json -> dir/sample.html
    - dir/subdir/sample.json -> dir/subdir/sample.html
    
  • Show all json file in tpl-dir
    $ render-template --show-all
    Template directory: /Users/iwasakishuto/.pycharmers/cli/render_templates
    * protocols.tpl
    
>>> # If you want to try the contents of the template
>>> from jinja2 import Environment, FileSystemLoader
>>> from pycharmers.cli._path import PYCHARMERS_CLI_RENDER_TEMPLATES_DIR
>>> env = Environment(loader=FileSystemLoader(searchpath=PYCHARMERS_CLI_RENDER_TEMPLATES_DIR))
>>> template = env.get_template("template.tpl")
>>> print(template.render())