mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
New template function: field_exists()
This commit is contained in:
parent
b7c4fcd711
commit
cfbff3d98f
@ -390,6 +390,7 @@ parameters can be statements (sequences of expressions). Note that the definitiv
|
||||
`[[` for the `{` character and `]]` for the '}' character; they are converted automatically. Note also that prefixes and suffixes
|
||||
(the `|prefix|suffix` syntax) cannot be used in the argument to this function when using Template Program Mode.
|
||||
* ``field(name)`` -- returns the metadata field named by ``name``.
|
||||
* ``field_exists(field_name)`` -- checks if a field (column) named ``field_name`` exists, returning '1' if so and '' if not.
|
||||
* ``finish_formatting(val, fmt, prefix, suffix)`` -- apply the format,
|
||||
prefix, and suffix to a value in the same way as done in a template like
|
||||
``{series_index:05.2f| - |- }``. This function is provided to ease
|
||||
|
@ -1894,6 +1894,19 @@ class BuiltinGlobals(BuiltinFormatterFunction):
|
||||
# The globals function is implemented in-line in the formatter
|
||||
raise NotImplementedError()
|
||||
|
||||
class BuiltinFieldExists(BuiltinFormatterFunction):
|
||||
name = 'field_exists'
|
||||
arg_count = 1
|
||||
category = 'If-then-else'
|
||||
__doc__ = doc = _('field_exists(field_name) -- checks if a field '
|
||||
'(column) named field_name exists, returning '
|
||||
"'1' if so and '' if not.")
|
||||
|
||||
def evaluate(self, formatter, kwargs, mi, locals, field_name):
|
||||
if field_name.lower() in mi.all_field_keys():
|
||||
return '1'
|
||||
return ''
|
||||
|
||||
|
||||
_formatter_builtins = [
|
||||
BuiltinAdd(), BuiltinAnd(), BuiltinApproximateFormats(), BuiltinArguments(),
|
||||
@ -1903,7 +1916,8 @@ _formatter_builtins = [
|
||||
BuiltinCmp(), BuiltinConnectedDeviceName(), BuiltinConnectedDeviceUUID(), BuiltinContains(),
|
||||
BuiltinCount(), BuiltinCurrentLibraryName(), BuiltinCurrentLibraryPath(),
|
||||
BuiltinDaysBetween(), BuiltinDivide(), BuiltinEval(), BuiltinFirstNonEmpty(),
|
||||
BuiltinField(), BuiltinFinishFormatting(), BuiltinFirstMatchingCmp(), BuiltinFloor(),
|
||||
BuiltinField(), BuiltinFieldExists(),
|
||||
BuiltinFinishFormatting(), BuiltinFirstMatchingCmp(), BuiltinFloor(),
|
||||
BuiltinFormatDate(), BuiltinFormatNumber(), BuiltinFormatsModtimes(),
|
||||
BuiltinFormatsPaths(), BuiltinFormatsSizes(), BuiltinFractionalPart(),
|
||||
BuiltinGlobals(),
|
||||
|
Loading…
x
Reference in New Issue
Block a user