Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a new template function: capitalize #5409

Merged
merged 1 commit into from
Sep 6, 2024
Merged
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
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
Loading