@@ -0,0 +1,1440 @@
+%22%22%22A simple extension that renders cells as jinja templates.%0A%0AFor demonstration purposes, this renders in a simple environment with %60solution=True%60,%0Aso that a solution notebook *template* will be executable.%0A%0AInput with:%0A%0A    %7B%25 if solution %25%7D%0A    solution_code%0A    %7B%25 else %25%7D%0A    student_code%0A    %7B%25 endif %25%7D%0A%0Awill be executable as the solution version.%0A%22%22%22%0A%0Afrom __future__ import print_function%0Aimport sys%0A%0Aimport jinja2%0A%0Afrom IPython.core.inputtransformer import InputTransformer%0A%0A%0Aclass SolutionInputTransformer(InputTransformer):%0A    %22%22%22Renders IPython input cells as jinja templates with solution=True%22%22%22%0A    def __init__(self, *args, **kwargs):%0A        super(SolutionInputTransformer, self).__init__(*args, **kwargs)%0A        %0A        self.env = jinja2.Environment()%0A        self._lines = %5B%5D%0A    %0A    def push(self, line):%0A        self._lines.append(line)%0A        return None%0A    %0A    def reset(self):%0A        text = u'%5Cn'.join(self._lines)%0A        self._lines = %5B%5D%0A        template = self.env.from_string(text)%0A        try:%0A            return template.render(solution=True)%0A        except Exception as e:%0A            print(%22Failed to render jinja template: %25s%22 %25 e, file=sys.stderr)%0A            return text%0A%0A%0Adef load_ipython_extension(ip):%0A    %22%22%22register the transformer as the first physical line transform.%22%22%22%0A    ip.input_transformer_manager.physical_line_transforms.insert(%0A        0,%0A        SolutionInputTransformer()%0A    )%0A

add jinjasolution