gearsix 869ef50010 Overhaul to README docs; update to the `-h` for the dati binary. 8 months ago
..
README.md 869ef50010 Overhaul to README docs; update to the `-h` for the dati binary. 8 months ago
dati.go 869ef50010 Overhaul to README docs; update to the `-h` for the dati binary. 8 months ago
dati_test.sh 912752f46b REBRAND to 'dati - data and template interface' 2 years ago

README.md

DATI

dati [OPTIONS]

DATA

Data is a file written in any data language (e.g. JSON or YAML), a list of supported languages can be seen in the README for the dati library. These files provide key=value data.

dati generates a single data structure of all data contained within parsed data files. This super-structure is passed to each "root" template, where value data is accessed using the key strings.

The data structure generated by dati will only have 1 absolute key: "data" (can be renamed using the -dk/-data-key option). This key will overwrite any other root key of the same name. Its value will be an array, where each element is the key=value data parsed one of the "data" files.

Parsed "global data" will be written to the root of the data structure and into the root for each element of the "data" array. If a key within one of these objects conflicts with one of the keys in the "global data", then the "global data" key is ignored.

TEMPLATES

All "root" template files passed to dati that have a file extension matching one of the supported templating languages will be parsed and executed against the generated data structure.

All "parital" templates will be parsed into any "root" templates that have a file extension that match the same templating language.

OPTIONS

  • -r, -root PATH
    Path of the root template file to execute against.

  • -p, -partial PATH ...
    Path of (multiple) template files that are called upon by at least one root template

  • If a directory is passed then all files within that directory will (recursively) be loaded.

  • -gd, -global-data PATH ...
    Path of (multiple) data files to load as "global data". If a directory is passed then all files within that directory will (recursively) be loaded.

  • -d, -data PATH ...
    path of (multiple) data files to load as "data". If a directory is passed then all files within that directory will (recursively) be loaded.

  • -dk, -data-key NAME
    Set the name of the key used for the generated array of data. The default data key is "data".

  • -sd, -sort-data ATTRIBUTE
    The file attribute to order data files by. If no value is provided, the data will be provided in the order it's loaded.

  • Accepted values: "filename", "modified".

  • A suffix can be appended to each value to set the sort order: "-asc" (for ascending), "-desc" (for descending). If not specified, this defaults to "-asc".

  • -cfg -config FILE
    A data file to provide default values for the above options (CONFIG).

CONFIG

You might want to use the same options if you run dati multiple times for the same project. This can be done by creating a data file and passing the filepath to the -cfg argument.

The key names for the options set in the config file must match the name of the argument option to set (long or short). For example (a config file in toml):

root="~/templates/blog.mst"
partial="~/templates/blog/"
gd="./blog.json"
data="./posts/"
dk="posts"

EXAMPLES

dati -cfg ./dati.cfg -r templates/textfile.mst

dati -r homepage.hmpl -p head.hmpl -p body.hmpl -gd meta.json -d posts/*

see the examples/ directory in the dati repository for a cool example.