Anki/anki/template
Damien Elmes c76c08069e change template replacement behaviour
Previously {{field}} wrapped the field in a span with the field's font
properties. This wasn't obvious, and caused frequent problems with people
trying to combine field and template text, or use field content in dictionary
links.

Now that AnkiWeb has a wizard for configuring the front & back layout, we can
just put the formatting in the template instead.
2011-11-18 02:50:47 +09:00
..
__init__.py convert pystache to private library since it doesn't behave like upstream 2010-11-29 22:51:55 +09:00
LICENSE convert pystache to private library since it doesn't behave like upstream 2010-11-29 22:51:55 +09:00
README.anki don't truncate sort field anymore, since we display it in the gui 2011-04-28 09:24:03 +09:00
README.rst convert pystache to private library since it doesn't behave like upstream 2010-11-29 22:51:55 +09:00
template.py change template replacement behaviour 2011-11-18 02:50:47 +09:00
view.py convert pystache to private library since it doesn't behave like upstream 2010-11-29 22:51:55 +09:00

========
Pystache
========

Inspired by ctemplate_ and et_, Mustache_ is a
framework-agnostic way to render logic-free views.

As ctemplates says, "It emphasizes separating logic from presentation:
it is impossible to embed application logic in this template language."

Pystache is a Python implementation of Mustache. Pystache requires
Python 2.6.

Documentation
=============

The different Mustache tags are documented at `mustache(5)`_.

Install It
==========

::

    pip install pystache


Use It
======

::

    >>> import pystache
    >>> pystache.render('Hi {{person}}!', {'person': 'Mom'})
    'Hi Mom!'

You can also create dedicated view classes to hold your view logic.

Here's your simple.py::

    import pystache
    class Simple(pystache.View):
        def thing(self):
            return "pizza"

Then your template, simple.mustache::

    Hi {{thing}}!

Pull it together::

    >>> Simple().render()
    'Hi pizza!'


Test It
=======

nose_ works great! ::

    pip install nose
    cd pystache
    nosetests


Author
======

::

    context = { 'author': 'Chris Wanstrath', 'email': 'chris@ozmm.org' }
    pystache.render("{{author}} :: {{email}}", context)


.. _ctemplate: http://code.google.com/p/google-ctemplate/
.. _et: http://www.ivan.fomichev.name/2008/05/erlang-template-engine-prototype.html
.. _Mustache: http://defunkt.github.com/mustache/
.. _mustache(5): http://defunkt.github.com/mustache/mustache.5.html
.. _nose: http://somethingaboutorange.com/mrl/projects/nose/0.11.1/testing.html