From 16189ca7f65e8f3d21e2697e616c1a819ad5e6ef 2013-02-13 19:30:03 From: Matthias BUSSONNIER Date: 2013-02-13 19:30:03 Subject: [PATCH] require jinja, merge base templates --- diff --git a/requirements.txt b/requirements.txt index f1fb6ec..2311cfa 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,3 +2,4 @@ docutils==0.9.1 markdown -e git://github.com/ipython/ipython.git#egg=IPython pygments +Jinja2 diff --git a/templates/basic.tpl b/templates/basic.tpl deleted file mode 100644 index 0eae91c..0000000 --- a/templates/basic.tpl +++ /dev/null @@ -1,29 +0,0 @@ -{%- block header -%} -{%- endblock header -%} -{%- block body -%} -{%- for worksheet in worksheets -%} - {%- for cell in worksheet.cells -%} - {%- block any_cell scoped -%} - {%- if cell.type in ['code'] -%} - {%- block codecell scoped-%} - {%- endblock codecell-%} - {%- elif cell.type in ['markdown'] -%} - {%- block markdowncell scoped-%} - {%- endblock markdowncell -%} - {%- elif cell.type in ['heading'] -%} - {%- block headingcell scoped-%} - {%- endblock headingcell -%} - {%- elif cell.type in ['raw'] -%} - {%- block rawcell scoped-%} - {%- endblock rawcell -%} - {%- else -%} - {%- block unknowncell scoped-%} - {%- endblock unknowncell -%} - {%- endif -%} - {%- endblock any_cell -%} - {%- endfor -%} -{%- endfor -%} -{%- endblock body -%} - -{%- block footer -%} -{%- endblock footer -%} diff --git a/templates/null.tpl b/templates/null.tpl index 5f62daf..32f0456 100644 --- a/templates/null.tpl +++ b/templates/null.tpl @@ -1,13 +1,15 @@ -{%- extends 'basic.tpl' -%} - {# +DO NOT USE THIS AS A BASE WORK, +IF YOU ARE COPY AND PASTING THIS FILE +YOU ARE PROBABLY DOING THINGS WRONG. + Null template, Does nothing except defining a basic structure To layout the diferents blocks of a notebook. Subtemplates can Override Blocks to define their custom reresentation. -If one of the block you do overrite is nt a leave block, consider +If one of the block you do overrite is not a leave block, consider calling super. {%- block nonLeaveBlock -%} @@ -19,37 +21,52 @@ calling super. consider calling super even if block is leave block, we might insert more block later. #} - -{%- block codecell scoped -%} -{%- block in_prompt -%}{%- endblock in_prompt -%} -{%- block input -%}{%- endblock input -%} -{%- if cell.outputs -%} -{%- block output_prompt -%}{%- endblock output_prompt -%} -{%- for output in cell.outputs -%} - {%- if output.output_type in ['pyout']%} - {%- block pyout scoped -%}{%- endblock pyout -%} - {%- elif output.output_type in ['stream'] -%} - {%- block stream scoped -%}{%- endblock stream -%} - {%- elif output.output_type in ['display_data'] -%} - {%- block display_data scoped -%}{%- endblock display_data -%} - {%- elif output.output_type in ['pyerr'] -%} - {%- block pyerr scoped -%} - {%- for line in output.traceback -%} - {%- block traceback_line scoped -%}{%- endblock traceback_line -%} - {%- endfor -%} - {%- endblock pyerr -%} - {%- endif -%} +{%- block header -%} +{%- endblock header -%} +{%- block body -%} +{%- for worksheet in worksheets -%} + {%- for cell in worksheet.cells -%} + {%- block any_cell scoped -%} + {%- if cell.type in ['code'] -%} + {%- block codecell scoped -%} + {%- block in_prompt -%}{%- endblock in_prompt -%} + {%- block input -%}{%- endblock input -%} + {%- if cell.outputs -%} + {%- block output_prompt -%}{%- endblock output_prompt -%} + {%- for output in cell.outputs -%} + {%- if output.output_type in ['pyout'] -%} + {%- block pyout scoped -%}{%- endblock pyout -%} + {%- elif output.output_type in ['stream'] -%} + {%- block stream scoped -%}{%- endblock stream -%} + {%- elif output.output_type in ['display_data'] -%} + {%- block display_data scoped -%}{%- endblock display_data -%} + {%- elif output.output_type in ['pyerr'] -%} + {%- block pyerr scoped -%} + {%- for line in output.traceback -%} + {%- block traceback_line scoped -%}{%- endblock traceback_line -%} + {%- endfor -%} + {%- endblock pyerr -%} + {%- endif -%} + {%- endfor -%} + {%- endif -%} + {%- endblock codecell -%} + {%- elif cell.type in ['markdown'] -%} + {%- block markdowncell scoped-%} + {%- endblock markdowncell -%} + {%- elif cell.type in ['heading'] -%} + {%- block headingcell scoped-%} + {%- endblock headingcell -%} + {%- elif cell.type in ['raw'] -%} + {%- block rawcell scoped-%} + {%- endblock rawcell -%} + {%- else -%} + {%- block unknowncell scoped-%} + {%- endblock unknowncell -%} + {%- endif -%} + {%- endblock any_cell -%} + {%- endfor -%} {%- endfor -%} -{%- endif -%} -{%- endblock codecell -%} - -{%- block markdowncell scoped -%}{%- endblock markdowncell -%} - -{%- block headingcell scoped -%} -{%- endblock headingcell -%} - -{%- block rawcell scoped -%} -{%- endblock rawcell -%} +{%- endblock body -%} -{%- block unknowncell scoped -%} -{%- endblock unknowncell -%} +{%- block footer -%} +{%- endblock footer -%} diff --git a/tests/test_templates.py b/tests/test_templates.py index d7ede81..08ad4de 100644 --- a/tests/test_templates.py +++ b/tests/test_templates.py @@ -10,11 +10,6 @@ def test_evens(): 'tests/ipynbref/IntroNumPy.orig' ] - C = ConverterTemplate(tplfile='basic') - C.read('tests/ipynbref/IntroNumPy.orig.ipynb') - result = C.convert() - nt.assert_equal(result,'') - # null template should return empty C = ConverterTemplate(tplfile='null') C.read('tests/ipynbref/IntroNumPy.orig.ipynb')