diff --git a/src/calibre/library/database2.py b/src/calibre/library/database2.py index 3ebd63afde..f203f36bd9 100644 --- a/src/calibre/library/database2.py +++ b/src/calibre/library/database2.py @@ -963,6 +963,7 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns): mi.cover_data = ('jpeg', cdata) else: mi.cover = self.cover(id, index_is_id=True, as_path=True) + mi.has_cover = _('Yes') if self.has_cover(id) else '' return mi def has_book(self, mi): diff --git a/src/calibre/manual/template_lang.rst b/src/calibre/manual/template_lang.rst index f9824187e5..9f33bcbb9e 100644 --- a/src/calibre/manual/template_lang.rst +++ b/src/calibre/manual/template_lang.rst @@ -257,6 +257,7 @@ The following functions are available in addition to those described in single-f iso : the date with time and timezone. Must be the only format present. * ``eval(string)`` -- evaluates the string as a program, passing the local variables (those ``assign`` ed to). This permits using the template processor to construct complex results from local variables. + * ``has_cover()`` -- return ``Yes`` if the book has a cover, otherwise return the empty string * ``not(value)`` -- returns the string "1" if the value is empty, otherwise returns the empty string. This function works well with test or first_non_empty. You can have as many values as you want. * ``merge_lists(list1, list2, separator)`` -- return a list made by merging the items in list1 and list2, removing duplicate items using a case-insensitive compare. If items differ in case, the one in list1 is used. The items in list1 and list2 are separated by separator, as are the items in the returned list. * ``multiply(x, y)`` -- returns x * y. Throws an exception if either x or y are not numbers. diff --git a/src/calibre/utils/formatter_functions.py b/src/calibre/utils/formatter_functions.py index 1684b9f85b..fcfd69d16d 100644 --- a/src/calibre/utils/formatter_functions.py +++ b/src/calibre/utils/formatter_functions.py @@ -679,6 +679,18 @@ class BuiltinOndevice(BuiltinFormatterFunction): return _('Yes') return '' +class BuiltinHasCover(BuiltinFormatterFunction): + name = 'has_cover' + arg_count = 0 + category = 'Get values from metadata' + __doc__ = doc = _('has_cover() -- return Yes if the book has a cover, ' + 'otherwise return the empty string') + + def evaluate(self, formatter, kwargs, mi, locals): + if mi.has_cover: + return _('Yes') + return '' + class BuiltinFirstNonEmpty(BuiltinFormatterFunction): name = 'first_non_empty' arg_count = -1 @@ -814,6 +826,7 @@ builtin_eval = BuiltinEval() builtin_first_non_empty = BuiltinFirstNonEmpty() builtin_field = BuiltinField() builtin_format_date = BuiltinFormatDate() +builtin_has_cover = BuiltinHasCover() builtin_identifier_in_list = BuiltinIdentifierInList() builtin_ifempty = BuiltinIfempty() builtin_in_list = BuiltinInList()