has_cover() template function

This commit is contained in:
Kovid Goyal 2011-07-02 09:15:09 -06:00
commit 75f44358e8
3 changed files with 15 additions and 0 deletions

View File

@ -963,6 +963,7 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
mi.cover_data = ('jpeg', cdata) mi.cover_data = ('jpeg', cdata)
else: else:
mi.cover = self.cover(id, index_is_id=True, as_path=True) mi.cover = self.cover(id, index_is_id=True, as_path=True)
mi.has_cover = _('Yes') if self.has_cover(id) else ''
return mi return mi
def has_book(self, mi): def has_book(self, mi):

View File

@ -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. 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. * ``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. * ``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. * ``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. * ``multiply(x, y)`` -- returns x * y. Throws an exception if either x or y are not numbers.

View File

@ -679,6 +679,18 @@ class BuiltinOndevice(BuiltinFormatterFunction):
return _('Yes') return _('Yes')
return '' 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): class BuiltinFirstNonEmpty(BuiltinFormatterFunction):
name = 'first_non_empty' name = 'first_non_empty'
arg_count = -1 arg_count = -1
@ -814,6 +826,7 @@ builtin_eval = BuiltinEval()
builtin_first_non_empty = BuiltinFirstNonEmpty() builtin_first_non_empty = BuiltinFirstNonEmpty()
builtin_field = BuiltinField() builtin_field = BuiltinField()
builtin_format_date = BuiltinFormatDate() builtin_format_date = BuiltinFormatDate()
builtin_has_cover = BuiltinHasCover()
builtin_identifier_in_list = BuiltinIdentifierInList() builtin_identifier_in_list = BuiltinIdentifierInList()
builtin_ifempty = BuiltinIfempty() builtin_ifempty = BuiltinIfempty()
builtin_in_list = BuiltinInList() builtin_in_list = BuiltinInList()