Create a new template function: capitalize

Update documentation

Update changelog
This commit is contained in:
Tânio Scherer 2024-08-28 21:31:36 -03:00
parent b2360461d0
commit 0b067e9f5b
4 changed files with 12 additions and 0 deletions

View file

@ -1783,6 +1783,11 @@ class DefaultTemplateFunctions:
"""Convert a string to upper case.""" """Convert a string to upper case."""
return s.upper() return s.upper()
@staticmethod
def tmpl_capitalize(s):
"""Converts to a capitalized string."""
return s.capitalize()
@staticmethod @staticmethod
def tmpl_title(s): def tmpl_title(s):
"""Convert a string to title case.""" """Convert a string to title case."""

View file

@ -8,6 +8,8 @@ Changelog goes here! Please add your entry to the bottom of one of the lists bel
New features: New features:
* New template function added: ``%capitalize``. Converts the first letter of
the text to uppercase and the rest to lowercase.
* Ability to query albums with track db fields and vice-versa, for example * Ability to query albums with track db fields and vice-versa, for example
`beet list -a title:something` or `beet list artpath:cover`. Consequently `beet list -a title:something` or `beet list artpath:cover`. Consequently
album queries involving `path` field have been sped up, like `beet list -a album queries involving `path` field have been sped up, like `beet list -a

View file

@ -60,6 +60,7 @@ These functions are built in to beets:
* ``%lower{text}``: Convert ``text`` to lowercase. * ``%lower{text}``: Convert ``text`` to lowercase.
* ``%upper{text}``: Convert ``text`` to UPPERCASE. * ``%upper{text}``: Convert ``text`` to UPPERCASE.
* ``%capitalize{text}``: Make the first letter of ``text`` UPPERCASE and the rest lowercase.
* ``%title{text}``: Convert ``text`` to Title Case. * ``%title{text}``: Convert ``text`` to Title Case.
* ``%left{text,n}``: Return the first ``n`` characters of ``text``. * ``%left{text,n}``: Return the first ``n`` characters of ``text``.
* ``%right{text,n}``: Return the last ``n`` characters of ``text``. * ``%right{text,n}``: Return the last ``n`` characters of ``text``.

View file

@ -629,6 +629,10 @@ class DestinationFunctionTest(BeetsTestCase, PathFormattingMixin):
self._setf("%upper{$title}") self._setf("%upper{$title}")
self._assert_dest(b"/base/THE TITLE") self._assert_dest(b"/base/THE TITLE")
def test_capitalize_variable(self):
self._setf("%capitalize{$title}")
self._assert_dest(b"/base/The title")
def test_title_case_variable(self): def test_title_case_variable(self):
self._setf("%title{$title}") self._setf("%title{$title}")
self._assert_dest(b"/base/The Title") self._assert_dest(b"/base/The Title")