Skip to content

Commit 06e289c

Browse files
committed
Prepared for compressed render output
Added additional generator to handle different output forms: compressed and full.
1 parent 13b3e39 commit 06e289c

1 file changed

Lines changed: 33 additions & 1 deletion

File tree

demo/render.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,38 @@ def html_file_section_handler_github(item: Dict[str, Any]) -> Any:
223223
return file_details_element
224224

225225

226+
def generate_html_section_handler_github(
227+
render_change: Callable[[Dict[str, Any], str, int, int], Optional[Any]]
228+
) -> Callable[[Any], Any]:
229+
"""
230+
Generates a change wrapper, inside which contains a report on each
231+
function or class depending on the compressed or full format.
232+
"""
233+
234+
def html_file_section_handler_github(item: Dict[str, Any]) -> Any:
235+
filepath = item["file"]
236+
file_url = item.get("file_url", filepath)
237+
change_elements = [
238+
render_change(change, filepath, 0, 2) for change in item["changes"]
239+
]
240+
file_summary_element = E.A(filepath, href=file_url)
241+
file_elements = [
242+
E.B("Changes:"),
243+
E.UL(*change_elements),
244+
]
245+
file_elements_div = E.DIV(*file_elements)
246+
file_details_element = E.DIV(
247+
lxml.html.fromstring(
248+
f"<details><summary>{lxml.html.tostring(file_summary_element).decode()}</summary>"
249+
f"{lxml.html.tostring(file_elements_div).decode()}</details>"
250+
)
251+
)
252+
253+
return file_details_element
254+
255+
return html_file_section_handler_github
256+
257+
226258
def generate_render_html(
227259
file_section_handler: Callable[[Dict[str, Any]], Any]
228260
) -> Callable[[Dict[str, Any]], str]:
@@ -311,7 +343,7 @@ def _enrich_changes(changes: List[Dict[str, Any]], root_url: str) -> None:
311343
"json": render_json,
312344
"yaml": render_yaml,
313345
"html": generate_render_html(html_file_section_handler_vanilla),
314-
"html-github": generate_render_html(html_file_section_handler_github),
346+
"html-github": generate_render_html(generate_html_section_handler_github(render_change_as_html))
315347
}
316348

317349

0 commit comments

Comments
 (0)