##// END OF EJS Templates
Merge pull request #4727 from takluyver/nbconvert-template-magic...
Min RK -
r14065:902758e2 merge
parent child Browse files
Show More
@@ -12,7 +12,7 b''
12 # Imports
12 # Imports
13 #-----------------------------------------------------------------------------
13 #-----------------------------------------------------------------------------
14
14
15 from IPython.utils.traitlets import Unicode, List
15 import os
16
16
17 from IPython.nbconvert import preprocessors
17 from IPython.nbconvert import preprocessors
18 from IPython.config import Config
18 from IPython.config import Config
@@ -31,17 +31,14 b' class HTMLExporter(TemplateExporter):'
31 filters, just change the 'template_file' config option.
31 filters, just change the 'template_file' config option.
32 """
32 """
33
33
34 file_extension = Unicode(
34 def _file_extension_default(self):
35 'html', config=True,
35 return 'html'
36 help="Extension of the file that should be written to disk"
37 )
38
36
39 mime_type = Unicode('text/html', config=True,
37 def _default_template_path_default(self):
40 help="MIME type of the result file, for HTTP response headers."
38 return os.path.join("..", "templates", "html")
41 )
42
39
43 default_template = Unicode('full', config=True, help="""Flavor of the data
40 def _template_file_default(self):
44 format to use. I.E. 'full' or 'basic'""")
41 return 'full'
45
42
46 output_mimetype = 'text/html'
43 output_mimetype = 'text/html'
47
44
@@ -16,7 +16,7 b''
16 import os
16 import os
17
17
18 # IPython imports
18 # IPython imports
19 from IPython.utils.traitlets import Unicode, List
19 from IPython.utils.traitlets import Unicode
20 from IPython.config import Config
20 from IPython.config import Config
21
21
22 from IPython.nbconvert import filters, preprocessors
22 from IPython.nbconvert import filters, preprocessors
@@ -35,22 +35,19 b' class LatexExporter(TemplateExporter):'
35 'template_file' config option. Place your template in the special "/latex"
35 'template_file' config option. Place your template in the special "/latex"
36 subfolder of the "../templates" folder.
36 subfolder of the "../templates" folder.
37 """
37 """
38
39 file_extension = Unicode(
40 'tex', config=True,
41 help="Extension of the file that should be written to disk")
42
38
43 default_template = Unicode('article', config=True, help="""Template of the
39 def _file_extension_default(self):
44 data format to use. I.E. 'article' or 'report'""")
40 return 'tex'
41
42 def _template_file_default(self):
43 return 'article'
45
44
46 #Latex constants
45 #Latex constants
47 default_template_path = Unicode(
46 def _default_template_path_default(self):
48 os.path.join("..", "templates", "latex"), config=True,
47 return os.path.join("..", "templates", "latex")
49 help="Path where the template files are located.")
50
48
51 template_skeleton_path = Unicode(
49 def _template_skeleton_path_default(self):
52 os.path.join("..", "templates", "latex", "skeleton"), config=True,
50 return os.path.join("..", "templates", "latex", "skeleton")
53 help="Path where the template skeleton files are located.")
54
51
55 #Special Jinja2 syntax that will not conflict when exporting latex.
52 #Special Jinja2 syntax that will not conflict when exporting latex.
56 jinja_comment_block_start = Unicode("((=", config=True)
53 jinja_comment_block_start = Unicode("((=", config=True)
@@ -13,7 +13,6 b''
13 #-----------------------------------------------------------------------------
13 #-----------------------------------------------------------------------------
14
14
15 from IPython.config import Config
15 from IPython.config import Config
16 from IPython.utils.traitlets import Unicode
17
16
18 from .templateexporter import TemplateExporter
17 from .templateexporter import TemplateExporter
19
18
@@ -26,9 +25,11 b' class MarkdownExporter(TemplateExporter):'
26 Exports to a markdown document (.md)
25 Exports to a markdown document (.md)
27 """
26 """
28
27
29 file_extension = Unicode(
28 def _file_extension_default(self):
30 'md', config=True,
29 return 'md'
31 help="Extension of the file that should be written to disk")
30
31 def _template_file_default(self):
32 return 'markdown'
32
33
33 output_mimetype = 'text/markdown'
34 output_mimetype = 'text/markdown'
34
35
@@ -12,8 +12,6 b''
12 # Imports
12 # Imports
13 #-----------------------------------------------------------------------------
13 #-----------------------------------------------------------------------------
14
14
15 from IPython.utils.traitlets import Unicode
16
17 from .templateexporter import TemplateExporter
15 from .templateexporter import TemplateExporter
18
16
19 #-----------------------------------------------------------------------------
17 #-----------------------------------------------------------------------------
@@ -24,9 +22,10 b' class PythonExporter(TemplateExporter):'
24 """
22 """
25 Exports a Python code file.
23 Exports a Python code file.
26 """
24 """
27
25 def _file_extension_default(self):
28 file_extension = Unicode(
26 return 'py'
29 'py', config=True,
27
30 help="Extension of the file that should be written to disk")
28 def _template_file_default(self):
29 return 'python'
31
30
32 output_mimetype = 'text/x-python'
31 output_mimetype = 'text/x-python'
@@ -12,7 +12,6 b''
12 # Imports
12 # Imports
13 #-----------------------------------------------------------------------------
13 #-----------------------------------------------------------------------------
14
14
15 from IPython.utils.traitlets import Unicode
16 from IPython.config import Config
15 from IPython.config import Config
17
16
18 from .templateexporter import TemplateExporter
17 from .templateexporter import TemplateExporter
@@ -26,9 +25,11 b' class RSTExporter(TemplateExporter):'
26 Exports restructured text documents.
25 Exports restructured text documents.
27 """
26 """
28
27
29 file_extension = Unicode(
28 def _file_extension_default(self):
30 'rst', config=True,
29 return 'rst'
31 help="Extension of the file that should be written to disk")
30
31 def _template_file_default(self):
32 return 'rst'
32
33
33 output_mimetype = 'text/restructuredtext'
34 output_mimetype = 'text/restructuredtext'
34
35
@@ -12,8 +12,6 b''
12 # Imports
12 # Imports
13 #-----------------------------------------------------------------------------
13 #-----------------------------------------------------------------------------
14
14
15 from IPython.utils.traitlets import Unicode
16
17 from IPython.nbconvert import preprocessors
15 from IPython.nbconvert import preprocessors
18 from IPython.config import Config
16 from IPython.config import Config
19
17
@@ -26,15 +24,13 b' from .html import HTMLExporter'
26 class SlidesExporter(HTMLExporter):
24 class SlidesExporter(HTMLExporter):
27 """Exports HTML slides with reveal.js"""
25 """Exports HTML slides with reveal.js"""
28
26
29 file_extension = Unicode(
27 def _file_extension_default(self):
30 'slides.html', config=True,
28 return 'slides.html'
31 help="Extension of the file that should be written to disk"
32 )
33
29
34 output_mimetype = 'text/html'
30 def _template_file_default(self):
31 return 'slides_reveal'
35
32
36 default_template = Unicode('reveal', config=True, help="""Template of the
33 output_mimetype = 'text/html'
37 data format to use. I.E. 'reveal'""")
38
34
39 @property
35 @property
40 def default_config(self):
36 def default_config(self):
@@ -173,15 +173,12 b' class TemplateExporter(Exporter):'
173 # template by name with extension added, then try loading the template
173 # template by name with extension added, then try loading the template
174 # as if the name is explicitly specified, then try the name as a
174 # as if the name is explicitly specified, then try the name as a
175 # 'flavor', and lastly just try to load the template by module name.
175 # 'flavor', and lastly just try to load the template by module name.
176 module_name = self.__module__.rsplit('.', 1)[-1]
177 try_names = []
176 try_names = []
178 if self.template_file:
177 if self.template_file:
179 try_names.extend([
178 try_names.extend([
180 self.template_file + self.template_extension,
179 self.template_file + self.template_extension,
181 self.template_file,
180 self.template_file,
182 module_name + '_' + self.template_file + self.template_extension,
183 ])
181 ])
184 try_names.append(module_name + self.template_extension)
185 for try_name in try_names:
182 for try_name in try_names:
186 self.log.debug("Attempting to load template %s", try_name)
183 self.log.debug("Attempting to load template %s", try_name)
187 try:
184 try:
@@ -47,5 +47,5 b' class TestSlidesExporter(ExportersTestsBase):'
47 """
47 """
48 Can a SlidesExporter export using the 'reveal' template?
48 Can a SlidesExporter export using the 'reveal' template?
49 """
49 """
50 (output, resources) = SlidesExporter(template_file='reveal').from_filename(self._get_notebook())
50 (output, resources) = SlidesExporter(template_file='slides_reveal').from_filename(self._get_notebook())
51 assert len(output) > 0
51 assert len(output) > 0
1 NO CONTENT: file renamed from IPython/nbconvert/templates/html_basic.tpl to IPython/nbconvert/templates/html/basic.tpl
NO CONTENT: file renamed from IPython/nbconvert/templates/html_basic.tpl to IPython/nbconvert/templates/html/basic.tpl
@@ -1,4 +1,4 b''
1 {%- extends 'html_basic.tpl' -%}
1 {%- extends 'basic.tpl' -%}
2
2
3
3
4 {%- block header -%}
4 {%- block header -%}
@@ -67,4 +67,4 b' init_mathjax();'
67
67
68 {% block footer %}
68 {% block footer %}
69 </html>
69 </html>
70 {% endblock footer %} No newline at end of file
70 {% endblock footer %}
@@ -1,4 +1,4 b''
1 {%- extends 'html_basic.tpl' -%}
1 {%- extends 'basic.tpl' -%}
2
2
3
3
4 {%- block any_cell scoped -%}
4 {%- block any_cell scoped -%}
1 NO CONTENT: file renamed from IPython/nbconvert/templates/reveal_internals/slides.tpl to IPython/nbconvert/templates/html/reveal_internals/slides.tpl
NO CONTENT: file renamed from IPython/nbconvert/templates/reveal_internals/slides.tpl to IPython/nbconvert/templates/html/reveal_internals/slides.tpl
1 NO CONTENT: file renamed from IPython/nbconvert/templates/reveal_internals/subslides.tpl to IPython/nbconvert/templates/html/reveal_internals/subslides.tpl
NO CONTENT: file renamed from IPython/nbconvert/templates/reveal_internals/subslides.tpl to IPython/nbconvert/templates/html/reveal_internals/subslides.tpl
1 NO CONTENT: file renamed from IPython/nbconvert/templates/slides_reveal.tpl to IPython/nbconvert/templates/html/slides_reveal.tpl
NO CONTENT: file renamed from IPython/nbconvert/templates/slides_reveal.tpl to IPython/nbconvert/templates/html/slides_reveal.tpl
1 NO CONTENT: file renamed from IPython/nbconvert/templates/latex/latex_article.tplx to IPython/nbconvert/templates/latex/article.tplx
NO CONTENT: file renamed from IPython/nbconvert/templates/latex/latex_article.tplx to IPython/nbconvert/templates/latex/article.tplx
1 NO CONTENT: file renamed from IPython/nbconvert/templates/latex/latex_base.tplx to IPython/nbconvert/templates/latex/base.tplx
NO CONTENT: file renamed from IPython/nbconvert/templates/latex/latex_base.tplx to IPython/nbconvert/templates/latex/base.tplx
1 NO CONTENT: file renamed from IPython/nbconvert/templates/latex/latex_report.tplx to IPython/nbconvert/templates/latex/report.tplx
NO CONTENT: file renamed from IPython/nbconvert/templates/latex/latex_report.tplx to IPython/nbconvert/templates/latex/report.tplx
@@ -1,6 +1,6 b''
1 ((= Black&white ipython input/output style =))
1 ((= Black&white ipython input/output style =))
2
2
3 ((*- extends 'latex_base.tplx' -*))
3 ((*- extends 'base.tplx' -*))
4
4
5 %===============================================================================
5 %===============================================================================
6 % Input
6 % Input
@@ -1,6 +1,6 b''
1 ((= Black&white Python input/output style =))
1 ((= Black&white Python input/output style =))
2
2
3 ((*- extends 'latex_base.tplx' -*))
3 ((*- extends 'base.tplx' -*))
4
4
5 %===============================================================================
5 %===============================================================================
6 % Input
6 % Input
@@ -1,6 +1,6 b''
1 ((= IPython input/output style =))
1 ((= IPython input/output style =))
2
2
3 ((*- extends 'latex_base.tplx' -*))
3 ((*- extends 'base.tplx' -*))
4
4
5 % Custom definitions
5 % Custom definitions
6 ((* block definitions *))
6 ((* block definitions *))
@@ -1,6 +1,6 b''
1 ((= Python input/output style =))
1 ((= Python input/output style =))
2
2
3 ((*- extends 'latex_base.tplx' -*))
3 ((*- extends 'base.tplx' -*))
4
4
5 % Custom definitions
5 % Custom definitions
6 ((* block definitions *))
6 ((* block definitions *))
@@ -135,7 +135,7 b' class TestNbConvertApp(TestsBase):'
135 """
135 """
136 with self.create_temp_cwd(['notebook2.ipynb']):
136 with self.create_temp_cwd(['notebook2.ipynb']):
137 self.call('nbconvert --log-level 0 --to slides '
137 self.call('nbconvert --log-level 0 --to slides '
138 'notebook2.ipynb --template reveal')
138 'notebook2.ipynb')
139 assert os.path.isfile('notebook2.slides.html')
139 assert os.path.isfile('notebook2.slides.html')
140 with open('notebook2.slides.html') as f:
140 with open('notebook2.slides.html') as f:
141 assert '/reveal.css' in f.read()
141 assert '/reveal.css' in f.read()
@@ -146,6 +146,11 b' def find_package_data():'
146
146
147 os.chdir(os.path.join('tests',))
147 os.chdir(os.path.join('tests',))
148 js_tests = glob('casperjs/*.*') + glob('casperjs/*/*')
148 js_tests = glob('casperjs/*.*') + glob('casperjs/*/*')
149
150 os.chdir(os.path.join(cwd, 'IPython', 'nbconvert'))
151 nbconvert_templates = [os.path.join(dirpath, '*.*')
152 for dirpath, _, _ in os.walk('templates')]
153
149 os.chdir(cwd)
154 os.chdir(cwd)
150
155
151 package_data = {
156 package_data = {
@@ -157,10 +162,8 b' def find_package_data():'
157 'IPython.html' : ['templates/*'] + static_data,
162 'IPython.html' : ['templates/*'] + static_data,
158 'IPython.html.tests' : js_tests,
163 'IPython.html.tests' : js_tests,
159 'IPython.qt.console' : ['resources/icon/*.svg'],
164 'IPython.qt.console' : ['resources/icon/*.svg'],
160 'IPython.nbconvert' : ['templates/*.tpl', 'templates/latex/*.tplx',
165 'IPython.nbconvert' : nbconvert_templates +
161 'templates/latex/skeleton/*.tplx', 'templates/skeleton/*',
166 ['tests/files/*.*', 'exporters/tests/files/*.*'],
162 'templates/reveal_internals/*.tpl', 'tests/files/*.*',
163 'exporters/tests/files/*.*'],
164 'IPython.nbformat' : ['tests/*.ipynb']
167 'IPython.nbformat' : ['tests/*.ipynb']
165 }
168 }
166 return package_data
169 return package_data
General Comments 0
You need to be logged in to leave comments. Login now