Metadata-Version: 2.0
Name: pandoc-mustache
Version: 0.0.1
Summary: Pandoc filter for variable substitution using Mustache syntax
Home-page: https://github.com/michaelstepner/pandoc-mustache/
Author: Michael Stepner
Author-email: stepner@mit.edu
License: CC0-1.0
Description-Content-Type: UNKNOWN
Keywords: pandoc pandocfilters panflute markdown latex mustache
Platform: UNKNOWN
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: End Users/Desktop
Classifier: Intended Audience :: Developers
Classifier: Topic :: Software Development :: Build Tools
Classifier: Topic :: Text Processing :: Filters
Classifier: Operating System :: OS Independent
Classifier: License :: CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
Classifier: Programming Language :: Python :: 2
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.4
Classifier: Programming Language :: Python :: 3.5
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Programming Language :: Python :: Implementation :: PyPy
Requires-Dist: panflute
Requires-Dist: pystache
Requires-Dist: pyyaml
Requires-Dist: future
Provides-Extra: pypi
Requires-Dist: docutils; extra == 'pypi'

:Date:   December 26, 2017

.. contents::
   :depth: 3
..

pandoc-mustache: Variable Substitution in Pandoc
================================================

|Build Status|

The **pandoc-mustache** filter allows you to put variables into your
pandoc document text, with their values stored in a separate file. When
you run ``pandoc`` the variables are replaced with their values.

*Technical note:* This pandoc filter is not a complete implementation of
the `Mustache template spec <https://mustache.github.io/>`__. Only
variable replacement is supported: other `tag
types <https://mustache.github.io/mustache.5.html#TAG-TYPES>`__ are not
currently supported.

Example
-------

This document, ``document.md``:

    | ---
    | mustache: ./le_gaps.yaml
    | ---
    | The richest American men live {{diff_le_richpoor_men}} years
      longer than the poorest men, while the richest American women live
      {{diff_le_richpoor_men}} years longer than the poorest women.

Combined with this dictionary, ``le_gaps.yaml``:

    | diff_le_richpoor_men: “14.6”
    | diff_le_richpoor_women: “10.1”

Will be converted by ``pandoc document.md --filter pandoc-mustache`` to:

    The richest American men live 14.6 years longer than the poorest
    men, while the richest American women live 10.1 years longer than
    the poorest women.

Installation
------------

Install by opening a terminal and running:

::

    pip install -U pandoc-mustache

Python 2.7, 3.4+, pypy, and pypy3 are supported.

Usage
-----

#. Within a pandoc document, variables are referenced by enclosing the
   variable name in double “mustaches”, i.e. curly brackets, like
   ``{{this}}``.

#. The variables are defined in one or more separate files, using YAML
   formatted key-value pairs. For example:

   .. code:: yaml

       place: Montreal
       temperature: '7'

#. The pandoc document containing the mustache variables points to the
   YAML file (or files) which contain the variable definitions. These
   files are indicated using the mustache field in a `YAML metadata
   block <https://pandoc.org/MANUAL.html#metadata-blocks>`__, typically
   placed at the top of the pandoc document. Absolute paths and relative
   paths are supported: relative paths are evaluated relative to the
   working directory where ``pandoc`` is being run.

   An example:
   ``yaml  ---  title: My Report  author: Jane Smith  mustache: ./vars.yaml  ---  The temperature in {{place}} was {{temperature}} degrees.``

   Or, with more than one file:

   .. code:: yaml

       ---
       title: My Report
       author: Jane Smith
       mustache:
           - ./vars.yaml
           - ./additional_vars.yaml
       ---
       The temperature in {{place}} was {{temperature}} degrees.
       The humidity was {{humidity}}%.

#. Run pandoc and replace all variables in the document with their
   values by adding ``--filter pandoc-mustache`` to the pandoc command.

Tips and Tricks
~~~~~~~~~~~~~~~

-  When defining variables in YAML, there is no need to enclose strings
   in quotes. But you should enclose numbers in quotes if you want them
   to appear in the document using the exact same formatting. Some
   examples:

   .. code:: yaml

       unquoted_string: Montreal  # becomes: Montreal
       quoted_string: 'Montreal'  # becomes: Montreal
       trailingzero_num: 7.40  # becomes: 7.4
       trailingzero_string: '7.40'  # becomes: 7.40

-  If you’re writing a document that reports computed numerical results,
   you can program your code (in R, Python, Stata, etc.) to write those
   numbers to a YAML file automatically each time they are generated. By
   referencing your numerical results using variables instead of
   hard-coding them into the text, the document can be updated instantly
   if the results change. And you can be certain that all the numbers in
   the output document reflect the latest results of your analysis.

Contributing
------------

|Project Status: Inactive – The project has reached a stable, usable
state but is no longer being actively developed; support/maintenance
will be provided as time allows.|

This code is not being actively developed. It was created to fulfill my
pandoc writing needs, and the current feature set is adequate for me.

If you have a **bug report**, you can create an issue or file a pull
request. I’ll look into it, time permitting.

If you have a **feature request**, it is unlikely that I will be able to
implement it for you. You can create an issue to generate discussion. If
you implement a feature, you can file pull request and I will review it
eventually, as time permits. If you’re interested in making major
additions to the code, I’d be happy to welcome a new maintainer to the
project.

License
-------

All of the files in this repository are released to the public domain
under a `CC0
license <https://creativecommons.org/publicdomain/zero/1.0/>`__ to
permit the widest possible reuse.

Acknowledgements
----------------

This pandoc filter was created using Sergio Correia’s
`panflute <https://github.com/sergiocorreia/panflute>`__ package. The
`panflute <https://github.com/sergiocorreia/panflute>`__ repository also
served as an inspiration for the organization of this repository.

Related Filters
~~~~~~~~~~~~~~~

Scott Koga-Browes’
`pandoc-abbreviations <https://github.com/scokobro/pandoc-abbreviations>`__
filter also performs variable replacement in pandoc documents, using a
different syntax.

.. |Build Status| image:: https://travis-ci.org/michaelstepner/pandoc-mustache.svg?branch=master
   :target: https://travis-ci.org/michaelstepner/pandoc-mustache
.. |Project Status: Inactive – The project has reached a stable, usable state but is no longer being actively developed; support/maintenance will be provided as time allows.| image:: http://www.repostatus.org/badges/latest/inactive.svg
   :target: http://www.repostatus.org/#inactive


