##// END OF EJS Templates
Fixed test and add fragments to the list of resets.
damianavila -
Show More
@@ -1,75 +1,75 b''
1 1 """Module that pre-processes the notebook for export via Reveal.
2 2 """
3 3 #-----------------------------------------------------------------------------
4 4 # Copyright (c) 2013, the IPython Development Team.
5 5 #
6 6 # Distributed under the terms of the Modified BSD License.
7 7 #
8 8 # The full license is in the file COPYING.txt, distributed with this software.
9 9 #-----------------------------------------------------------------------------
10 10
11 11 #-----------------------------------------------------------------------------
12 12 # Imports
13 13 #-----------------------------------------------------------------------------
14 14
15 15 from .base import Preprocessor
16 16 from IPython.utils.traitlets import Unicode
17 17
18 18 #-----------------------------------------------------------------------------
19 19 # Classes and functions
20 20 #-----------------------------------------------------------------------------
21 21
22 22 class RevealHelpPreprocessor(Preprocessor):
23 23
24 24 url_prefix = Unicode('reveal.js', config=True,
25 25 help="""The URL prefix for reveal.js.
26 26 This can be a a relative URL for a local copy of reveal.js,
27 27 or point to a CDN.
28 28
29 29 For speaker notes to work, a local reveal.js prefix must be used.
30 30 """
31 31 )
32 32
33 33 def preprocess(self, nb, resources):
34 34 """
35 35 Called once to 'preprocess' contents of the notebook.
36 36
37 37 Parameters
38 38 ----------
39 39 nb : NotebookNode
40 40 Notebook being converted
41 41 resources : dictionary
42 42 Additional resources used in the conversion process. Allows
43 43 preprocessors to pass variables into the Jinja engine.
44 44 """
45 45
46 46 for worksheet in nb.worksheets:
47 47 for index, cell in enumerate(worksheet.cells):
48 48
49 49 #Make sure the cell has slideshow metadata.
50 50 cell.metadata.slide_type = cell.get('metadata', {}).get('slideshow', {}).get('slide_type', '-')
51 51
52 52 #Get the slide type. If type is start of subslide or slide,
53 53 #end the last subslide/slide.
54 54 if cell.metadata.slide_type in ['slide']:
55 55 worksheet.cells[index - 1].metadata.slide_helper = 'slide_end'
56 56 if cell.metadata.slide_type in ['subslide']:
57 57 worksheet.cells[index - 1].metadata.slide_helper = 'subslide_end'
58 58 #Prevent the rendering of "do nothing" cells before fragments
59 59 #Group fragments passing frag_number to the data-fragment-index
60 60 if cell.metadata.slide_type in ['fragment']:
61 61 worksheet.cells[index].metadata.frag_number = index
62 62 i = 1
63 63 while i < len(worksheet.cells) - index:
64 64 worksheet.cells[index + i].metadata.frag_helper = 'fragment_end'
65 65 worksheet.cells[index + i].metadata.frag_number = index
66 66 i += 1
67 67 #Restart the slide_helper when the cell status is changed
68 #to "do nothing".
69 if cell.metadata.slide_type in ['-']:
68 #to other types.
69 if cell.metadata.slide_type in ['-', 'skip', 'notes', 'fragment']:
70 70 worksheet.cells[index - 1].metadata.slide_helper = '-'
71 71
72 72 if not isinstance(resources['reveal'], dict):
73 73 resources['reveal'] = {}
74 74 resources['reveal']['url_prefix'] = self.url_prefix
75 75 return nb, resources
@@ -1,93 +1,94 b''
1 1 """
2 2 Module with tests for the revealhelp preprocessor
3 3 """
4 4
5 5 #-----------------------------------------------------------------------------
6 6 # Copyright (c) 2013, the IPython Development Team.
7 7 #
8 8 # Distributed under the terms of the Modified BSD License.
9 9 #
10 10 # The full license is in the file COPYING.txt, distributed with this software.
11 11 #-----------------------------------------------------------------------------
12 12
13 13 #-----------------------------------------------------------------------------
14 14 # Imports
15 15 #-----------------------------------------------------------------------------
16 16
17 17 from IPython.nbformat import current as nbformat
18 18
19 19 from .base import PreprocessorTestsBase
20 20 from ..revealhelp import RevealHelpPreprocessor
21 21
22 22
23 23 #-----------------------------------------------------------------------------
24 24 # Class
25 25 #-----------------------------------------------------------------------------
26 26
27 27 class Testrevealhelp(PreprocessorTestsBase):
28 28 """Contains test functions for revealhelp.py"""
29 29
30 30 def build_notebook(self):
31 """Build a reveal slides notebook in memory for use with tests.
31 """Build a reveal slides notebook in memory for use with tests.
32 32 Overrides base in PreprocessorTestsBase"""
33 33
34 34 outputs = [nbformat.new_output(output_type="stream", stream="stdout", output_text="a")]
35
35
36 36 slide_metadata = {'slideshow' : {'slide_type': 'slide'}}
37 37 subslide_metadata = {'slideshow' : {'slide_type': 'subslide'}}
38 38
39 39 cells=[nbformat.new_code_cell(input="", prompt_number=1, outputs=outputs),
40 40 nbformat.new_text_cell('markdown', source="", metadata=slide_metadata),
41 41 nbformat.new_code_cell(input="", prompt_number=2, outputs=outputs),
42 42 nbformat.new_text_cell('markdown', source="", metadata=slide_metadata),
43 43 nbformat.new_text_cell('markdown', source="", metadata=subslide_metadata)]
44 44 worksheets = [nbformat.new_worksheet(name="worksheet1", cells=cells)]
45 45
46 46 return nbformat.new_notebook(name="notebook1", worksheets=worksheets)
47 47
48 48
49 49 def build_preprocessor(self):
50 50 """Make an instance of a preprocessor"""
51 51 preprocessor = RevealHelpPreprocessor()
52 52 preprocessor.enabled = True
53 53 return preprocessor
54 54
55 55
56 56 def test_constructor(self):
57 57 """Can a RevealHelpPreprocessor be constructed?"""
58 58 self.build_preprocessor()
59
59
60 60
61 61 def test_reveal_attribute(self):
62 62 """Make sure the reveal url_prefix resources is set"""
63 63 nb = self.build_notebook()
64 64 res = self.build_resources()
65 65 preprocessor = self.build_preprocessor()
66 66 nb, res = preprocessor(nb, res)
67 67 assert 'reveal' in res
68 68 assert 'url_prefix' in res['reveal']
69 69
70 70
71 71 def test_reveal_output(self):
72 72 """Make sure that the reveal preprocessor """
73 73 nb = self.build_notebook()
74 74 res = self.build_resources()
75 75 preprocessor = self.build_preprocessor()
76 76 nb, res = preprocessor(nb, res)
77 77 cells = nb.worksheets[0].cells
78 78
79 79 # Make sure correct metadata tags are available on every cell.
80 80 for cell in cells:
81 81 assert 'slide_type' in cell.metadata
82 82
83 83 # Make sure slide end is only applied to the cells preceeding slide
84 84 # cells.
85 assert 'slide_helper' not in cells[1].metadata
85 assert 'slide_helper' in cells[1].metadata
86 self.assertEqual(cells[1].metadata['slide_helper'], '-')
86 87
87 88 # Verify 'slide-end'
88 89 assert 'slide_helper' in cells[0].metadata
89 90 self.assertEqual(cells[0].metadata['slide_helper'], 'slide_end')
90 91 assert 'slide_helper' in cells[2].metadata
91 92 self.assertEqual(cells[2].metadata['slide_helper'], 'slide_end')
92 93 assert 'slide_helper' in cells[3].metadata
93 94 self.assertEqual(cells[3].metadata['slide_helper'], 'subslide_end')
General Comments 0
You need to be logged in to leave comments. Login now