-
Notifications
You must be signed in to change notification settings - Fork 4
/
app.py
39 lines (28 loc) · 1.18 KB
/
app.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
import types
from tf.advanced.helpers import NB
from tf.advanced.app import App
MODIFIERS = "lang script intl unc cor rem rec alt vac".strip().split()
def fmt_layoutOrig(app, n, **kwargs):
return app._wrapHtml(n, "glyph", "")
def fmt_layoutTrans(app, n, **kwargs):
return app._wrapHtml(n, "glyph", "e")
def fmt_layoutSource(app, n, **kwargs):
return app._wrapHtml(n, "glyph", "o")
class TfApp(App):
def __init__(app, *args, **kwargs):
app.fmt_layoutOrig = types.MethodType(fmt_layoutOrig, app)
app.fmt_layoutTrans = types.MethodType(fmt_layoutTrans, app)
app.fmt_layoutSource = types.MethodType(fmt_layoutSource, app)
super().__init__(*args, **kwargs)
def _wrapHtml(app, n, ft, kind):
api = app.api
F = api.F
Fs = api.Fs
after = F.after.v(n) or ""
isEmpty = F.type.v(n) == "empty"
material = NB if isEmpty else (Fs(f"{ft}{kind}").v(n) or "")
clses = " ".join(f"{cf}{Fs(cf).v(n)}" for cf in MODIFIERS if Fs(cf).v(n))
empty = " empty" if isEmpty else ""
if clses:
material = f'<span class="{clses}{empty}">{material}</span>'
return f"{material}{after}"