Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ History
2.3.2 (unreleased)
------------------

- Parse value if they are callable, for HTML5 Data-Attributes
[2silver, 2019-06-12]

- Use ``logger.warning`` instead of deprecated ``logger.warn``.
[rnix]

Expand Down
12 changes: 12 additions & 0 deletions src/yafowil/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,18 @@ def as_data_attrs(data):
continue
if val is UNSET:
continue

# this probably could be done much better!
# 2silver, 2019-06-11
if callable(val):
try:
val = val()
except TypeError:
logging.warning(
'converting data-attribute for "{}" failed'.format(key)
)
val = str(val)

# convert value to JSON dump if no string.
if not isinstance(val, STR_TYPE):
# also remove leading and trailing double quotes,
Expand Down