-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsteps.py
54 lines (47 loc) · 1.68 KB
/
steps.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
"""Modifiers concerned with individual slides and their very concrete content.
"""
from modifiers import TextModifier, AnonymousPlaceHolder
class Step(TextModifier):
"""Special abstract parent of slide bodies,
whose individual slides inherit of.
Useful a meta-list of children so we can dynamically pick the right type
by matching document information with their type name.
"""
def __init__(self, input: str):
intro, body = input.split("{\n", 1)
self.intro = AnonymousPlaceHolder(r"\Step[<type>]{<progress>}", "parse", intro)
body = body.strip()
assert body.endswith("}")
self.body = body.removesuffix("}")
# Responsibility to the kids to parse further.
self.parse_body()
def parse_body(self):
raise NotImplementedError(
f"Cannot parse body for Step type {type(self).__name__}."
)
def render(self) -> str:
"""Rendering a step is not a regular render,
because only _prolog and _epilog special member makes sense
and it should stay within the command.
"""
return (
self.intro.render()
+ "{\n"
+ (
"\n".join(m.render() for m in self._prolog)
if hasattr(self, "_prolog")
else ""
)
+ self.render_body()
+ "\n"
+ (
"\n".join(m.render() for m in self._epilog)
if hasattr(self, "_epilog")
else ""
)
+ "}"
)
def render_body(self):
raise NotImplementedError(
f"Cannot render body for Step type {type(self).__name__}."
)