diff --git a/src/calibre/manual/template_lang.rst b/src/calibre/manual/template_lang.rst index 8b0f9b6755..555a29b269 100644 --- a/src/calibre/manual/template_lang.rst +++ b/src/calibre/manual/template_lang.rst @@ -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``. diff --git a/src/calibre/utils/formatter_functions.py b/src/calibre/utils/formatter_functions.py index f0618044ab..ec887887db 100644 --- a/src/calibre/utils/formatter_functions.py +++ b/src/calibre/utils/formatter_functions.py @@ -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(),