Skip to content

Commit

Permalink
prepare for callable data-attributes, bluedynamics/yafowil.plone#26 t…
Browse files Browse the repository at this point in the history
…his commit needs
  • Loading branch information
2silver committed Jun 12, 2019
1 parent b977650 commit bf84c53
Showing 1 changed file with 12 additions and 0 deletions.
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

0 comments on commit bf84c53

Please sign in to comment.