Show More
@@ -1,93 +1,94 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 | import os |
|
16 | 16 | import urllib2 |
|
17 | 17 | |
|
18 | 18 | from .base import Transformer |
|
19 | 19 | from IPython.utils.traitlets import Unicode, Bool |
|
20 | 20 | |
|
21 | 21 | #----------------------------------------------------------------------------- |
|
22 | 22 | # Classes and functions |
|
23 | 23 | #----------------------------------------------------------------------------- |
|
24 | 24 | |
|
25 | 25 | class RevealHelpTransformer(Transformer): |
|
26 | 26 | |
|
27 | 27 | url_prefix = Unicode('//cdn.jsdelivr.net/reveal.js/2.4.0', |
|
28 | 28 | config=True, |
|
29 | 29 | help="""If you want to use a local reveal.js library, |
|
30 | 30 | use 'url_prefix':'reveal.js' in your config object.""") |
|
31 | 31 | |
|
32 |
speaker_notes = Bool(False, |
|
|
33 | If you want to use the speaker notes set | |
|
34 | 'speaker_notes':'True' in your config object.""") | |
|
32 | speaker_notes = Bool(False, | |
|
33 | config=True, | |
|
34 | help="""If you want to use the speaker notes | |
|
35 | set this to True.""") | |
|
35 | 36 | |
|
36 | 37 | def call(self, nb, resources): |
|
37 | 38 | """ |
|
38 | 39 | Called once to 'transform' contents of the notebook. |
|
39 | 40 | |
|
40 | 41 | Parameters |
|
41 | 42 | ---------- |
|
42 | 43 | nb : NotebookNode |
|
43 | 44 | Notebook being converted |
|
44 | 45 | resources : dictionary |
|
45 | 46 | Additional resources used in the conversion process. Allows |
|
46 | 47 | transformers to pass variables into the Jinja engine. |
|
47 | 48 | """ |
|
48 | 49 | |
|
49 | 50 | for worksheet in nb.worksheets : |
|
50 | 51 | for index, cell in enumerate(worksheet.cells): |
|
51 | 52 | |
|
52 | 53 | #Make sure the cell has slideshow metadata. |
|
53 | 54 | cell.metadata.align_type = cell.get('metadata', {}).get('slideshow', {}).get('align_type', 'Left') |
|
54 | 55 | cell.metadata.slide_type = cell.get('metadata', {}).get('slideshow', {}).get('slide_type', '-') |
|
55 | 56 | |
|
56 | 57 | #Get the slide type. If type is start of subslide or slide, |
|
57 | 58 | #end the last subslide/slide. |
|
58 | 59 | if cell.metadata.slide_type in ['slide']: |
|
59 | 60 | worksheet.cells[index - 1].metadata.slide_helper = 'slide_end' |
|
60 | 61 | if cell.metadata.slide_type in ['subslide']: |
|
61 | 62 | worksheet.cells[index - 1].metadata.slide_helper = 'subslide_end' |
|
62 | 63 | |
|
63 | 64 | |
|
64 | 65 | if 'reveal' not in resources: |
|
65 | 66 | resources['reveal'] = {} |
|
66 | 67 | resources['reveal']['url_prefix'] = self.url_prefix |
|
67 | 68 | resources['reveal']['notes_prefix'] = self.url_prefix |
|
68 | 69 | |
|
69 | 70 | cdn = 'http://cdn.jsdelivr.net/reveal.js/2.4.0' |
|
70 | 71 | local = 'local' |
|
71 | 72 | html_path = 'plugin/notes/notes.html' |
|
72 | 73 | js_path = 'plugin/notes/notes.js' |
|
73 | 74 | |
|
74 | 75 | html_infile = os.path.join(cdn, html_path) |
|
75 | 76 | js_infile = os.path.join(cdn, js_path) |
|
76 | 77 | html_outfile = os.path.join(local, html_path) |
|
77 | 78 | js_outfile = os.path.join(local, js_path) |
|
78 | 79 | |
|
79 | 80 | if self.speaker_notes: |
|
80 | 81 | if 'outputs' not in resources: |
|
81 | 82 | resources['outputs'] = {} |
|
82 | 83 | resources['outputs'][html_outfile] = self.notes_helper(html_infile) |
|
83 | 84 | resources['outputs'][js_outfile] = self.notes_helper(js_infile) |
|
84 | 85 | resources['reveal']['notes_prefix'] = local |
|
85 | 86 | |
|
86 | 87 | return nb, resources |
|
87 | 88 | |
|
88 | 89 | def notes_helper(self, infile): |
|
89 | 90 | """Helper function to get the content from an url.""" |
|
90 | 91 | |
|
91 | 92 | content = urllib2.urlopen(infile).read() |
|
92 | 93 | |
|
93 | 94 | return content |
General Comments 0
You need to be logged in to leave comments.
Login now