template: Add initials filter.
This commit is contained in:
parent
ce5ba7123b
commit
0f42421804
1 changed files with 12 additions and 0 deletions
|
|
@ -497,6 +497,7 @@ class Renderer(object):
|
|||
self.env.globals["C"] = C
|
||||
|
||||
# custom filters
|
||||
self.env.filters["initials"] = self._initials
|
||||
self.env.filters["bare_jid"] = self._bare_jid
|
||||
self.env.filters["next_gidx"] = self._next_gidx
|
||||
self.env.filters["cur_gidx"] = self._cur_gidx
|
||||
|
|
@ -799,6 +800,17 @@ class Renderer(object):
|
|||
"""Return the bare JID"""
|
||||
return str(jid.JID(str(full_jid)).bare)
|
||||
|
||||
def _initials(self, name: str) -> str:
|
||||
"""Return the uppercased initials of a name."""
|
||||
name_parts = name.strip().split()
|
||||
if not name_parts:
|
||||
initials = "??"
|
||||
elif len(name_parts) == 1:
|
||||
initials = name_parts[0][:2]
|
||||
else:
|
||||
initials = name_parts[0][0] + name_parts[1][0]
|
||||
return initials.upper()
|
||||
|
||||
@pass_context
|
||||
def _next_gidx(self, ctx, value):
|
||||
"""Use next current global index as suffix"""
|
||||
|
|
|
|||
Loading…
Reference in a new issue