mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
New author_sorts() formatter function. Returns the author sort strings from the authors table for the authors in the book.
This commit is contained in:
parent
6ea8bab905
commit
521c98b4ff
@ -240,6 +240,7 @@ The following functions are available in addition to those described in single-f
|
||||
* ``assign(id, val)`` -- assigns val to id, then returns val. id must be an identifier, not an expression
|
||||
* ``approximate_formats()`` -- return a comma-separated list of formats that at one point were associated with the book. There is no guarantee that the list is correct, although it probably is. This function can be called in template program mode using the template ``{:'approximate_formats()'}``. Note that format names are always uppercase, as in EPUB.
|
||||
* ``author_links(val_separator, pair_separator)`` -- returns a string containing a list of authors and that author's link values in the form ``author1 val_separator author1link pair_separator author2 val_separator author2link`` etc. An author is separated from its link value by the ``val_separator`` string with no added spaces. ``author:linkvalue`` pairs are separated by the ``pair_separator`` string argument with no added spaces. It is up to you to choose separator strings that do not occur in author names or links. An author is included even if the author link is empty.
|
||||
* ``author_sorts(val_separator)`` -- returns a string containing a list of author's sort values for the authors of the book. The sort is the one in the author metadata (different from the author_sort in books). The returned list has the form author sort 1 ``val_separator`` author sort 2 etc. The author sort values in this list are in the same order as the authors of the book. If you want spaces around ``val_separator`` then include them in the separator string
|
||||
* ``booksize()`` -- returns the value of the |app| 'size' field. Returns '' if there are no formats.
|
||||
* ``cmp(x, y, lt, eq, gt)`` -- compares x and y after converting both to numbers. Returns ``lt`` if x < y. Returns ``eq`` if x == y. Otherwise returns ``gt``.
|
||||
* ``current_library_name() -- `` return the last name on the path to the current calibre library. This function can be called in template program mode using the template ``{:'current_library_name()'}``.
|
||||
|
@ -1423,9 +1423,30 @@ class BuiltinAuthorLinks(BuiltinFormatterFunction):
|
||||
return pair_sep.join(n + val_sep + link_data[n] for n in names)
|
||||
return _('This function can be used only in the GUI')
|
||||
|
||||
class BuiltinAuthorSorts(BuiltinFormatterFunction):
|
||||
name = 'author_sorts'
|
||||
arg_count = 1
|
||||
category = 'Get values from metadata'
|
||||
__doc__ = doc = _('author_sorts(val_separator) -- returns a string '
|
||||
'containing a list of author\'s sort values for the '
|
||||
'authors of the book. The sort is the one in the author '
|
||||
'metadata (different from the author_sort in books). The '
|
||||
'returned list has the form author sort 1 val_separator '
|
||||
'author sort 2 etc. The author sort values in this list '
|
||||
'are in the same order as the authors of the book. If '
|
||||
'you want spaces around val_separator then include them '
|
||||
'in the separator string')
|
||||
|
||||
def evaluate(self, formatter, kwargs, mi, locals, val_sep):
|
||||
sort_data = mi.author_sort_map
|
||||
if not sort_data:
|
||||
return ''
|
||||
names = [sort_data.get(n) for n in mi.authors if n.strip()]
|
||||
return val_sep.join(n for n in names)
|
||||
|
||||
_formatter_builtins = [
|
||||
BuiltinAdd(), BuiltinAnd(), BuiltinApproximateFormats(),
|
||||
BuiltinAssign(), BuiltinAuthorLinks(), BuiltinBooksize(),
|
||||
BuiltinAdd(), BuiltinAnd(), BuiltinApproximateFormats(), BuiltinAssign(),
|
||||
BuiltinAuthorLinks(), BuiltinAuthorSorts(), BuiltinBooksize(),
|
||||
BuiltinCapitalize(), BuiltinCmp(), BuiltinContains(), BuiltinCount(),
|
||||
BuiltinCurrentLibraryName(), BuiltinCurrentLibraryPath(),
|
||||
BuiltinDaysBetween(), BuiltinDivide(), BuiltinEval(), BuiltinFirstNonEmpty(),
|
||||
|
Loading…
x
Reference in New Issue
Block a user