##// END OF EJS Templates
fix typo
Matthias BUSSONNIER -
Show More
@@ -1,236 +1,236 b''
1 1 """
2 2
3 3 """
4 4
5 5 from __future__ import print_function
6 6
7 7 from IPython.config.configurable import Configurable
8 8 from IPython.utils.traitlets import Unicode, Bool, Dict, List
9 9
10 10 class ConfigurableTransformers(Configurable):
11 11 """ A configurable transformer """
12 12
13 13 def __init__(self, config=None, **kw):
14 14 super(ConfigurableTransformers, self).__init__(config=config, **kw)
15 15
16 16 def __call__(self, nb, other):
17 17 try :
18 18 for worksheet in nb.worksheets :
19 19 for index, cell in enumerate(worksheet.cells):
20 20 worksheet.cells[index], other = self.cell_transform(cell, other, index)
21 21 return nb, other
22 22 except NotImplementedError as error :
23 23 raise NotImplementedError('should be implemented by subclass')
24 24
25 25 def cell_transform(self, cell, other, index):
26 26 """
27 27 Overwrite if you want to apply a transformation on each cell
28 28 """
29 29 raise NotImplementedError('should be implemented by subclass')
30 30
31 31
32 32 class Foobar(ConfigurableTransformers):
33 33 message = Unicode('-- nothing', config=True)
34 34
35 35
36 36 def cell_transform(self, cell, other, index):
37 37 return cell, other
38 38
39 39
40 40 def cell_preprocessor(function):
41 41 """ wrap a function to be executed on all cells of a notebook
42 42
43 43 wrapped function parameters :
44 44 cell : the cell
45 45 other : external resources
46 46 index : index of the cell
47 47 """
48 48 def wrappedfunc(nb, other):
49 49 for worksheet in nb.worksheets :
50 50 for index, cell in enumerate(worksheet.cells):
51 51 worksheet.cells[index], other = function(cell, other, index)
52 52 return nb, other
53 53 return wrappedfunc
54 54
55 55
56 56 @cell_preprocessor
57 57 def haspyout_transformer(cell, other, count):
58 58 """
59 59 Add a haspyout flag to cell that have it
60 60
61 61 Easier for templating, where you can't know in advance
62 62 wether to write the out prompt
63 63
64 64 """
65 65 cell.type = cell.cell_type
66 66 cell.haspyout = False
67 67 for out in cell.get('outputs', []):
68 68 if out.output_type == 'pyout':
69 69 cell.haspyout = True
70 70 break
71 71 return cell, other
72 72
73 73
74 74 # todo, make the key part configurable.
75 75
76 76 class ExtractFigureTransformer(ConfigurableTransformers):
77 77 enabled = Bool(False,
78 78 config=True,
79 79 help=""" If set to false, this transformer will be no-op """
80 80 )
81 81
82 82 extra_ext_map = Dict({},
83 83 config=True,
84 84 help="""extra map to override extension based on type.
85 85 Usefull for latex where svg will be converted to pdf before inclusion
86 86 """
87 87 )
88 88 display_data_priority = List(['html', 'pdf', 'svg', 'latex', 'png', 'jpg', 'jpeg' , 'text'],
89 89 config=True,
90 90 help= """
91 91 An ordered list of prefered output type, the first
92 92 encounterd will usually be used when converting discarding
93 93 the others.
94 94 """
95 95 )
96 96
97 97
98 98 #to do change this to .format {} syntax
99 99 key_tpl = Unicode('_fig_%02i.%s', config=True)
100 100
101 101 def _get_ext(self, ext):
102 102 if ext in self.extra_ext_map :
103 103 return self.extra_ext_map[ext]
104 104 return ext
105 105
106 106 def _new_figure(self, data, fmt, count):
107 107 """Create a new figure file in the given format.
108 108
109 109 Returns a path relative to the input file.
110 110 """
111 111 figname = self.key_tpl % (count, self._get_ext(fmt))
112 112 key = self.key_tpl % (count, fmt)
113 113
114 114 # Binary files are base64-encoded, SVG is already XML
115 115 if fmt in ('png', 'jpg', 'pdf'):
116 116 data = data.decode('base64')
117 117
118 118 return figname, key, data
119 119
120 120
121 121 def cell_transform(self, cell, other, count):
122 122 if not self.enabled:
123 123 return cell, other
124 124 if other.get('figures',None) is None :
125 125 other['figures']={}
126 126 for i, out in enumerate(cell.get('outputs', [])):
127 127 for type in self.display_data_priority:
128 128 if out.hasattr(type):
129 129 figname, key, data = self._new_figure(out[type], type, count)
130 130 out['key_'+type] = figname
131 131 other['figures'][key] = data
132 132 count = count+1
133 133 return cell, other
134 134
135 135 class RevealHelpTransformer(ConfigurableTransformers):
136 136
137 137 section_open = False
138 138 subsection_open = False
139 139 fragment_open = False
140 140
141 141 def open_subsection(self):
142 142 self.subsection_open = True
143 143 return True
144 144
145 145 def open_section(self):
146 146 self.section_open = True
147 147 return True
148 148
149 149 def open_fragment(self):
150 150 self.fragment_open = True
151 151 return True
152 152
153 153 # could probaly write those maybe_close/open
154 154 # with a function functor
155 155 def maybe_close_section(self):
156 156 """return True is already open, false otherwise
157 157 and change state to close
158 158 """
159 159 if self.section_open :
160 160 self.section_open = False
161 161 return True
162 162 else :
163 163 return False
164 164
165 165 def maybe_open_section(self):
166 166 """return True is already open, false otherwise
167 167 and change state to close
168 168 """
169 169 if not self.section_open :
170 170 self.section_open = True
171 171 return True
172 172 else :
173 173 return False
174 174
175 175 def maybe_open_subsection(self):
176 176 """return True is already open, false otherwise
177 177 and change state to close
178 178 """
179 179 if not self.subsection_open :
180 180 self.subsection_open = True
181 181 return True
182 182 else :
183 183 return False
184 184
185 185 def maybe_close_subsection(self):
186 186 """return True is already open, false otherwise
187 187 and change state to close
188 188 """
189 189 if self.subsection_open :
190 190 self.subsection_open = False
191 191 return True
192 192 else :
193 193 return False
194 194
195 195 def maybe_close_fragment(self):
196 196 """return True is already open, false otherwise
197 197 and change state to close
198 198 """
199 199 if self.fragment_open :
200 200 self.fragment_open = False
201 201 return True
202 202 else :
203 203 return False
204 204
205 205 def cell_transform(self, cell, other,count):
206 206 ctype = cell.metadata.get('slideshow',{}).get('slide_type',None)
207 if ctype is None :
207 if ctype in [None, '-'] :
208 208 cell.metadata.slideshow = {}
209 209 cell.metadata.slideshow['slide_type'] = None
210 210 elif ctype == 'fragment':
211 211 cell.metadata.slideshow.close_fragment = self.maybe_close_fragment()
212 212 cell.metadata.slideshow.close_subsection = False
213 213 cell.metadata.slideshow.close_section = False
214 214
215 215 cell.metadata.slideshow.open_section = self.maybe_open_section()
216 216 cell.metadata.slideshow.open_subsection = self.maybe_open_subsection()
217 217 cell.metadata.slideshow.open_fragment = self.open_fragment()
218 218
219 219 elif ctype == 'subslide':
220 220 cell.metadata.slideshow.close_fragment = self.maybe_close_fragment()
221 221 cell.metadata.slideshow.close_subsection = self.maybe_close_subsection()
222 222 cell.metadata.slideshow.close_section = False
223 223
224 224 cell.metadata.slideshow.open_section = self.maybe_open_section()
225 225 cell.metadata.slideshow.open_subsection = self.open_subsection()
226 226 cell.metadata.slideshow.open_fragment = False
227 227 elif ctype == 'slide':
228 228 cell.metadata.slideshow.close_fragment = self.maybe_close_fragment()
229 229 cell.metadata.slideshow.close_subsection = self.maybe_close_subsection()
230 230 cell.metadata.slideshow.close_section = self.maybe_close_section()
231 231
232 232 cell.metadata.slideshow.open_section = self.open_section()
233 233 cell.metadata.slideshow.open_subsection = self.open_subsection()
234 234 cell.metadata.slideshow.open_fragment = False
235 235 return cell,other
236 236
@@ -1,150 +1,150 b''
1 1 {%- extends 'basichtml.tpl' -%}
2 2
3 3
4 4 {% block any_cell -%}
5 5
6 6 {% if cell.metadata.slideshow.close_fragment %}
7 7 </div>
8 8 {% endif %}
9 9 {% if cell.metadata.slideshow.close_subsection %}
10 10 </section>
11 11 {% endif %}
12 12 {% if cell.metadata.slideshow.close_section %}
13 13 </section>
14 14 {% endif %}
15 15
16 16 {% if cell.metadata.slideshow.open_section %}
17 17 <section>
18 18 {%- endif %}
19 19 {% if cell.metadata.slideshow.open_subsection %}
20 20 <section>
21 21 {%- endif %}
22 22 {% if cell.metadata.slideshow.open_fragment %}
23 23 <div class='fragment'>
24 24 {% endif %}
25 25 {% if cell.metadata.slideshow.slide_type in ['notes'] %}
26 26 <aside class="notes">
27 27 {{ super() }}
28 28 </aside>
29 {% elif cell.metadata.slideshow.slide_tyle not in ['skip'] %}
29 {% elif cell.metadata.slideshow.slide_type not in ['skip'] %}
30 30 {{ super() }}
31 31 {% endif %}
32 32
33 33 {% endblock %}
34 34
35 35
36 36 {% block body %}
37 37 <body>
38 38 <div class="reveal"><div class="slides">
39 39 {{ super() }}
40 40 </section>
41 41 </section>
42 42 </div></div>
43 43
44 44 <script src="reveal/lib/js/head.min.js"></script>
45 45
46 46 <script src="reveal/js/reveal.min.js"></script>
47 47
48 48 <script>
49 49
50 50 // Full list of configuration options available here: https://github.com/hakimel/reveal.js#configuration
51 51 Reveal.initialize({
52 52 controls: true,
53 53 progress: true,
54 54 history: true,
55 55
56 56 theme: Reveal.getQueryHash().theme, // available themes are in /css/theme
57 57 transition: Reveal.getQueryHash().transition || 'linear', // default/cube/page/concave/zoom/linear/none
58 58
59 59 // Optional libraries used to extend on reveal.js
60 60 dependencies: [
61 61 { src: 'reveal/lib/js/classList.js', condition: function() { return !document.body.classList; } },
62 62 { src: 'reveal/plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } },
63 63 { src: 'reveal/plugin/zoom-js/zoom.js', async: true, condition: function() { return !!document.body.classList; } },
64 64 { src: 'notes/notes.js', async: true, condition: function() { return !!document.body.classList; } },
65 65 { src: 'https://c328740.ssl.cf1.rackcdn.com/mathjax/latest/MathJax.js?config=TeX-AMS_HTML', async: true },
66 66 { src: 'js/revealmathjax.js', async: true}
67 67 ]
68 68 });
69 69 </script>
70 70
71 71 <script>
72 72 Reveal.addEventListener( 'slidechanged', function( event ) {
73 73 MathJax.Hub.Rerender(event.currentSlide);
74 74 });
75 75 </script>
76 76 </body>
77 77 </html>{% endblock body %}
78 78
79 79
80 80
81 81
82 82 {% block header %}<!DOCTYPE html>
83 83 <html>
84 84 <head>
85 85
86 86 <meta charset="utf-8" />
87 87 <meta http-equiv="X-UA-Compatible" content="chrome=1">
88 88
89 89 <meta name="apple-mobile-web-app-capable" content="yes" />
90 90 <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
91 91
92 92 <link rel="stylesheet" href="reveal/css/reveal.css">
93 93 <link rel="stylesheet" href="reveal/css/theme/simple.css" id="theme">
94 94
95 95 <!-- For syntax highlighting -->
96 96 <link rel="stylesheet" href="reveal/lib/css/zenburn.css">
97 97
98 98 <!-- If the query includes 'print-pdf', use the PDF print sheet -->
99 99 <script>
100 100 document.write( '<link rel="stylesheet" href="reveal/css/print/' + ( window.location.search.match( /print-pdf/gi ) ? 'pdf' : 'paper' ) + '.css" type="text/css" media="print">' );
101 101 </script>
102 102
103 103 <!--[if lt IE 9]>
104 104 <script src="reveal/lib/js/html5shiv.js"></script>
105 105 <![endif]-->
106 106
107 107 {% for css in inlining.css -%}
108 108 <style type="text/css">
109 109 {{css}}
110 110 </style>
111 111 {% endfor %}
112 112
113 113 <style type="text/css">
114 114 /* Overrides of notebook CSS for static HTML export */
115 115
116 116 .reveal {
117 117 font-size: 20px;
118 118 }
119 119 .reveal pre {
120 120 width: 100%;
121 121 padding: 0.2em;
122 122 margin: 0px auto;
123 123 font-family: monospace, sans-serif;
124 124 font-size: 60%;
125 125 box-shadow: 0px 0px 0px rgba(0, 0, 0, 0);
126 126 }
127 127 .reveal section img {
128 128 border: 0px solid black;
129 129 box-shadow: 0 0 10px rgba(0, 0, 0, 0);
130 130 }
131 131 div.input_area {
132 132 padding: 0.2em;
133 133 }
134 134 div.code_cell {
135 135 background-color: transparent;
136 136 }
137 137 div.prompt {
138 138 width: 11ex;
139 139 padding: 0.0em;
140 140 margin: 0px;
141 141 font-family: monospace;
142 142 font-size: 60%;
143 143 text-align: center;
144 144 }
145 145 div.output_prompt {
146 146 /* 5px right shift to account for margin in parent container */
147 147 margin: 5px 5px 0 -5px;
148 148 }
149 149 </style>
150 150 </head>{% endblock %}
General Comments 0
You need to be logged in to leave comments. Login now