modal.py¶
clew/wiki/modal.py
The wiki's one modal component, from the Python side (round 3, P1b).
modal
str clew.wiki.modal.modal(str key, str label, str title, str body, str cls="")
A trigger and the template it opens.
Source · 9 lines
def modal(key: str, label: str, title: str, body: str, cls: str = "") -> str:
"""@brief Write a trigger + template. @return HTML."""
classes = f"modal-link {cls}".strip()
return (
f'<a class="{classes}" href="#m={key}" data-modal="{key}">{escape(label)}</a>'
+ modal_template(key, title, body)
)
Activity · 2 steps
Requirements
Flows
modal_template
str clew.wiki.modal.modal_template(str key, str title, str body)
The template alone, for a trigger drawn elsewhere (an SVG box carrying data-modal ).
Source · 10 lines
def modal_template(key: str, title: str, body: str) -> str:
"""REFUSES a key the hash reader would not accept, rather than writing a template whose deep
link silently opens nothing.
@brief Write a template.
@return HTML.
"""
if not _KEY.match(key):
raise ValueError(f"modal key {key!r} must match {_KEY.pattern}")
return f'<template id="modal-{key}" data-title="{escape(title)}">{body}</template>'1 more lines, not shown