mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Merge branch 'master' of https://github.com/cbhaley/calibre
This commit is contained in:
commit
05776164d0
@ -346,7 +346,7 @@ parameters can be statements (sequences of expressions). Note that the definitiv
|
|||||||
|
|
||||||
* ``and(value, value, ...)`` -- returns the string "1" if all values are not empty, otherwise returns the empty string. This function works
|
* ``and(value, value, ...)`` -- returns the string "1" if all values are not 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.
|
well with test or first_non_empty. You can have as many values as you want.
|
||||||
* ``add(x, y)`` -- returns x + y. Throws an exception if either x or y are not numbers.
|
* ``add(x, y, ...)`` -- returns the sum of its arguments. Throws an exception if an argument is not a number.
|
||||||
* ``assign(id, val)`` -- assigns val to id, then returns val. id must be an identifier, not an expression
|
* ``assign(id, val)`` -- assigns val to id, then returns val. id must be an identifier, not an expression
|
||||||
* ``approximate_formats()`` -- return a comma-separated list of formats that at one point were associated with the book. There is no
|
* ``approximate_formats()`` -- return a comma-separated list of formats that at one point were associated with the book. There is no
|
||||||
guarantee that the list is correct, although it probably is. This function can be called in Template Program Mode using the template
|
guarantee that the list is correct, although it probably is. This function can be called in Template Program Mode using the template
|
||||||
@ -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
|
`[[` 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.
|
(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(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,
|
* ``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
|
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
|
``{series_index:05.2f| - |- }``. This function is provided to ease
|
||||||
@ -480,7 +481,7 @@ parameters can be statements (sequences of expressions). Note that the definitiv
|
|||||||
``separator``, as are the items in the returned list.
|
``separator``, as are the items in the returned list.
|
||||||
* ``mod(x)`` -- returns the remainder of ``x / y``, where ``x``, ``y``, and the result are integers. Throws an exception if either ``x`` or
|
* ``mod(x)`` -- returns the remainder of ``x / y``, where ``x``, ``y``, and the result are integers. Throws an exception if either ``x`` or
|
||||||
``y`` is not a number.
|
``y`` is not a number.
|
||||||
* ``multiply(x, y)`` -- returns x * y. Throws an exception if either x or y are not numbers.
|
* ``multiply(x, y, ...)`` -- returns the product of its arguments. Throws an exception if any argument is not a number.
|
||||||
* ``ondevice()`` -- return the string "Yes" if ``ondevice`` is set, otherwise return the empty string
|
* ``ondevice()`` -- return the string "Yes" if ``ondevice`` is set, otherwise return the empty string
|
||||||
* ``or(value, value, ...)`` -- returns the string ``"1"`` if any value is not empty, otherwise returns the empty string. This function works
|
* ``or(value, value, ...)`` -- returns the string ``"1"`` if any value is not 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.
|
well with test or `first_non_empty`. You can have as many values as you want.
|
||||||
|
@ -241,14 +241,17 @@ class BuiltinStrlen(BuiltinFormatterFunction):
|
|||||||
|
|
||||||
class BuiltinAdd(BuiltinFormatterFunction):
|
class BuiltinAdd(BuiltinFormatterFunction):
|
||||||
name = 'add'
|
name = 'add'
|
||||||
arg_count = 2
|
arg_count = -1
|
||||||
category = 'Arithmetic'
|
category = 'Arithmetic'
|
||||||
__doc__ = doc = _('add(x, y) -- returns x + y. Throws an exception if either x or y are not numbers.')
|
__doc__ = doc = _('add(x, y, ...) -- returns the sum of its arguments. '
|
||||||
|
'Throws an exception if an argument is not a number.')
|
||||||
|
|
||||||
def evaluate(self, formatter, kwargs, mi, locals, x, y):
|
def evaluate(self, formatter, kwargs, mi, locals, *args):
|
||||||
x = float(x if x and x != 'None' else 0)
|
res = 0
|
||||||
y = float(y if y and y != 'None' else 0)
|
for v in args:
|
||||||
return unicode_type(x + y)
|
v = float(v if v and v != 'None' else 0)
|
||||||
|
res += v
|
||||||
|
return unicode_type(res)
|
||||||
|
|
||||||
|
|
||||||
class BuiltinSubtract(BuiltinFormatterFunction):
|
class BuiltinSubtract(BuiltinFormatterFunction):
|
||||||
@ -265,14 +268,17 @@ class BuiltinSubtract(BuiltinFormatterFunction):
|
|||||||
|
|
||||||
class BuiltinMultiply(BuiltinFormatterFunction):
|
class BuiltinMultiply(BuiltinFormatterFunction):
|
||||||
name = 'multiply'
|
name = 'multiply'
|
||||||
arg_count = 2
|
arg_count = -1
|
||||||
category = 'Arithmetic'
|
category = 'Arithmetic'
|
||||||
__doc__ = doc = _('multiply(x, y) -- returns x * y. Throws an exception if either x or y are not numbers.')
|
__doc__ = doc = _('multiply(x, y, ...) -- returns the product of its arguments. '
|
||||||
|
'Throws an exception if any argument is not a number.')
|
||||||
|
|
||||||
def evaluate(self, formatter, kwargs, mi, locals, x, y):
|
def evaluate(self, formatter, kwargs, mi, locals, *args):
|
||||||
x = float(x if x and x != 'None' else 0)
|
res = 1
|
||||||
y = float(y if y and y != 'None' else 0)
|
for v in args:
|
||||||
return unicode_type(x * y)
|
v = float(v if v and v != 'None' else 0)
|
||||||
|
res *= v
|
||||||
|
return unicode_type(res)
|
||||||
|
|
||||||
|
|
||||||
class BuiltinDivide(BuiltinFormatterFunction):
|
class BuiltinDivide(BuiltinFormatterFunction):
|
||||||
@ -1888,6 +1894,19 @@ class BuiltinGlobals(BuiltinFormatterFunction):
|
|||||||
# The globals function is implemented in-line in the formatter
|
# The globals function is implemented in-line in the formatter
|
||||||
raise NotImplementedError()
|
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 = [
|
_formatter_builtins = [
|
||||||
BuiltinAdd(), BuiltinAnd(), BuiltinApproximateFormats(), BuiltinArguments(),
|
BuiltinAdd(), BuiltinAnd(), BuiltinApproximateFormats(), BuiltinArguments(),
|
||||||
@ -1897,7 +1916,8 @@ _formatter_builtins = [
|
|||||||
BuiltinCmp(), BuiltinConnectedDeviceName(), BuiltinConnectedDeviceUUID(), BuiltinContains(),
|
BuiltinCmp(), BuiltinConnectedDeviceName(), BuiltinConnectedDeviceUUID(), BuiltinContains(),
|
||||||
BuiltinCount(), BuiltinCurrentLibraryName(), BuiltinCurrentLibraryPath(),
|
BuiltinCount(), BuiltinCurrentLibraryName(), BuiltinCurrentLibraryPath(),
|
||||||
BuiltinDaysBetween(), BuiltinDivide(), BuiltinEval(), BuiltinFirstNonEmpty(),
|
BuiltinDaysBetween(), BuiltinDivide(), BuiltinEval(), BuiltinFirstNonEmpty(),
|
||||||
BuiltinField(), BuiltinFinishFormatting(), BuiltinFirstMatchingCmp(), BuiltinFloor(),
|
BuiltinField(), BuiltinFieldExists(),
|
||||||
|
BuiltinFinishFormatting(), BuiltinFirstMatchingCmp(), BuiltinFloor(),
|
||||||
BuiltinFormatDate(), BuiltinFormatNumber(), BuiltinFormatsModtimes(),
|
BuiltinFormatDate(), BuiltinFormatNumber(), BuiltinFormatsModtimes(),
|
||||||
BuiltinFormatsPaths(), BuiltinFormatsSizes(), BuiltinFractionalPart(),
|
BuiltinFormatsPaths(), BuiltinFormatsSizes(), BuiltinFractionalPart(),
|
||||||
BuiltinGlobals(),
|
BuiltinGlobals(),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user