Skip to content

Commit 3f0f3ae

Browse files
authored
Merge pull request #45 from apiad/feature/better-verticals
Feature/better verticals
2 parents 4984691 + e01bd36 commit 3f0f3ae

13 files changed

+223
-243
lines changed

Readme.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
[<img alt="Gitter" src="https://img.shields.io/gitter/room/apiad/auditorium">](https://gitter.im/auditorium-slides/community)
99
[<img alt="Demo" src="https://img.shields.io/badge/demo-browse-blueviolet"></img>](https://auditorium-demo.apiad.net)
1010

11-
<img src="assets/logo.png"></img>
11+
<img src="https://apiad.net/auditorium/assets/logo.png"></img>
1212

1313
> A Python-powered slideshow creator with steroids.
1414
@@ -44,6 +44,9 @@ And point your browser at [localhost:6789](http://localhost:6789).
4444

4545
## Quick Start and Tutorials
4646

47+
If you want to quickly grok `auditorium`, the best option is to [look at the demo online](https://auditorium-demo.apiad.net) and then
48+
[read the source code](https://github.com/apiad/auditorium/blob/master/auditorium/demo.py). This way you will both see the end result and what effort it takes to get there.
49+
4750
* [Authoring a slideshow with Python](https://apiad.net/auditorium/quickstart/#python-first)
4851
* [Authoring a slideshow with Markdown](https://apiad.net/auditorium/quickstart/#markdown-first)
4952
* [Rendering a slideshow as purely static HTML](https://apiad.net/auditorium/quickstart/#going-full-static)

auditorium/demo.py

+81-77
Original file line numberDiff line numberDiff line change
@@ -212,39 +212,41 @@ def vertical_slides(ctx):
212212
with ctx.warning(ctx):
213213
ctx.markdown("Press `DOWN` instead of `LEFT` or click the down arrow.")
214214

215-
@show.slide
216-
def vertical_code(ctx):
217-
"""
218-
## Vertical Slides: Code
219-
"""
220215

221-
ctx.code(
222-
"""
223-
@show.slide
224-
def main_slide(ctx):
225-
# content of main slide
216+
@vertical_slides.slide
217+
def vertical_code(ctx):
218+
"""
219+
## Vertical Slides: Code
220+
"""
226221

227-
@show.slide
228-
def vertical_1(ctx):
229-
# content of first vertical slide
222+
ctx.code(
223+
"""
224+
@show.slide
225+
def main_slide(ctx):
226+
# content of main slide
230227
231-
@show.slide
232-
def vertical_2(ctx):
233-
# content of first vertical slide
234-
"""
235-
)
228+
@main_slide.slide
229+
def vertical_1(ctx):
230+
# content of first vertical slide
236231
237-
@show.slide
238-
def vertical_more(ctx):
232+
@main_slide.slide
233+
def vertical_2(ctx):
234+
# content of first vertical slide
239235
"""
240-
### Vertical Slides: More Info
236+
)
241237

242-
If you press `SPACE` instead of `LEFT` or `DOWN`
243-
the slideshow will cycle through **all** of the slides
244-
in order, including vertical slides.
245238

246-
Show will go down and left automatically as necessary.
247-
"""
239+
@vertical_slides.slide
240+
def vertical_more(ctx):
241+
"""
242+
### Vertical Slides: More Info
243+
244+
If you press `SPACE` instead of `LEFT` or `DOWN`
245+
the slideshow will cycle through **all** of the slides
246+
in order, including vertical slides.
247+
248+
Show will go down and left automatically as necessary.
249+
"""
248250

249251

250252
@show.slide
@@ -271,27 +273,28 @@ def blocks(ctx):
271273
with ctx.error("Error block"):
272274
ctx.markdown("When nothing works...")
273275

274-
@show.slide
275-
def blocks_code(ctx):
276-
"""
277-
## Blocks: Code
278-
"""
279276

280-
ctx.code(
281-
"""
282-
with ctx.block('Standard block'):
283-
ctx.markdown("And its content...")
277+
@blocks.slide
278+
def blocks_code(ctx):
279+
"""
280+
## Blocks: Code
281+
"""
284282

285-
with ctx.success('Success block'):
286-
ctx.markdown("For happy endings...")
283+
ctx.code(
284+
"""
285+
with ctx.block('Standard block'):
286+
ctx.markdown("And its content...")
287287
288-
with ctx.warning('Warning block'):
289-
ctx.markdown("For hairy stuff...")
288+
with ctx.success('Success block'):
289+
ctx.markdown("For happy endings...")
290290
291-
with ctx.error('Error block'):
292-
ctx.markdown("When nothing works...")
293-
"""
294-
)
291+
with ctx.warning('Warning block'):
292+
ctx.markdown("For hairy stuff...")
293+
294+
with ctx.error('Error block'):
295+
ctx.markdown("When nothing works...")
296+
"""
297+
)
295298

296299

297300
@show.slide
@@ -314,24 +317,25 @@ def fragments(ctx):
314317
"""
315318
)
316319

317-
@show.slide
318-
def fragment_examples(ctx):
319-
"""
320-
## Fragment examples
321320

322-
Here are some of the possible fragment animations.
323-
"""
321+
@fragments.slide
322+
def fragment_examples(ctx):
323+
"""
324+
## Fragment examples
324325
325-
with ctx.columns(3) as cl:
326-
for i, style in enumerate(
327-
"grow shrink fade-in fade-out fade-up fade-down fade-left \
328-
fade-right highlight-blue highlight-red highlight-green".split()
329-
):
330-
if i > 0 and i % 4 == 0:
331-
cl.tab()
326+
Here are some of the possible fragment animations.
327+
"""
332328

333-
with ctx.fragment(style):
334-
ctx.markdown(f"`{style}`")
329+
with ctx.columns(3) as cl:
330+
for i, style in enumerate(
331+
"grow shrink fade-in fade-out fade-up fade-down fade-left \
332+
fade-right highlight-blue highlight-red highlight-green".split()
333+
):
334+
if i > 0 and i % 4 == 0:
335+
cl.tab()
336+
337+
with ctx.fragment(style):
338+
ctx.markdown(f"`{style}`")
335339

336340

337341
@show.slide
@@ -378,26 +382,26 @@ def pyplot(ctx):
378382
% (4 * colors.count("green") / len(x) if len(x) > 0 else 0)
379383
)
380384

381-
@show.slide
382-
def pyplot_code(ctx):
383-
"""### Pyplot: Code"""
385+
@pyplot.slide
386+
def pyplot_code(ctx):
387+
"""### Pyplot: Code"""
384388

385-
ctx.code(
386-
"""
387-
xg = np.random.RandomState(0)
388-
yg = np.random.RandomState(1)
389-
390-
with ctx.animation(steps=60, time=0.5, loop=True) as anim:
391-
x = xg.uniform(size=anim.current * 50)
392-
y = yg.uniform(size=anim.current * 50)
393-
colors = ['green' if xi ** 2 + yi ** 2 < 1 else 'orange'
394-
for (xi, yi) in zip(x,y)]
395-
plt.scatter(x, y, s=3, c=colors)
396-
plt.ylim(0, 1)
397-
plt.xlim(0, 1)
398-
ctx.pyplot(plt, fmt='png', height=350)
399-
"""
400-
)
389+
ctx.code(
390+
"""
391+
xg = np.random.RandomState(0)
392+
yg = np.random.RandomState(1)
393+
394+
with ctx.animation(steps=60, time=0.5, loop=True) as anim:
395+
x = xg.uniform(size=anim.current * 50)
396+
y = yg.uniform(size=anim.current * 50)
397+
colors = ['green' if xi ** 2 + yi ** 2 < 1 else 'orange'
398+
for (xi, yi) in zip(x,y)]
399+
plt.scatter(x, y, s=3, c=colors)
400+
plt.ylim(0, 1)
401+
plt.xlim(0, 1)
402+
ctx.pyplot(plt, fmt='png', height=350)
403+
"""
404+
)
401405

402406

403407
@show.slide

auditorium/show.py

+23-13
Original file line numberDiff line numberDiff line change
@@ -146,30 +146,40 @@ def wrapper(func):
146146

147147
return wrapper
148148

149-
def _wrap(self, func, id):
149+
@staticmethod
150+
def _vertical_slide_wrapper(show, section):
151+
class _VerticalWrapper:
152+
def __init__(self, section):
153+
self.section = section
154+
155+
def slide(self, func=None, id=None):
156+
if func is not None:
157+
return show._wrap(func, id, self.section)
158+
159+
elif id is not None:
160+
161+
def wrapper(func):
162+
return show._wrap(func, id, self.section)
163+
164+
return wrapper
165+
166+
return _VerticalWrapper(section)
167+
168+
def _wrap(self, func, id, section=None):
150169
if self._rendering:
151170
return func
152171

153172
slide_id = id or func.__name__
154173
slide = Slide(slide_id, func, self)
155174
self._slides[slide_id] = slide
156175

157-
if self._current_section is None:
158-
# We are at the top level, this a regular slide
176+
if section is None:
159177
section = Section()
160178
section.add_slide(slide)
161-
162179
self._sections.append(section)
163-
self._current_section = section
164-
165-
# recursively build this slide (just once)
166-
# to reach the vertical slides
167-
slide.run(ShowMode.Markup)
168-
169-
self._current_section = None
180+
wrapper = Show._vertical_slide_wrapper(self, section)
181+
func.slide = wrapper.slide
170182
else:
171-
# We are inside a slide, this a vertical slide
172-
section = self._current_section
173183
section.add_slide(slide)
174184

175185
return func

demo/Readme.md

+1-51
Original file line numberDiff line numberDiff line change
@@ -18,54 +18,4 @@ See the demo at [auditorium-demo.apiad.net](https://auditorium-demo.apiad.net).
1818

1919
This folder shows the layout you need to comply with for hosting a slideshow at [now.sh](https://now.sh), such that the backend logic works as well. If you don't know what [now.sh](https://now.sh) is, go and [read about it](https://zeit.co/docs) first.
2020

21-
In short, these are the basic steps:
22-
23-
1. Make sure your `slideshow.py` (or whatever the name) slideshow file has the following line:
24-
25-
```python
26-
from auditorium import Show
27-
28-
show = Show("My Awesome Show")
29-
app = show.app # <--- This line
30-
```
31-
32-
This will allow `now.sh` serverless functions to find your slideshow's underlying `sanic` application, and automagically make the backend logic work.
33-
34-
2. Make a folder for uploading to `now.sh`, let's call it `my-show` and an `api` folder inside.
35-
36-
```bash
37-
mkdir -p /path/to/my-show/api
38-
```
39-
40-
3. Render the HTML.
41-
42-
```bash
43-
auditorium render /path/to/slideshow.py > /path/to/my-show/index.html
44-
```
45-
46-
4. Have your `slideshow.py` copied to `my-show/api/update.py`
47-
48-
```bash
49-
cp /path/to/slideshow.py /path/to/my-show/api/update.py
50-
```
51-
52-
5. Add a `now.json` file with an adequate configuration. This one works for the demo (replace `name` with your name):
53-
54-
```json
55-
{
56-
"name": "auditorium-demo",
57-
"rewrites": [
58-
{ "source": "/", "destination": "/index.html" },
59-
{ "source": "/update", "destination": "/api/update" }
60-
]
61-
}
62-
```
63-
64-
6. Add a `requirements.txt` file with your requirements. This one works for the demo:
65-
66-
```ini
67-
auditorium # This is basically mandatory :)
68-
matplotlib # Stuff you use in your slides
69-
```
70-
71-
7. [Install](https://zeit.co/docs#install-now-cli) and run `now` inside the `my-show` folder.
21+
For a full description [see the docs](https://apiad.net/auditorium/hosting/#hosting-a-slideshow-at-nowsh) about hosting at `now.sh`.

0 commit comments

Comments
 (0)