Skip to content

scme0/tmpltr

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

Tmpltr

🚧 Work in Progress 🚧 This is a new project which isn't fully implemented yet 🙂

Tmpltr is a small app that allows you to convert any text-based file type into a template where you can inject data from a yaml.

The original usecase is for a latex resume where you want to extract the actual information out of latex so that it's easier to edit and update.

The three ways it works are:

  1. Specify a property and it will directly inject the value into the document as a string.
  2. Specify a property that is an object and specify another template file: a. Tmpltr will load the second template and evaluate it against the property's object. It will then inject the output of the evaluation in-line.
  3. Specify a property that is an array and specify another template file: a. Tmpltr will load the second template and evaluate it against each object in the array. It will then inject the output of each evaluation on a new line. b. If an array is just a list of strings, you can refence the string value in the subtemplate with << . >>

Format:

  1. << path.to.property >>
  2. and 3. << path.to.property | path/to/subtemplate.tex >>

Localisation (-l)

Any property whose value is a map containing the active language as a key is automatically reduced to that language's value. For example, with -l en:

title:
  en: 'Software Engineer'
  fr: 'Ingénieur'

<< title >> injects Software Engineer. With -l fr it injects Ingénieur. Plain (non-map) values and maps without the active language key pass through untouched, so the same data file builds one language per run. If -l is omitted, locale selection is disabled.

Builtin functions (@)

Instead of a sub-template file, the right side of a | may be a builtin function, prefixed with @:

  • << start | @duration >> — formats an employment length from a date. The value may be an object { start: 'YYYY-MM-DD', end?: 'YYYY-MM-DD' } (the end defaults to today) and renders as - 4 years and 5 months (or - 4 ans et 5 mois under -l fr). A plain string value is passed through verbatim, so an entry can opt out of the calculation and supply a fixed label instead.

CommandLine args:

tmpltr [-d '{{ }}'] [-l <language>] path/to/basetemplate.tex path/to/data.yaml [-o path/to/output.tex]

-o is to specify an output file. If you don't specify it, the result will be sent to stdout.

-d is to specify the injection marker for properties. The default is '<< >>' but you can specify anything as long as the end is different to the start (eg: NOT $$ $$). The format to put in the command line arg is <start><space><end>. It can be longer than 2 chars. eg: ~:> <:~

-l (or --lang) selects the language for localised fields (see above).

About

A C# templating library - good to templating data into LaTex documents

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors