Skip to content

Commit

Permalink
Create a new template function: capitalize
Browse files Browse the repository at this point in the history
Update documentation

Update changelog
  • Loading branch information
taniodev committed Sep 6, 2024
1 parent b236046 commit 0b067e9
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions beets/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -1783,6 +1783,11 @@ def tmpl_upper(s):
"""Convert a string to upper case."""
return s.upper()

@staticmethod
def tmpl_capitalize(s):
"""Converts to a capitalized string."""
return s.capitalize()

@staticmethod
def tmpl_title(s):
"""Convert a string to title case."""
Expand Down
2 changes: 2 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ Changelog goes here! Please add your entry to the bottom of one of the lists bel

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
`beet list -a title:something` or `beet list artpath:cover`. Consequently
album queries involving `path` field have been sped up, like `beet list -a
Expand Down
1 change: 1 addition & 0 deletions docs/reference/pathformat.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ These functions are built in to beets:

* ``%lower{text}``: Convert ``text`` to lowercase.
* ``%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.
* ``%left{text,n}``: Return the first ``n`` characters of ``text``.
* ``%right{text,n}``: Return the last ``n`` characters of ``text``.
Expand Down
4 changes: 4 additions & 0 deletions test/test_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,10 @@ def test_upper_case_variable(self):
self._setf("%upper{$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):
self._setf("%title{$title}")
self._assert_dest(b"/base/The Title")
Expand Down

0 comments on commit 0b067e9

Please sign in to comment.