mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 10:14:46 -04:00
Template language: Add a current_library_name() function that can be used to return the name of the currently opened library in calibre
This commit is contained in:
commit
8cc4134f06
@ -242,6 +242,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
|
||||
* ``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()'}``.
|
||||
* ``days_between(date1, date2)`` -- return the number of days between ``date1`` and ``date2``. The number is positive if ``date1`` is greater than ``date2``, otherwise negative. If either ``date1`` or ``date2`` are not dates, the function returns the empty string.
|
||||
* ``divide(x, y)`` -- returns x / y. Throws an exception if either x or y are not numbers.
|
||||
* ``field(name)`` -- returns the metadata field named by ``name``.
|
||||
|
@ -1106,9 +1106,22 @@ class BuiltinLanguageCodes(BuiltinFormatterFunction):
|
||||
pass
|
||||
return ', '.join(retval)
|
||||
|
||||
class BuiltinCurrentLibraryName(BuiltinFormatterFunction):
|
||||
name = 'current_library_name'
|
||||
arg_count = 0
|
||||
category = 'Get values from metadata'
|
||||
__doc__ = doc = _('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()\'}".')
|
||||
def evaluate(self, formatter, kwargs, mi, locals):
|
||||
from calibre.library import current_library_name
|
||||
return current_library_name()
|
||||
|
||||
_formatter_builtins = [
|
||||
BuiltinAdd(), BuiltinAnd(), BuiltinAssign(), BuiltinBooksize(),
|
||||
BuiltinCapitalize(), BuiltinCmp(), BuiltinContains(), BuiltinCount(),
|
||||
BuiltinCurrentLibraryName(),
|
||||
BuiltinDaysBetween(), BuiltinDivide(), BuiltinEval(),
|
||||
BuiltinFirstNonEmpty(), BuiltinField(), BuiltinFormatDate(),
|
||||
BuiltinFormatNumber(), BuiltinFormatsModtimes(), BuiltinFormatsSizes(),
|
||||
|
Loading…
x
Reference in New Issue
Block a user