Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Nbconvert template loading magic #4727

Merged
merged 9 commits into from
Jan 8, 2014
17 changes: 7 additions & 10 deletions IPython/nbconvert/exporters/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# Imports
#-----------------------------------------------------------------------------

from IPython.utils.traitlets import Unicode, List
import os

from IPython.nbconvert import preprocessors
from IPython.config import Config
Expand All @@ -31,17 +31,14 @@ class HTMLExporter(TemplateExporter):
filters, just change the 'template_file' config option.
"""

file_extension = Unicode(
'html', config=True,
help="Extension of the file that should be written to disk"
)
def _file_extension_default(self):
return 'html'

mime_type = Unicode('text/html', config=True,
help="MIME type of the result file, for HTTP response headers."
)
def _default_template_path_default(self):
return os.path.join("..", "templates", "html")

default_template = Unicode('full', config=True, help="""Flavor of the data
format to use. I.E. 'full' or 'basic'""")
def _template_file_default(self):
return 'full'

output_mimetype = 'text/html'

Expand Down
18 changes: 8 additions & 10 deletions IPython/nbconvert/exporters/latex.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import os

# IPython imports
from IPython.utils.traitlets import Unicode, List
from IPython.utils.traitlets import Unicode
from IPython.config import Config

from IPython.nbconvert import filters, preprocessors
Expand All @@ -35,18 +35,16 @@ class LatexExporter(TemplateExporter):
'template_file' config option. Place your template in the special "/latex"
subfolder of the "../templates" folder.
"""

file_extension = Unicode(
'tex', config=True,
help="Extension of the file that should be written to disk")

default_template = Unicode('article', config=True, help="""Template of the
data format to use. I.E. 'article' or 'report'""")
def _file_extension_default(self):
return 'tex'

def _template_file_default(self):
return 'article'

#Latex constants
default_template_path = Unicode(
os.path.join("..", "templates", "latex"), config=True,
help="Path where the template files are located.")
def _default_template_path_default(self):
return os.path.join("..", "templates", "latex")

