From f9a8bee7328660168b6606bb656ac339442d9a69 Mon Sep 17 00:00:00 2001 From: noah morrison Date: Sun, 2 Nov 2014 23:43:51 -0500 Subject: [PATCH] Added some documentation And fixed some pep8 problems. also... the code seems to not be rendering right... how long has that been happening? --- chevron.py | 26 +++++++++++++++++++++++++- test_spec.py | 3 ++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/chevron.py b/chevron.py index 996b02b..a81497c 100755 --- a/chevron.py +++ b/chevron.py @@ -62,7 +62,6 @@ def tokenize(template): return literal - tag_types = { '!': 'comment', '#': 'section', @@ -124,6 +123,31 @@ def tokenize(template): def render(template, data, partials_path='.', partials_ext='mustache'): + """Render a mustache template. + + Renders a mustache template with a data scope and partial capability. + Given the file structure... + . + |- main.py + |- main.ms + |- partials + |- part.ms + + then main.py would make the following call: + + render(open('main.ms', 'r'), {...}, 'partials', 'ms') + + Arguments: + template -- A file-like object or a string containing the template + data -- A python dictionary with your data scope + partials_path -- The path to where your partials are stored + (defaults to '.') + partials_ext -- The extension that you want the parser to look for + (defaults to 'mustache') + + Returns: + A string containing the rendered template. + """ def get_key(key): for scope in scopes: try: diff --git a/test_spec.py b/test_spec.py index 484cf73..f28ecbb 100755 --- a/test_spec.py +++ b/test_spec.py @@ -18,7 +18,8 @@ def _test_case_from_path(json_path): def test_case(self): self.assertEqual(STACHE(obj['template'], obj['data']), obj['expected']) - test_case.__doc__ = 'suite: {} desc: {}'.format(spec, obj['desc']) + test_case.__doc__ = 'suite: {} desc: {}'.format(spec, + obj['desc']) return test_case with open(json_path, 'r') as f: yaml = json.load(f) -- 2.47.3