Skip to content

Commit

Permalink
add .j2 extension
Browse files Browse the repository at this point in the history
  • Loading branch information
maartenbreddels committed Oct 14, 2019
1 parent 621eb9d commit 6df9090
Show file tree
Hide file tree
Showing 26 changed files with 38 additions and 38 deletions.
7 changes: 0 additions & 7 deletions nbconvert/exporters/latex.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,10 @@ def _file_extension_default(self):
def _template_data_paths_default(self):
return jupyter_path("nbconvert", "templates", "latex")

@default('template_extension')
def _template_extension_default(self):
return '.tex'

@default('template_name')
def _template_name_default(self):
return 'latex'

#Extension that the template files use.
template_extension = Unicode(".tex").tag(config=True)

output_mimetype = 'text/latex'

def default_filters(self):
Expand Down
5 changes: 5 additions & 0 deletions nbconvert/exporters/pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ class PDFExporter(LatexExporter):
def _file_extension_default(self):
return '.pdf'


@default('template_extension')
def _template_extension_default(self):
return '.tex.j2'

def run_command(self, command_list, filename, count, log_function, raise_on_failure=None):
"""Run command_list count times.
Expand Down
2 changes: 1 addition & 1 deletion nbconvert/exporters/slides.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def _file_extension_default(self):

@default('template_extension')
def _template_extension_default(self):
return '.html'
return '.html.j2'

output_mimetype = 'text/html'

Expand Down
5 changes: 4 additions & 1 deletion nbconvert/exporters/templateexporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,10 @@ def _raw_template_changed(self, change):
template_extension = Unicode(".tpl").tag(config=True, affects_environment=True)
@default('template_extension')
def _template_extension_default(self):
return self.file_extension
if self.file_extension:
return self.file_extension + ".j2"
else:
return self.file_extension

@default('template_file')
def _template_file_default(self):
Expand Down
2 changes: 1 addition & 1 deletion nbconvert/exporters/tests/test_latex.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def test_prompt_number_color_ipython(self):
"""
my_loader_tplx = DictLoader({'my_template':
"""
((* extends 'style_ipython.tex' *))
((* extends 'style_ipython.tex.j2' *))
((* block docclass *))
\documentclass[11pt]{article}
Expand Down
24 changes: 12 additions & 12 deletions nbconvert/exporters/tests/test_templateexporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

import pytest

raw_template = """{%- extends 'index.rst' -%}
raw_template = """{%- extends 'index.rst.j2' -%}
{%- block in_prompt -%}
blah
{%- endblock in_prompt -%}
Expand Down Expand Up @@ -163,7 +163,7 @@ def __init__(self, *args, **kwargs):
output_init, _ = exporter_init.from_notebook_node(nb)
assert "blah" in output_init
exporter_init.raw_template = ''
assert exporter_init.template_file == "index.rst"
assert exporter_init.template_file == "index.rst.j2"
output_init, _ = exporter_init.from_notebook_node(nb)
assert "blah" not in output_init

Expand All @@ -180,7 +180,7 @@ def test_raw_template_dynamic_attr(self):
class AttrDynamicExporter(TemplateExporter):
@default('default_template_file')
def _template_file_default(self):
return "index.rst"
return "index.rst.j2"

@default('raw_template')
def _raw_template_default(self):
Expand All @@ -190,7 +190,7 @@ def _raw_template_default(self):
output_attr_dynamic, _ = exporter_attr_dynamic.from_notebook_node(nb)
assert "blah" in output_attr_dynamic
exporter_attr_dynamic.raw_template = ''
assert exporter_attr_dynamic.template_file == "index.rst"
assert exporter_attr_dynamic.template_file == "index.rst.j2"
output_attr_dynamic, _ = exporter_attr_dynamic.from_notebook_node(nb)
assert "blah" not in output_attr_dynamic

Expand All @@ -211,13 +211,13 @@ def _raw_template_default(self):

@default('default_template_file')
def _template_file_default(self):
return 'index.rst'
return 'index.rst.j2'

exporter_attr_dynamic = AttrDynamicExporter(template_name='rst')
output_attr_dynamic, _ = exporter_attr_dynamic.from_notebook_node(nb)
assert "blah" in output_attr_dynamic
exporter_attr_dynamic.raw_template = ''
assert exporter_attr_dynamic.template_file == 'index.rst'
assert exporter_attr_dynamic.template_file == 'index.rst.j2'
output_attr_dynamic, _ = exporter_attr_dynamic.from_notebook_node(nb)
assert "blah" not in output_attr_dynamic

Expand Down Expand Up @@ -270,7 +270,7 @@ def test_raw_template_deassignment(self):
output_deassign, _ = exporter_deassign.from_notebook_node(nb)
assert "blah" in output_deassign
exporter_deassign.raw_template = ''
assert exporter_deassign.template_file == 'index.rst'
assert exporter_deassign.template_file == 'index.rst.j2'
output_deassign, _ = exporter_deassign.from_notebook_node(nb)
assert "blah" not in output_deassign

Expand All @@ -289,7 +289,7 @@ def test_raw_template_dereassignment(self):
output_dereassign, _ = exporter_dereassign.from_notebook_node(nb)
assert "baz" in output_dereassign
exporter_dereassign.raw_template = ''
assert exporter_dereassign.template_file == 'index.rst'
assert exporter_dereassign.template_file == 'index.rst.j2'
output_dereassign, _ = exporter_dereassign.from_notebook_node(nb)
assert "blah" not in output_dereassign

Expand Down Expand Up @@ -318,7 +318,7 @@ def test_exclude_code_cell(self):
}
c_no_io = Config(no_io)
exporter_no_io = TemplateExporter(config=c_no_io, template_name='markdown')
exporter_no_io.template_file = 'index.md'
exporter_no_io.template_file = 'index.md.j2'
nb_no_io, resources_no_io = exporter_no_io.from_filename(self._get_notebook())

assert not resources_no_io['global_content_filter']['include_input']
Expand All @@ -336,7 +336,7 @@ def test_exclude_code_cell(self):
}
c_no_code = Config(no_code)
exporter_no_code = TemplateExporter(config=c_no_code, template_name='markdown')
exporter_no_code.template_file = 'index.md'
exporter_no_code.template_file = 'index.md.j2'
nb_no_code, resources_no_code = exporter_no_code.from_filename(self._get_notebook())

assert not resources_no_code['global_content_filter']['include_code']
Expand Down Expand Up @@ -376,7 +376,7 @@ def test_exclude_markdown(self):

c_no_md = Config(no_md)
exporter_no_md = TemplateExporter(config=c_no_md, template_name='python')
exporter_no_md.template_file = 'index.py'
exporter_no_md.template_file = 'index.py.j2'
nb_no_md, resources_no_md = exporter_no_md.from_filename(self._get_notebook())

assert not resources_no_md['global_content_filter']['include_markdown']
Expand Down Expand Up @@ -424,5 +424,5 @@ def _make_exporter(self, config=None):
if not exporter.template_file:
# give it a default if not specified
exporter.template_name = 'python'
exporter.template_file = 'index.py'
exporter.template_file = 'index.py.j2'
return exporter
2 changes: 1 addition & 1 deletion nbconvert/tests/fake_exporters.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ def _file_extension_default(self):

@default('template_extension')
def _template_extension_default(self):
return '.html'
return '.html.j2'
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{%- extends 'base.html' -%}
{% from 'mathjax.html' import mathjax %}
{%- extends 'base.html.j2' -%}
{% from 'mathjax.html.j2' import mathjax %}


{%- block header -%}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{%- extends 'classic/index.html' -%}

{%- extends 'classic/index.html.j2' -%}

{%- block html_head_css -%}
{{ resources.include_css("static/index.css") }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
This template defines defines a default docclass, the inheriting class should
override this.-=))

((*- extends 'document_contents.tex' -*))
((*- extends 'document_contents.tex.j2' -*))

%===============================================================================
% Abstract overrides
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

((=- Default to the notebook output style -=))
((*- if not cell_style is defined -*))
((* set cell_style = 'style_jupyter.tex' *))
((* set cell_style = 'style_jupyter.tex.j2' *))
((*- endif -*))

((=- Inherit from the specified cell style. -=))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

% Default to the notebook output style
((* if not cell_style is defined *))
((* set cell_style = 'style_ipython.tex' *))
((* set cell_style = 'style_ipython.tex.j2' *))
((* endif *))

% Inherit from the specified cell style.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
((= Black&white ipython input/output style =))

((*- extends 'base.tex' -*))
((*- extends 'base.tex.j2' -*))

%===============================================================================
% Input
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
((= Black&white Python input/output style =))

((*- extends 'base.tex' -*))
((*- extends 'base.tex.j2' -*))

%===============================================================================
% Input
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
((= IPython input/output style =))
style_bw_python.\TeX((= IPython input/output style =))

((*- extends 'base.tex' -*))
((*- extends 'base.tex.j2' -*))

% Custom definitions
((* block definitions *))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
((=- IPython input/output style -=))
((*- extends 'base.tex' -*))
((*- extends 'base.tex.j2' -*))

((*- block packages -*))
\usepackage[breakable]{tcolorbox}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
((= Python input/output style =))

((*- extends 'base.tex' -*))
((*- extends 'base.tex.j2' -*))

% Custom definitions
((* block definitions *))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{%- extends 'classic/index.html' -%}
{% from 'mathjax.html' import mathjax %}
{%- extends 'classic/index.html.j2' -%}
{% from 'mathjax.html.j2' import mathjax %}

{%- block any_cell scoped -%}
{%- if cell.metadata.get('slide_start', False) -%}
Expand Down

0 comments on commit 6df9090

Please sign in to comment.