return literal
-
tag_types = {
'!': 'comment',
'#': 'section',
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:
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)