Skip to content

Commit 4d29635

Browse files
authored
Merge pull request #52 from apiad/develop
Merge latest development changes
2 parents d952e8b + cc57eaa commit 4d29635

File tree

4 files changed

+137
-31
lines changed

4 files changed

+137
-31
lines changed

auditorium/components.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,12 @@ def begin(self):
6464
self.widths.pop(0)
6565

6666
def tab(self):
67-
self.ctx.content.append(f"</div>")
68-
self.ctx.content.append(
69-
f'<div class="column" style="width: {self.widths[0] * 100}%;">'
70-
)
71-
self.widths.pop(0)
67+
if self.widths:
68+
self.ctx.content.append(f"</div>")
69+
self.ctx.content.append(
70+
f'<div class="column" style="width: {self.widths[0] * 100}%;">'
71+
)
72+
self.widths.pop(0)
7273

7374
def end(self):
7475
self.ctx.content.append("</div>")

auditorium/server.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,16 @@
2323
@server.get("/")
2424
async def index():
2525
with open(path('templates/server.html')) as fp:
26-
TEMPLATE = Template(fp.read())
26+
return HTMLResponse(fp.read())
2727

28-
return HTMLResponse(TEMPLATE.render(servers_list=list(SERVERS)))
28+
29+
@server.get("/_list/")
30+
async def list_servers():
31+
return dict(
32+
slides=[dict(
33+
name=s
34+
) for s in SERVERS]
35+
)
2936

3037

3138
@server.get("/{name}/")

auditorium/show.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,15 @@ class UpdateData(BaseModel):
3838

3939

4040
class Show(FastAPI):
41-
def __init__(self, title="", theme="white", code_style="monokai"):
41+
def __init__(self, title="", theme="white", code_style="monokai", metadata=None, context_class=None):
4242
self.theme = theme
4343
self.formatter = HtmlFormatter(style=get_style_by_name(code_style))
4444

4545
self._slides = {}
4646
self._sections = []
4747
self._tail = []
48+
self._metadata = metadata or {}
49+
self._context_class = context_class or Context
4850

4951
self.app = FastAPI()
5052
self.app.get("/")(self._index)
@@ -279,14 +281,15 @@ async def _index(self, theme: str = "white"):
279281

280282

281283
class Context:
282-
def __init__(self, slide_id, mode, show, values=None):
284+
def __init__(self, slide_id, mode, show, values=None, metadata=None):
283285
self.content = []
284286
self.update = {}
285287
self.slide_id = slide_id
286288
self.unique_id = 0
287289
self.mode = mode
288290
self.values = values
289291
self.show = show
292+
self.metadata = metadata
290293

291294
## Utility methods
292295

@@ -446,7 +449,7 @@ def slide_id(self) -> str:
446449
return self._slide_id
447450

448451
def run(self, mode, values=None) -> Context:
449-
ctx = Context(self.slide_id, mode, self._show, values)
452+
ctx = self._show._context_class(self.slide_id, mode, self._show, values, self._show._metadata.get(self.slide_id))
450453

451454
if self._func.__doc__:
452455
ctx.markdown(self._func.__doc__)

auditorium/templates/server.html

+116-21
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,135 @@
11
<!DOCTYPE html>
22
<html lang="en">
3+
34
<head>
45
<meta charset="UTF-8">
56
<meta name="viewport" content="width=device-width, initial-scale=1.0">
67
<meta http-equiv="X-UA-Compatible" content="ie=edge">
7-
<title>Auditorium</title>
8+
<title>auditorium</title>
89

910
<link href="https://fonts.googleapis.com/css?family=DM+Sans:300,400,700&display=swap" rel="stylesheet">
10-
<link rel="stylesheet" href="static/css/server.css">
11+
<link href="https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css" rel="stylesheet">
12+
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
13+
1114
</head>
12-
<body>
1315

