Package: combustache
combustacheMustache v1.4 implementation with lambdas.Usable both in code and as CLI.
To render a mustache template usecombustache.render.
Processed templates are cached; to clear cache usecombustache.cache_clear.InstallationFromPyPI:pipinstallcombustacheFrom git:pipinstallgit+https://github.com/sakhezech/combustacheUsage as CLIcombustache ...orpython -m combustache ...usage: combustache [-h] [-v] [-s] [-d DATA] [-o OUTPUT] [-p PARTIAL]
                   [--partial-dir PARTIAL_DIR] [--partial-ext PARTIAL_EXT]
                   [--left-delimiter LEFT_DELIMITER] [--right-delimiter RIGHT_DELIMITER]
                   template

an explosive mustache v1.4 implementation with lambdas

positional arguments:
  template              mustache template file (use -s for string)

options:
  -h, --help            show this help message and exit
  -v, --version         show program's version number and exit
  -s, --string          pass in a string instead of a file for template
  -d DATA, --data DATA  data json file (defaults to stdin)
  -o OUTPUT, --output OUTPUT
                        output file (defaults to stdout)
  -p PARTIAL, --partial PARTIAL
                        mustache partial file (can add multiple)
  --partial-dir PARTIAL_DIR
                        directory with mustache partials
  --partial-ext PARTIAL_EXT
                        partial file extention (defaults to '.mustache')
  --left-delimiter LEFT_DELIMITER
                        left mustache template delimiter (defaults to '{{')
  --right-delimiter RIGHT_DELIMITER
                        right mustache template delimiter (defaults to '}}')Usage in codeBasic>>>template='Hello {{place}}!'>>>data={'place':'world'}>>>combustache.render(template,data)'Hello world!'PartialsPartials have to be provided as a dictionary.>>>template='My {{>md_link}}!'>>>data={'name':'Github','url':'https://github.com/sakhezech'}>>>partials={'md_link':'[{{name}}]({{url}})'}>>>combustache.render(template,data,partials)'My [Github](https://github.com/sakhezech)!'Custom delimitersYou can specify the delimiters outside the template.>>>template='My name is <%name%>.'>>>data={'name':'Anahit'}>>>combustache.render(template,data,left_delimiter='<%',right_delimiter='%>')'My name is Anahit.'List indexingYou can index into lists by dotting into them with a number. Both positive and negative numbers work.>>>data={'items':['Apricot','Cherry','Pomegranate']}>>>template='The first item is {{items.0}}.'>>>combustache.render(template,data)'The first item is Apricot.'>>>template='The last item is {{items.-1}}.'>>>combustache.render(template,data)'The last item is Pomegranate.'Custom stringifyYou can provide a custom stringify function if needed.Note:None -> ''happens here, so you will need to handle this case yourself.>>>template='This statement is {{bool}}.'>>>data={'bool':True}>>>deflowercase_bool(val):...ifvalisNone:...return''...ifisinstance(val,bool):...returnstr(val).lower()...returnstr(val)...>>>combustache.render(template,data,stringify=lowercase_bool)'This statement is true.'Custom escapingIf you need some other way of escaping your data, you can provide a custom escaping function.>>>template='Escaped: {{content}}; Not escaped: {{{content}}}.'>>>data={'content':'{hello}'}>>>defescape_braces(string):...returnstring.replace('{',r'\{').replace('}',r'\}')...>>>combustache.render(template,data,escape=escape_braces)'Escaped:\\{hello\\}; Not escaped:{hello}.'Handling missing dataIf you want to do something on a missing value, like raise an exception or insert a default value, you can do that too.Note:Noneis not missing data.>>>template='{{something}}'>>>data={}>>>combustache.render(template,data,missing_data=lambda:'NO DATA')'NO DATA'