template_skeleton_path = Unicode(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same treatment for template_skeleton_path as default_template_path, probably

os.path.join("..", "templates", "latex", "skeleton"), config=True,
Expand Down
9 changes: 5 additions & 4 deletions IPython/nbconvert/exporters/markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#-----------------------------------------------------------------------------

from IPython.config import Config
from IPython.utils.traitlets import Unicode

from .templateexporter import TemplateExporter

Expand All @@ -26,9 +25,11 @@ class MarkdownExporter(TemplateExporter):
Exports to a markdown document (.md)
"""

file_extension = Unicode(
'md', config=True,
help="Extension of the file that should be written to disk")
def _file_extension_default(self):
return 'md'

def _template_file_default(self):
return 'markdown'

output_mimetype = 'text/markdown'

Expand Down
11 changes: 5 additions & 6 deletions IPython/nbconvert/exporters/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
# Imports
#-----------------------------------------------------------------------------

from IPython.utils.traitlets import Unicode

from .templateexporter import TemplateExporter

#-----------------------------------------------------------------------------
Expand All @@ -24,9 +22,10 @@ class PythonExporter(TemplateExporter):
"""
Exports a Python code file.
"""

file_extension = Unicode(
'py', config=True,
help="Extension of the file that should be written to disk")
def _file_extension_default(self):
return 'py'

def _template_file_default(self):
return 'python'

output_mimetype = 'text/x-python'
9 changes: 5 additions & 4 deletions IPython/nbconvert/exporters/rst.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
# Imports
#-----------------------------------------------------------------------------

from IPython.utils.traitlets import Unicode
from IPython.config import Config

from .templateexporter import TemplateExporter
Expand All @@ -26,9 +25,11 @@ class RSTExporter(TemplateExporter):
Exports restructured text documents.
"""

file_extension = Unicode(
'rst', config=True,
help="Extension of the file that should be written to disk")
def _file_extension_default(self):
return 'rst'

def _template_file_default(self):
return 'rst'

output_mimetype = 'text/restructuredtext'

Expand Down
14 changes: 5 additions & 9 deletions IPython/nbconvert/exporters/slides.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
# Imports
#-----------------------------------------------------------------------------

from IPython.utils.traitlets import Unicode

from IPython.nbconvert import preprocessors
from IPython.config import Config

Expand All @@ -26,15 +24,13 @@
class SlidesExporter(HTMLExporter):
"""Exports HTML slides with reveal.js"""

file_extension = Unicode(
'slides.html', config=True,
help="Extension of the file that should be written to disk"
)
def _file_extension_default(self):
return 'slides.html'

output_mimetype = 'text/html'
def _template_file_default(self):
return 'slides_reveal'

default_template = Unicode('reveal', config=True, help="""Template of the
data format to use. I.E. 'reveal'""")
output_mimetype = 'text/html'

@property
def default_config(self):
Expand Down
3 changes: 0 additions & 3 deletions IPython/nbconvert/exporters/templateexporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,12 @@ def _load_template(self):
# template by name with extension added, then try loading the template
# as if the name is explicitly specified, then try the name as a
# 'flavor', and lastly just try to load the template by module name.
module_name = self.__module__.rsplit('.', 1)[-1]
try_names = []
if self.template_file:
try_names.extend([
self.template_file + self.template_extension,
self.template_file,
module_name + '_' + self.template_file + self.template_extension,
])
try_names.append(module_name + self.template_extension)
for try_name in try_names:
self.log.debug("Attempting to load template %s", try_name)
try:
Expand Down
2 changes: 1 addition & 1 deletion IPython/nbconvert/exporters/tests/test_slides.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,5 @@ def test_export_reveal(self):
"""
Can a SlidesExporter export using the 'reveal' template?
"""
(output, resources) = SlidesExporter(template_file='reveal').from_filename(self._get_notebook())
(output, resources) = SlidesExporter(template_file='slides_reveal').from_filename(self._get_notebook())
assert len(output) > 0
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{%- extends 'html_basic.tpl' -%}
{%- extends 'basic.tpl' -%}


{%- block header -%}
Expand Down Expand Up @@ -67,4 +67,4 @@ init_mathjax();

{% block footer %}
</html>
{% endblock footer %}
{% endblock footer %}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{%- extends 'html_basic.tpl' -%}
{%- extends 'basic.tpl' -%}


{%- block any_cell scoped -%}
Expand Down
2 changes: 1 addition & 1 deletion IPython/nbconvert/templates/latex/style_bw_ipython.tplx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
((= Black&white ipython input/output style =))

((*- extends 'latex_base.tplx' -*))
((*- extends 'base.tplx' -*))

%===============================================================================
% Input
Expand Down
2 changes: 1 addition & 1 deletion IPython/nbconvert/templates/latex/style_bw_python.tplx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
((= Black&white Python input/output style =))

((*- extends 'latex_base.tplx' -*))
((*- extends 'base.tplx' -*))

%===============================================================================
% Input
Expand Down
2 changes: 1 addition & 1 deletion IPython/nbconvert/templates/latex/style_ipython.tplx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
((= IPython input/output style =))

((*- extends 'latex_base.tplx' -*))
((*- extends 'base.tplx' -*))

% Custom definitions
((* block definitions *))
Expand Down
2 changes: 1 addition & 1 deletion IPython/nbconvert/templates/latex/style_python.tplx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
((= Python input/output style =))

((*- extends 'latex_base.tplx' -*))
((*- extends 'base.tplx' -*))

% Custom definitions
((* block definitions *))
Expand Down
2 changes: 1 addition & 1 deletion IPython/nbconvert/tests/test_nbconvertapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def test_template(self):
"""
with self.create_temp_cwd(['notebook2.ipynb']):
self.call('nbconvert --log-level 0 --to slides '
'notebook2.ipynb --template reveal')
'notebook2.ipynb --template slides_reveal')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the --template arg is superfluous here anyway, right?

assert os.path.isfile('notebook2.slides.html')
with open('notebook2.slides.html') as f:
assert '/reveal.css' in f.read()
Expand Down