"""YAML requirements renderer — for request_*.yaml style files.""" from html import escape def render(filepath): """Render YAML requirements as grouped tables (F_/P_/S_ sections).""" try: import yaml except ImportError: return '
{escape(str(data))}'
sections = {
'F_': ('功能需求', []),
'P_': ('性能需求', []),
'S_': ('规格需求', []),
}
other = []
for key, val in data.items():
if not isinstance(val, dict):
continue
name = val.get('name', key)
desc = val.get('description', '')
limit = val.get('limit', None)
limit_str = ''
if limit and isinstance(limit, dict):
parts = []
if 'min' in limit and limit['min'] is not None:
parts.append(f'>= {limit["min"]}')
if 'max' in limit and limit['max'] is not None:
parts.append(f'<= {limit["max"]}')
if 'value' in limit:
parts.append(str(limit['value']))
if 'unit' in limit:
parts.append(limit['unit'])
if 'count' in limit:
parts.append(f'x{limit["count"]}')
limit_str = ' '.join(parts)
entry = {'id': key, 'name': name, 'desc': desc, 'limit': limit_str}
placed = False
for prefix in sections:
if key.startswith(prefix):
sections[prefix][1].append(entry)
placed = True
break
if not placed:
other.append(entry)
html = []
for prefix, (label, items) in sections.items():
if not items:
continue
html.append(f'| ID | ' '名称 | ' '描述 | ' '指标 | ' '
|---|---|---|---|
| {escape(e["id"])} | ' f'{escape(e["name"])} | ' f'{escape(e["desc"])} | ' f'{escape(e["limit"])} | ' f'