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