Skip to content

Commit d952e8b

Browse files
authored
Merge pull request #50 from apiad/develop
v20.2.1
2 parents bb33b10 + 01a836a commit d952e8b

13 files changed

+415
-33
lines changed

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2019 Alejandro Piad, <https://apiad.net> and contributors.
3+
Copyright (c) 2020 Alejandro Piad, <https://apiad.net> and contributors.
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

Readme.md

+2-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="https://apiad.net/auditorium/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
@@ -50,6 +50,7 @@ If you want to quickly grok `auditorium`, the best option is to [look at the dem
5050
* [Authoring a slideshow with Python](https://apiad.net/auditorium/quickstart/#python-first)
5151
* [Authoring a slideshow with Markdown](https://apiad.net/auditorium/quickstart/#markdown-first)
5252
* [Rendering a slideshow as purely static HTML](https://apiad.net/auditorium/quickstart/#going-full-static)
53+
* [Hosting a slideshow online for free](https://apiad.net/auditorium/hosting/#hosting-freely-with-auditorium-publish)
5354

5455
## Made with Auditorium
5556

auditorium/__main__.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import webbrowser
66

77
from auditorium import Show
8+
from auditorium.watcher import Watcher
89

910

1011
class Auditorium:
@@ -14,13 +15,17 @@ def run(
1415
*,
1516
host: str = "127.0.0.1",
1617
port: int = 6789,
17-
debug: bool = False,
18+
reload: bool = False,
1819
instance_name: str = "show",
1920
):
2021
"Runs a custom Python script as a slideshow."
2122

2223
show = Show.load(path, instance_name)
23-
show.run(host=host, port=port, debug=debug)
24+
25+
if reload:
26+
show = Watcher(path, instance_name)
27+
28+
show.run(host=host, port=port, debug=reload)
2429

2530
@staticmethod
2631
def publish(

auditorium/watcher.py

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import os, sys, time
2+
import asyncio
3+
import fire
4+
5+
6+
class Watcher:
7+
def __init__(self, files, callback=None):
8+
self.files = files
9+
self.callback = callback
10+
11+
def files_to_timestamp(self):
12+
return dict ([(f, os.path.getmtime(f)) for f in self.files])
13+
14+
async def run(self):
15+
before = self.files_to_timestamp()
16+
17+
while True:
18+
await asyncio.sleep(1)
19+
after = self.files_to_timestamp()
20+
21+
modified = []
22+
23+
for f in before.keys():
24+
if os.path.getmtime(f) != before.get(f):
25+
modified.append(f)
26+
27+
if modified: print('Modified: {}'.format(', '.join(modified)))
28+
29+
before = after
30+
31+
32+
if __name__ == "__main__":
33+
fire.Fire(Watcher)

docs/api/cli.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# The `auditorium` CLI
2+
3+
!!! warning
4+
This section is under construction. More content will be added shortly.

docs/api/context.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# The `Context` class
2+
3+
!!! warning
4+
This section is under construction. More content will be added shortly.

docs/api/show.md

+188
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
# The `Show` class
2+
3+
!!! warning
4+
This section is for advanced usage. Please read the [Quick Start](/quickstart/) guides first.
5+
6+
!!! note
7+
This section asumes a Python-first approach for simplicity.
8+
You can use all of `auditorium` features in a Markdown-first approach
9+
with [runnable code blocks](/quickstart/#markdown-first).
10+
11+
The `Show` class is the first class you will need to interact
12+
with when using `auditorium`. All your slideshows begin with something like:
13+
14+
```python
15+
from auditorium import Show
16+
17+
show = auditorium.Show("My Show Title")
18+
```
19+
20+
## Creating slides
21+
22+
The most important use of your `show` instance is the `@slide` decorator, which
23+
allows you to create slides. A slide is created by decorating a function (or actually any callable)
24+
with `@show.slide` like this:
25+
26+
```python
27+
@show.slide
28+
def first_slide(ctx):
29+
# content
30+
```
31+
32+
Everything that can be included **inside** a slide is discussed in the [Context](/api/context/) page.
33+
34+
!!! note
35+
Slides are sorted in the order in which they are declared in your Python script.
36+
37+
### Customizing slides
38+
39+
The `@slide` decorator can receive an optional parameter `id` to configure a specific slide.
40+
41+
```python
42+
@show.slide(id="the-first-slide")
43+
def first_slide(ctx):
44+
# content
45+
```
46+
47+
The slide identifier is used in HTML as anchor for that slide. Hence, when running
48+
the slideshow, the previous slide would be located at `http://localhost:6789/#/the-first-slide`.
49+
If no `id` is provided the slide identifier is built from the callable `__name__` parameter,
50+
hence in the previous example it would be located at `http://localhost:6789/#/first_slide`
51+
52+
!!! warning
53+
Note that when using additional parameters, you have to use the form `@show.slide(...)`
54+
with parenthesis, but when not using parameters, you can use the decorator directly as
55+
`@show.slide` without parenthesis.
56+
57+
Default slide ids are OK if you don't care about having those ugly underscores in your slide
58+
anchors in HTML. In any case, you can always author your slideshow first and then add
59+
pretty slide identifiers afterwards.
60+
61+
### Vertical slides
62+
63+
Vertical slides are an effective way to add "read-more" like content to a slideshow.
64+
You can see them in action at <https://auditorium-demo.apiad.net/#/vertical_slides>.
65+
66+
Vertical slides are added *after* a main slide, using a modified form of the `@slide` decorator.
67+
Instead of using `@show.slide` you use `@main_slide.slide` where `main_slide` is the actual
68+
function (or any other callable) that corresponds to the main slide.
69+
70+
```python
71+
@show.slide
72+
def main_slide(ctx):
73+
# This will be a regular slide
74+
75+
@main_slide.slide
76+
def vertical_1(ctx):
77+
# This one is vertical to `main_slide`
78+
79+
@show.slide
80+
def other_slide(ctx):
81+
# This one is another main slide
82+
83+
@other_slide.slide
84+
def vertical_2(ctx):
85+
# This one is vertical to `other_slide`
86+
87+
@other_slide.slide
88+
def vertical_3(ctx):
89+
# This one is also vertical to `other_slide`,
90+
# under the previous (`vertical_2`)
91+
```
92+
93+
!!! note
94+
Vertical slides can be declared at any moment *after* but not necesarily *under* the main slide.
95+
This allows you to organize all your main slides at the top of a script and then add vertical slides when
96+
you think is convenient.
97+
98+
## Running the show
99+
100+
Once all slides are in, you can run a show by calling directly the `show.run` method:
101+
102+
```python
103+
show.run('localhost', 6789)
104+
```
105+
106+
However, this method is actually **not recommended**. Instead it is *preferred* to use:
107+
108+
```bash
109+
auditorium run /path/to/myshow.py [--host HOST] [--port PORT]
110+
```
111+
112+
The second method is preferred because it is more aligned with other usages such as `auditorium publish`
113+
and, in the future, we will add a `--reload` option to allow hot-reload when you save your slideshow.
114+
115+
!!! error
116+
When calling `run` you can get an error like:
117+
118+
:::bash
119+
(!) You need `uvicorn` installed in order to call `run`.
120+
121+
This means you didn't installed `uvicorn` when installing `auditorium`, which is necessary
122+
for actually serving the HTML. You can fix it by installing like this:
123+
124+
pip install auditorium[server]
125+
126+
Serverless installations are smaller and useful if you only want to use `render` or `publish`,
127+
or [deploy to a serverless cloud provider](/hosting/#hosting-as-serverless-functions-at-nowsh).
128+
129+
## Rendering the show
130+
131+
You can obtain a static HTML with embedded resources ready to be served with:
132+
133+
```python
134+
static_html = show.render(theme="white")
135+
136+
with open("/path/to/myshow.html", "w") as fp:
137+
fp.write(static_html)
138+
```
139+
140+
The reason why `render` returns a `string` rather than saving to a file is because you could
141+
use this functionality in a serverless cloud provider or any other context where you cannot
142+
interact directly with path-based files. It's up to you how to make use of the rendered HTML.
143+
144+
That said, if you use the [CLI command](/api/cli) `render` you can achieve this more easily with:
145+
146+
```python
147+
auditorium render /path/to/myshow.py > /path/to/myshow.html
148+
```
149+
150+
## Loading a show
151+
152+
The static method `Show.load` takes in a path and loads the corresponding show instance.
153+
154+
```python
155+
show = Show.load("/path/to/show.py")
156+
```
157+
158+
It works with both Python (`myshow.py`) and Markdown (`myshow.md`) file extensions.
159+
It is useful in contexts where you can serve multiple slideshows, for example,
160+
in a server context where you want to map URL paths to specific shows.
161+
162+
After calling `load` you receive a `Show` instance with all it can do.
163+
164+
## Appending multiple shows
165+
166+
You can build a slideshow in parts, some in Python, some in Markdown, and then
167+
use `show.append` to connect them. It works with `Show` instances and path names as well.
168+
169+
```python
170+
show = Show("Main Show")
171+
# ... build show
172+
173+
# append another instance
174+
other_show = Show("Other show")
175+
# ... build other_show
176+
show.append(other_show)
177+
178+
# append by path
179+
show.append("/path/to/anothershow.py") # Python
180+
show.append("/path/to/anothershow.md") # Markdown
181+
```
182+
183+
This allows you to build a slideshow in parts. Maybe some slides are more
184+
convenient in Markdown-first mode because they are mostly static content,
185+
while a few specific slides are very tricky and it's better to code them in Python.
186+
187+
!!! warning
188+
This section is under construction. More content will be added shortly.

docs/hosting.md

+25-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Hosting your slideshow
22

33
If you are presenting on a big screen connected to your own computer, all you need to do is
4-
`auditorium run [file]`, and you can present from [localhost:6789](http://localhost:6789) as usual.
4+
`auditorium run`, and you can present from [localhost:6789](http://localhost:6789) as usual.
55

66
However, there are many cases where you are either not presenting from your computer, or you want
77
to host your slideshow publicly for others to follow. Here are some ideas.
@@ -12,7 +12,7 @@ If the audience can ping your computer, then the easiest solution to
1212
simply do:
1313

1414
```bash
15-
auditorium run [file] --host=0.0.0.0
15+
auditorium run /path/to/file --host=0.0.0.0
1616
```
1717
Then give them your public IP address. In Linux, run `ip addr` to see it.
1818

@@ -30,14 +30,15 @@ with a server that renders the slide and proxies all incoming requests back to y
3030
To use it, simple run:
3131

3232
```bash
33-
auditorium publish [file] --name [your-slideshow-name]
33+
auditorium publish /path/to/file --name [your-slideshow-name]
3434
```
3535

3636
Then head over to `http://auditorium.apiad.net/your-slideshow-name/` and enjoy!
3737

38-
> **NOTE:** This service is provided as-is with no guarantees whatsoever. The service runs
39-
> on a development server that is restarted often (at least twice a day), so slideshows are **not** guaranteed to stay
40-
> up for a long time. Don't use this service in mission critical presentations.
38+
!!! warning
39+
This service is provided as-is with no guarantees whatsoever. The service runs
40+
on a development server that is restarted often (at least twice a day), so slideshows are **not** guaranteed to stay
41+
up for a long time. Don't use this service in mission critical presentations.
4142

4243
If you need finer control then you can host the server yourself on your own infrastructure
4344
and thus ensure that it's online when you need it. Just run:
@@ -47,14 +48,29 @@ auditorium server [--host HOST] [--port PORT]
4748
```
4849

4950
Make sure the server is publicly accessible. You'll probably use some kind of web server,
50-
or `--host 0.0.0.0` and `--port 80` which you can totally do since `auditorium` ships
51+
or run it with `--host 0.0.0.0` and `--port 80`, which you can totally do since `auditorium` ships
5152
with `uvicorn` which is a fully fledged production web server.
5253
Then publish to your own address with:
5354

5455
```bash
55-
auditorium publish [file] --name [name] --server [ws://your-server:port] # or wss://
56+
auditorium publish /path/to/file --name [name] --server [ws://your-server:port] # or wss://
5657
```
5758

59+
!!! error
60+
When calling `server` you can get an error like:
61+
62+
:::bash
63+
(!) You need `uvicorn` installed in order to call `server`.
64+
65+
This means you didn't installed `uvicorn` when installing `auditorium`, which is necessary
66+
for actually serving the HTML. You can fix it by installing like this:
67+
68+
pip install auditorium[server]
69+
70+
Serverless installations are smaller and useful if you only want to use `render` or `publish`,
71+
or [deploy to a serverless cloud provider](/hosting/#hosting-as-serverless-functions-at-nowsh).
72+
73+
5874
## Hosting temporarily through `ngrok`
5975

6076
Another option is to use [`ngrok`](https://ngrok.com/).
@@ -80,7 +96,7 @@ The do have paid plans for securing a custom domain.
8096
If your slideshow is purely static, then you ran run:
8197

8298
```bash
83-
auditorium render [file] > index.html
99+
auditorium render /path/to/file > index.html
84100
```
85101

86102
Then upload the file to a Github repository.

docs/index.md

+2-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="https://apiad.net/auditorium/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
@@ -50,6 +50,7 @@ If you want to quickly grok `auditorium`, the best option is to [look at the dem
5050
* [Authoring a slideshow with Python](https://apiad.net/auditorium/quickstart/#python-first)
5151
* [Authoring a slideshow with Markdown](https://apiad.net/auditorium/quickstart/#markdown-first)
5252
* [Rendering a slideshow as purely static HTML](https://apiad.net/auditorium/quickstart/#going-full-static)
53+
* [Hosting a slideshow online for free](https://apiad.net/auditorium/hosting/#hosting-freely-with-auditorium-publish)
5354

5455
## Made with Auditorium
5556

docs/quickstart.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Quick Start
22

3+
This section provides quick hints for starting using `auditorium` right now. However,
4+
the best way to grok it is looking at the [demo](https://auditorium-demo.apiad.net).
5+
36
## Python First
47

58
In `auditorium` you create a presentation via the `Show` class:
@@ -148,3 +151,7 @@ auditorium render <file.[py|md]> > <output.html>
148151
```
149152

150153
This will render the slideshow in an HTML file with all CSS and JavaScript embedded. Just copy this single HTML file and open it on any browser. You won't need to have `auditorium` installed. However, do keep in mind that all of the backend code will execute only once for the initial rendering, so your animations will be frozen at the starting frame and none of the interaction will work.
154+
155+
## Read on
156+
157+
The [API docs](/api/show/) have a more in-depth explanation about all topics covered here.

0 commit comments

Comments
 (0)