CLI Samples

Help

usage: datatemplate [-h] [--config-file CONFIG_FILE] {render,dump} ...

options:
  -h, --help            show this help message and exit
  --config-file CONFIG_FILE
                        the path to conf.py

commands:
  valid commands

  {render,dump}
    render              render a template to stdout
    dump                dump the data to stdout without a template

Data File

---
key1: value1

---
key: value
key1: different value

Template File

.. -*- mode: rst -*-

Static Heading
--------------

Individual Item
~~~~~~~~~~~~~~~

{{ data[0]|tojson }}

List of Items
~~~~~~~~~~~~~

{% for item in data %}
- {{item|tojson}}

  - {{item.key}}
  - {{item.key1}}
{% endfor %}


Mapping Series Table
~~~~~~~~~~~~~~~~~~~~

Rendering a table from a list of nested dictionaries using dynamic
headers.

{{ make_list_table_from_mappings(
    [('Key', 'key'), ('Key One', 'key1')],
    data,
    title='Table from series of mappings',
    ) }}

Rendering a Template

$ datatemplate render -o multiple-documents \
  doc/source/_templates/sample-multiple.tmpl \
  doc/source/sample-multiple.yaml
.. -*- mode: rst -*-

Static Heading
--------------

Individual Item
~~~~~~~~~~~~~~~

{"key1": "value1"}

List of Items
~~~~~~~~~~~~~


- {"key1": "value1"}

  - 
  - value1

- {"key": "value", "key1": "different value"}

  - value
  - different value



Mapping Series Table
~~~~~~~~~~~~~~~~~~~~

Rendering a table from a list of nested dictionaries using dynamic
headers.

.. list-table:: Table from series of mappings
   :header-rows: 1

   - * Key
     * Key One
   - * None
     * value1
   - * value
     * different value

Experimenting by Dumping Data

CSV Data With Headers

$ datatemplate dump -o dialect:excel-tab \
  -o headers \
  doc/source/sample.csv
[{'a': 'Eins', 'b': 'Zwei', 'c': 'Drei'},
 {'a': '1', 'b': '2', 'c': '3'},
 {'a': 'I', 'b': 'II', 'c': 'III'}]

CSV Data Without Headers

$ datatemplate dump -o dialect:excel-tab \
  doc/source/sample.csv
[['a', 'b', 'c'], ['Eins', 'Zwei', 'Drei'], ['1', '2', '3'], ['I', 'II', 'III']]