def _render_template(self, name, revision, options): """Render a template. :param name: the file name of the template :type name: str :param revision: the package revision :type revision: str :param options: the template options to use in rendering :type options: dict :rtype: dict """ template = self._data(revision, name) return util.render_mustache_json(template, options)
def test_render_mustache_json(): # x's value expands to a JSON array # y's value expands to a JSON object # z's value expands to a JSON string template = '{ "x": {{{xs}}}, "y": {{{ys}}}, "z": "{{{z}}}"}' xs = [1, 2, 3] ys = {'y1': 1, 'y2': 2} z = 'abc' data = {'xs': xs, 'ys': ys, 'z': z} result = util.render_mustache_json(template, data) assert type(result) is dict assert result.get('x') == xs assert result.get('y') == ys assert result.get('z') == z