This is an automated email from the ASF dual-hosted git repository.
sbp pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tooling-trusted-release.git
The following commit(s) were added to refs/heads/main by this push:
new ae5525e Add source code references to generated elements
ae5525e is described below
commit ae5525e1be73f77592ac5f4544c8a86bce1dde25
Author: Sean B. Palmer <[email protected]>
AuthorDate: Mon Sep 15 17:29:38 2025 +0100
Add source code references to generated elements
---
atr/htm.py | 28 +++++++++++++++++++++++-----
1 file changed, 23 insertions(+), 5 deletions(-)
diff --git a/atr/htm.py b/atr/htm.py
index eedbaa8..a6d0513 100644
--- a/atr/htm.py
+++ b/atr/htm.py
@@ -21,6 +21,8 @@ from typing import TYPE_CHECKING, Any
import htpy
+from . import log
+
if TYPE_CHECKING:
from collections.abc import Callable
@@ -73,18 +75,34 @@ class Block:
match eob:
case Block():
# TODO: Does not support separator
- self.elements.append(eob.collect())
+ self.elements.append(eob.collect(depth=2))
case htpy.Element():
self.elements.append(eob)
- def collect(self, separator: str | None = None) -> htpy.Element:
+ def collect(self, separator: str | None = None, depth: int = 1) ->
htpy.Element:
+ src = log.caller_name(depth=depth)
+
if separator is not None:
separated: list[htpy.Element | str] = [separator] * (2 *
len(self.elements) - 1)
separated[::2] = self.elements
- self.elements = separated
+ elements = separated
+ else:
+ elements = self.elements
+
if self.element is None:
- return htpy.div[*self.elements]
- return self.element[*self.elements]
+ return htpy.div(data_src=src)[*elements]
+
+ new_element = self.element.__class__(
+ self.element._name,
+ self.element._attrs,
+ self.element._children,
+ )
+ if ' data-src="' not in new_element._attrs:
+ if new_element._attrs:
+ new_element._attrs = new_element._attrs + f' data-src="{src}"'
+ else:
+ new_element._attrs = f' data-src="{src}"'
+ return new_element[*elements]
@property
def a(self) -> BlockElementCallable:
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]