Skip to main content

Mustache templating language renderer

Project description

Latest Version Build Status Coverage Status

A python implementation of the mustache templating language.

Why chevron?

I’m glad you asked!

chevron is fast

Chevron runs in less than half the time of pystache (Which is not even up to date on the spec). And in about 70% the time of Stache (A ‘trimmed’ version of mustache, also not spec compliant).

chevron is pep8

The pep8 command is run by travis to ensure consistency.

chevron is spec compliant

Chevron passes all the unittests provided by the spec (in every version listed below).

If you find a test that chevron does not pass, please report it.

chevron is Python 2 and 3 compatible

Python 2.6, 2.7, 3.2, 3.3, and 3.4 are all tested by travis.

USAGE

Commandline usage: (if installed via pypi)

usage: chevron [-h] [-d DATA] [-p PARTIALS_PATH] [-e PARTIALS_EXT]
               [-l DEF_LDEL] [-r DEF_RDEL]
               template

positional arguments:
  template              The mustache file

optional arguments:
  -h, --help            show this help message and exit
  -d DATA, --data DATA  The json data file
  -p PARTIALS_PATH, --path PARTIALS_PATH
                        The directory where your partials reside
  -e PARTIALS_EXT, --ext PARTIALS_EXT
                        The extension for your mustache partials, 'mustache'
                        by default
  -l DEF_LDEL, --left-delimiter DEF_LDEL
                        The default left delimiter, "{{" by default.
  -r DEF_RDEL, --right-delimiter DEF_RDEL
                        The default right delimiter, "}}" by default.

Python usage with strings

import chevron

chevron.render('Hello, {{ mustache }}!', {'mustache': 'World'})

Python usage with file

import chevron

with open('file.mustache', 'r') as f:
    chevron.render(f, {'mustache': 'World'})

Python usage with unpacking

import chevron

args = {
  template: 'Hello, {{ mustache }}!',

  data: {
    'mustache': 'World'
  }
}

chevron.render(**args)

chevron supports partials (via dictionaries)

import chevron

args = {
    template: 'Hello, {{> thing }}!',

    partials_dict: {
        'thing': 'World'
    }
}

chevron.render(**args)

chevron supports partials (via the filesystem)

import chevron

args = {
    template: 'Hello, {{> thing }}!',

    # defaults to .
    partials_path: 'partials/',

    # defaults to mustache
    partials_ext: 'ms',
}

# ./partials/thing.ms will be read and rendered
chevron.render(**args)

INSTALL

  • with git

    $ git clone https://github.com/noahmorrison/chevron.git

or using submodules

$ git submodules add https://github.com/noahmorrison/chevron.git

Also available on pypi!

  • with pip

    $ pip install chevron

TODO

  • add postmortem debugging

  • add caching of templates

  • get popular

  • have people complain

  • fix those complaints

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

chevron-0.7.6.tar.gz (7.3 kB view details)

Uploaded Source

File details

Details for the file chevron-0.7.6.tar.gz.

File metadata

  • Download URL: chevron-0.7.6.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for chevron-0.7.6.tar.gz
Algorithm Hash digest
SHA256 1901da847b458dc6d15c01df82161ba61be2a5bcaac6d6426039e05b16c01511
MD5 a250c62fd0de768f898afc1ece8c9baa
BLAKE2b-256 2fcd0f3169d076a3a6883bef22d7a5aabf8b24ad76ecc1574262a48045237c60

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page