14-
<a class="fork-me" href="https://github.com/apiad/auditorium"><img width="149" height="149" src="https://github.blog/wp-content/uploads/2008/12/forkme_right_white_ffffff.png?resize=149%2C149" class="attachment-full size-full" alt="Fork me on GitHub" data-recalc-dims="1"></a>
16+
<body class="bg-gray-100 font-sans h-full">
17+
<div id="app">
18+
19+
<div class="bg-blue-900 text-gray-100 py-6 px-20">
20+
<h1 class="text-4xl font-semibold text-center">auditorium</h1>
21+
<h2 class="text-2xl text-center leading-tight">A Python-powered slideshow generator with steroids</h2>
22+
23+
<a href="https://github.com/apiad/auditorium" class="github-corner absolute top-0 right-0 fill-current"
24+
aria-label="View source on GitHub"><svg width="80" height="80" viewBox="0 0 250 250" aria-hidden="true">
25+
<path class="text-blue-700" d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path>
26+
<path
27+
d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2"
28+
style="transform-origin: 130px 106px;" class="octo-arm"></path>
29+
<path
30+
d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z"
31+
class="octo-body"></path>
32+
</svg>
33+
</a>
34+
</div>
35+
36+
<div class="max-w-screen-lg mx-auto mb-24">
37+
<h3 class="p-4 text-xl text-blue-900">
38+
What's this?
39+
</h3>
1540

16-
<div class="main">
17-
<div class="hero">
41+
<p class="px-4 text-lg text-gray-800">
42+
<span class="font-mono">auditorium</span>
43+
is a Python-powered slide generator. You write pure Python code and
44+
<span class="font-mono">auditorium</span>
45+
renders and serves a beautiful HTML slideshow.
46+
</p>
1847

19-
<h1>Auditorium</h1>
20-
<h2>A Python-powered slideshow generator with steroids</h2>
48+
<h3 class="px-4 py-8 text-xl text-blue-900">The following slides are currently running:</h3>
2149

50+
<div class="flex flex-wrap w-full justify-center px-4">
51+
<button @click="goto(slide)"
52+
class="relative p-2 border text-blue-800 bg-white hover:shadow-lg hover:text-gray-100 hover:bg-blue-600 cursor-pointer w-72 h-48 m-2 flex-shrink-0"
53+
v-for="slide in slides">
54+
<iframe class="mb-1" :src="slide.name" frameborder="0"></iframe>
55+
<span class="mx-auto font-semibold">{{ slide.name }}</span>
56+
</button>
57+
</div>
2258
</div>
23-
</div>
2459

25-
<div class="section">
26-
<h3>The following slideshows have been registered:</h3>
27-
<ul>
28-
{% for name in servers_list %}
29-
<li>
30-
<a href="/{{ name }}/">{{ name }}</a>
31-
</li>
32-
{% endfor %}
33-
</ul>
60+
<div class="fixed bottom-0 p-4 flex bg-blue-900 w-full">
61+
<div class="mx-auto text-gray-100">
62+
Copyright 2020
63+
<span class="mx-2">
64+
&bullet;
65+
</span>
66+
<a class="font-semibold hover:underline" href="http://auditorium.apiad.net">auditorium.apiad.net</a>
67+
</div>
68+
</div>
3469
</div>
3570

36-
<div class="footer">
37-
Copyright 2020 - <a href="http://auditorium.apiad.net">auditorium.apiad.net</a>
38-
</div>
71+
3972
</body>
73+
74+
<script>
75+
var vm = new Vue({
76+
el: "#app",
77+
data: {
78+
slides: []
79+
},
80+
methods: {
81+
goto(slide) {
82+
window.location = slide.name;
83+
}
84+
}
85+
});
86+
87+
setInterval(() => {
88+
fetch("./_list/").then(res => {
89+
return res.json();
90+
}).then(data => {
91+
console.log(data);
92+
vm.slides = data.slides;
93+
});
94+
}, 1000);
95+
</script>
96+
97+
<style>
98+
.github-corner:hover .octo-arm {
99+
animation: octocat-wave 560ms ease-in-out
100+
}
101+
102+
iframe {
103+
pointer-events: none;
104+
}
105+
106+
@keyframes octocat-wave {
107+
108+
0%,
109+
100% {
110+
transform: rotate(0)
111+
}
112+
113+
20%,
114+
60% {
115+
transform: rotate(-25deg)
116+
}
117+
118+
40%,
119+
80% {
120+
transform: rotate(10deg)
121+
}
122+
}
123+
124+
@media (max-width:500px) {
125+
.github-corner:hover .octo-arm {
126+
animation: none
127+
}
128+
129+
.github-corner .octo-arm {
130+
animation: octocat-wave 560ms ease-in-out
131+
}
132+
}
133+
</style>
134+
40135
</html>

0 commit comments

Comments
 (0)