def render_slide(file, templates, partials): header = parse_header(file) slide_src = header["src"] template_name = header.get("context", {}).get("template", None) template_src = templates.get(template_name, None) template_config = {"partial": partials} if template_src is not None: # bind to contents variable template_config["contents"] = slide_src eco_ctx = eco.context_for(template_src) else: eco_ctx = eco.context_for(slide_src) # merge with header context dictionary return eco_ctx.call("render", dict(template_config, **header["context"]))
def test_runtime_error(): context = eco.context_for("Hello <% throw 'foo' %>") try: context.call("render") except execjs.ProgramError: pass
def test_context_for(): context = eco.context_for("Hello <%= @name %>") assert "Hello " == context.call("render") assert "Hello Sam" == context.call("render", {"name": "Sam"})