Skip to content

Commit

Permalink
Merge pull request #45 from apiad/feature/better-verticals
Browse files Browse the repository at this point in the history
Feature/better verticals
  • Loading branch information
apiad authored Jan 1, 2020
2 parents 4984691 + e01bd36 commit 3f0f3ae
Show file tree
Hide file tree
Showing 13 changed files with 223 additions and 243 deletions.
5 changes: 4 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
[<img alt="Gitter" src="https://img.shields.io/gitter/room/apiad/auditorium">](https://gitter.im/auditorium-slides/community)
[<img alt="Demo" src="https://img.shields.io/badge/demo-browse-blueviolet"></img>](https://auditorium-demo.apiad.net)

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

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

## Quick Start and Tutorials

If you want to quickly grok `auditorium`, the best option is to [look at the demo online](https://auditorium-demo.apiad.net) and then
[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.

* [Authoring a slideshow with Python](https://apiad.net/auditorium/quickstart/#python-first)
* [Authoring a slideshow with Markdown](https://apiad.net/auditorium/quickstart/#markdown-first)
* [Rendering a slideshow as purely static HTML](https://apiad.net/auditorium/quickstart/#going-full-static)
Expand Down
158 changes: 81 additions & 77 deletions auditorium/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,39 +212,41 @@ def vertical_slides(ctx):
with ctx.warning(ctx):
ctx.markdown("Press `DOWN` instead of `LEFT` or click the down arrow.")

@show.slide
def vertical_code(ctx):
"""
## Vertical Slides: Code
"""

ctx.code(
"""
@show.slide
def main_slide(ctx):
# content of main slide
@vertical_slides.slide
def vertical_code(ctx):
"""
## Vertical Slides: Code
"""

@show.slide
def vertical_1(ctx):
# content of first vertical slide
ctx.code(
"""
@show.slide
def main_slide(ctx):
# content of main slide
@show.slide
def vertical_2(ctx):
# content of first vertical slide
"""
)
@main_slide.slide
def vertical_1(ctx):
# content of first vertical slide
@show.slide
def vertical_more(ctx):
@main_slide.slide
def vertical_2(ctx):
# content of first vertical slide
"""
### Vertical Slides: More Info
)

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

Show will go down and left automatically as necessary.
"""
@vertical_slides.slide
def vertical_more(ctx):
"""
### Vertical Slides: More Info
If you press `SPACE` instead of `LEFT` or `DOWN`
the slideshow will cycle through **all** of the slides
in order, including vertical slides.
Show will go down and left automatically as necessary.
"""


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

@show.slide
def blocks_code(ctx):
"""
## Blocks: Code
"""

ctx.code(
"""
with ctx.block('Standard block'):
ctx.markdown("And its content...")
@blocks.slide
def blocks_code(ctx):
"""
## Blocks: Code
"""

with ctx.success('Success block'):
ctx.markdown("For happy endings...")
ctx.code(
"""
with ctx.block('Standard block'):
ctx.markdown("And its content...")
with ctx.warning('Warning block'):
ctx.markdown("For hairy stuff...")
with ctx.success('Success block'):
ctx.markdown("For happy endings...")
with ctx.error('Error block'):
ctx.markdown("When nothing works...")
"""
)
with ctx.warning('Warning block'):
ctx.markdown("For hairy stuff...")
with ctx.error('Error block'):
ctx.markdown("When nothing works...")
"""
)


@show.slide
Expand All @@ -314,24 +317,25 @@ def fragments(ctx):
"""
)

@show.slide
def fragment_examples(ctx):
"""
## Fragment examples

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

with ctx.fragment(style):
ctx.markdown(f"`{style}`")
with ctx.columns(3) as cl:
for i, style in enumerate(
"grow shrink fade-in fade-out fade-up fade-down fade-left \
fade-right highlight-blue highlight-red highlight-green".split()
):
if i > 0 and i % 4 == 0:
cl.tab()

with ctx.fragment(style):
ctx.markdown(f"`{style}`")


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

@show.slide
def pyplot_code(ctx):
"""### Pyplot: Code"""
@pyplot.slide
def pyplot_code(ctx):
"""### Pyplot: Code"""

ctx.code(
"""
xg = np.random.RandomState(0)
yg = np.random.RandomState(1)
with ctx.animation(steps=60, time=0.5, loop=True) as anim:
x = xg.uniform(size=anim.current * 50)
y = yg.uniform(size=anim.current * 50)
colors = ['green' if xi ** 2 + yi ** 2 < 1 else 'orange'
for (xi, yi) in zip(x,y)]
plt.scatter(x, y, s=3, c=colors)
plt.ylim(0, 1)
plt.xlim(0, 1)
ctx.pyplot(plt, fmt='png', height=350)
"""
)
ctx.code(
"""
xg = np.random.RandomState(0)
yg = np.random.RandomState(1)
with ctx.animation(steps=60, time=0.5, loop=True) as anim:
x = xg.uniform(size=anim.current * 50)
y = yg.uniform(size=anim.current * 50)
colors = ['green' if xi ** 2 + yi ** 2 < 1 else 'orange'
for (xi, yi) in zip(x,y)]
plt.scatter(x, y, s=3, c=colors)
plt.ylim(0, 1)
plt.xlim(0, 1)
ctx.pyplot(plt, fmt='png', height=350)
"""
)


@show.slide
Expand Down
36 changes: 23 additions & 13 deletions auditorium/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,30 +146,40 @@ def wrapper(func):

return wrapper

def _wrap(self, func, id):
@staticmethod
def _vertical_slide_wrapper(show, section):
class _VerticalWrapper:
def __init__(self, section):
self.section = section

def slide(self, func=None, id=None):
if func is not None:
return show._wrap(func, id, self.section)

elif id is not None:

def wrapper(func):
return show._wrap(func, id, self.section)

return wrapper

return _VerticalWrapper(section)

def _wrap(self, func, id, section=None):
if self._rendering:
return func

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

if self._current_section is None:
# We are at the top level, this a regular slide
if section is None:
section = Section()
section.add_slide(slide)

self._sections.append(section)
self._current_section = section

# recursively build this slide (just once)
# to reach the vertical slides
slide.run(ShowMode.Markup)

self._current_section = None
wrapper = Show._vertical_slide_wrapper(self, section)
func.slide = wrapper.slide
else:
# We are inside a slide, this a vertical slide
section = self._current_section
section.add_slide(slide)

return func
Expand Down
52 changes: 1 addition & 51 deletions demo/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,54 +18,4 @@ See the demo at [auditorium-demo.apiad.net](https://auditorium-demo.apiad.net).

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.

In short, these are the basic steps:

1. Make sure your `slideshow.py` (or whatever the name) slideshow file has the following line:

```python
from auditorium import Show

show = Show("My Awesome Show")
app = show.app # <--- This line
```

This will allow `now.sh` serverless functions to find your slideshow's underlying `sanic` application, and automagically make the backend logic work.

2. Make a folder for uploading to `now.sh`, let's call it `my-show` and an `api` folder inside.

```bash
mkdir -p /path/to/my-show/api
```

3. Render the HTML.

```bash
auditorium render /path/to/slideshow.py > /path/to/my-show/index.html
```

4. Have your `slideshow.py` copied to `my-show/api/update.py`

```bash
cp /path/to/slideshow.py /path/to/my-show/api/update.py
```

5. Add a `now.json` file with an adequate configuration. This one works for the demo (replace `name` with your name):

```json
{
"name": "auditorium-demo",
"rewrites": [
{ "source": "/", "destination": "/index.html" },
{ "source": "/update", "destination": "/api/update" }
]
}
```

6. Add a `requirements.txt` file with your requirements. This one works for the demo:

```ini
auditorium # This is basically mandatory :)
matplotlib # Stuff you use in your slides
```

7. [Install](https://zeit.co/docs#install-now-cli) and run `now` inside the `my-show` folder.
For a full description [see the docs](https://apiad.net/auditorium/hosting/#hosting-a-slideshow-at-nowsh) about hosting at `now.sh`.
Loading

0 comments on commit 3f0f3ae

Please sign in to comment.