From 7a8be7beb131f621f10e0230271317f13b9032f5 2013-12-21 03:07:21 From: Thomas Kluyver Date: 2013-12-21 03:07:21 Subject: [PATCH] Remove magic for loading templates from module names --- diff --git a/IPython/nbconvert/exporters/html.py b/IPython/nbconvert/exporters/html.py index 8cb8675..d752148 100644 --- a/IPython/nbconvert/exporters/html.py +++ b/IPython/nbconvert/exporters/html.py @@ -31,17 +31,11 @@ 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." - ) - - 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 'html_full' output_mimetype = 'text/html' diff --git a/IPython/nbconvert/exporters/latex.py b/IPython/nbconvert/exporters/latex.py index 0a94b9d..1c3a58b 100644 --- a/IPython/nbconvert/exporters/latex.py +++ b/IPython/nbconvert/exporters/latex.py @@ -35,14 +35,17 @@ class LatexExporter(TemplateExporter): 'template_file' config option. Place your template in the special "/latex" subfolder of the "../templates" folder. """ + + def _file_extension_default(self): + return 'tex' + + def _template_file_default(self): + return 'article' 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'""") - #Latex constants default_template_path = Unicode( os.path.join("..", "templates", "latex"), config=True, diff --git a/IPython/nbconvert/exporters/markdown.py b/IPython/nbconvert/exporters/markdown.py index 6a888ae..220b3ea 100644 --- a/IPython/nbconvert/exporters/markdown.py +++ b/IPython/nbconvert/exporters/markdown.py @@ -26,9 +26,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' diff --git a/IPython/nbconvert/exporters/python.py b/IPython/nbconvert/exporters/python.py index b5a4293..cd3880d 100644 --- a/IPython/nbconvert/exporters/python.py +++ b/IPython/nbconvert/exporters/python.py @@ -24,9 +24,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' diff --git a/IPython/nbconvert/exporters/rst.py b/IPython/nbconvert/exporters/rst.py index e401c99..3f7704e 100644 --- a/IPython/nbconvert/exporters/rst.py +++ b/IPython/nbconvert/exporters/rst.py @@ -26,9 +26,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' diff --git a/IPython/nbconvert/exporters/slides.py b/IPython/nbconvert/exporters/slides.py index 1a4ebec..428c7f4 100644 --- a/IPython/nbconvert/exporters/slides.py +++ b/IPython/nbconvert/exporters/slides.py @@ -26,15 +26,13 @@ from .html import HTMLExporter 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): diff --git a/IPython/nbconvert/exporters/templateexporter.py b/IPython/nbconvert/exporters/templateexporter.py index e127ab9..f68bfea 100644 --- a/IPython/nbconvert/exporters/templateexporter.py +++ b/IPython/nbconvert/exporters/templateexporter.py @@ -173,15 +173,12 @@ class TemplateExporter(Exporter): # 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: diff --git a/IPython/nbconvert/templates/latex/latex_article.tplx b/IPython/nbconvert/templates/latex/article.tplx similarity index 100% rename from IPython/nbconvert/templates/latex/latex_article.tplx rename to IPython/nbconvert/templates/latex/article.tplx diff --git a/IPython/nbconvert/templates/latex/latex_base.tplx b/IPython/nbconvert/templates/latex/base.tplx similarity index 100% rename from IPython/nbconvert/templates/latex/latex_base.tplx rename to IPython/nbconvert/templates/latex/base.tplx diff --git a/IPython/nbconvert/templates/latex/latex_report.tplx b/IPython/nbconvert/templates/latex/report.tplx similarity index 100% rename from IPython/nbconvert/templates/latex/latex_report.tplx rename to IPython/nbconvert/templates/latex/report.tplx diff --git a/IPython/nbconvert/templates/latex/style_bw_ipython.tplx b/IPython/nbconvert/templates/latex/style_bw_ipython.tplx index 3df4556..84859ab 100644 --- a/IPython/nbconvert/templates/latex/style_bw_ipython.tplx +++ b/IPython/nbconvert/templates/latex/style_bw_ipython.tplx @@ -1,6 +1,6 @@ ((= Black&white ipython input/output style =)) -((*- extends 'latex_base.tplx' -*)) +((*- extends 'base.tplx' -*)) %=============================================================================== % Input diff --git a/IPython/nbconvert/templates/latex/style_bw_python.tplx b/IPython/nbconvert/templates/latex/style_bw_python.tplx index 5371025..e10d4a2 100644 --- a/IPython/nbconvert/templates/latex/style_bw_python.tplx +++ b/IPython/nbconvert/templates/latex/style_bw_python.tplx @@ -1,6 +1,6 @@ ((= Black&white Python input/output style =)) -((*- extends 'latex_base.tplx' -*)) +((*- extends 'base.tplx' -*)) %=============================================================================== % Input diff --git a/IPython/nbconvert/templates/latex/style_ipython.tplx b/IPython/nbconvert/templates/latex/style_ipython.tplx index 77bc0b9..7799d18 100644 --- a/IPython/nbconvert/templates/latex/style_ipython.tplx +++ b/IPython/nbconvert/templates/latex/style_ipython.tplx @@ -1,6 +1,6 @@ ((= IPython input/output style =)) -((*- extends 'latex_base.tplx' -*)) +((*- extends 'base.tplx' -*)) % Custom definitions ((* block definitions *)) diff --git a/IPython/nbconvert/templates/latex/style_python.tplx b/IPython/nbconvert/templates/latex/style_python.tplx index f6f6e87..f950af9 100644 --- a/IPython/nbconvert/templates/latex/style_python.tplx +++ b/IPython/nbconvert/templates/latex/style_python.tplx @@ -1,6 +1,6 @@ ((= Python input/output style =)) -((*- extends 'latex_base.tplx' -*)) +((*- extends 'base.tplx' -*)) % Custom definitions ((* block definitions *))