Add the separator argument to

This commit is contained in:
Charles Haley 2014-07-25 12:32:37 +02:00
parent bf52bedeac
commit 54cd94e05e
2 changed files with 15 additions and 11 deletions

View File

@ -242,7 +242,7 @@ The following functions are available in addition to those described in single-f
* ``add(x, y)`` -- returns x + y. Throws an exception if either x or y are not numbers. * ``add(x, y)`` -- returns x + y. Throws an exception if either x or y are not numbers.
* ``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 guarantee that the list is correct, although it probably is. This function can be called in template program mode using the template ``{:'approximate_formats()'}``. Note that format names are always uppercase, as in EPUB. * ``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 ``{:'approximate_formats()'}``. Note that format names are always uppercase, as in EPUB.
* ``author_links()`` -- returns a string containing a list of authors and that author's link values in the form ``author1:author1link & author2:author2link`` etc. An author is separated from its link value by a : character. ``author:linkvalue`` pairs are separated by " & " (space ampersand space) characters. An author is included even if the author link is empty. * ``author_links(val_separator, pair_separator)`` -- returns a string containing a list of authors and that author's link values in the form ``author1 val_separator author1link pair_separator author2 val_separator author2link`` etc. An author is separated from its link value by the ``val_separator`` string with no added spaces. ``author:linkvalue`` pairs are separated by the ``pair_separator`` string argument with no added spaces. It is up to you to choose separator strings that do not occur in author names or links. An author is included even if the author link is empty.
* ``booksize()`` -- returns the value of the |app| 'size' field. Returns '' if there are no formats. * ``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``. * ``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()'}``. * ``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()'}``.

View File

@ -1400,23 +1400,27 @@ class BuiltinTransliterate(BuiltinFormatterFunction):
class BuiltinAuthorLinks(BuiltinFormatterFunction): class BuiltinAuthorLinks(BuiltinFormatterFunction):
name = 'author_links' name = 'author_links'
arg_count = 0 arg_count = 2
category = 'Get values from metadata' category = 'Get values from metadata'
__doc__ = doc = _('author_links() -- returns a string containing a list of ' __doc__ = doc = _('author_links(val_separator, pair_separator) -- returns '
'authors and that author\'s link values in the form ' 'a string containing a list of authors and that author\'s '
'author1:author1link & author2:author2link etc. ' 'link values in the '
'An author is separated from its link value by a : character. ' 'form author1 val_separator author1link pair_separator '
'author:linkvalue pairs are separated by " & " (space ampersand ' 'author2 val_separator author2link etc. An author is '
'space) characters. An author is included even if the ' 'separated from its link value by the val_separator string '
'author link is empty.') 'with no added spaces. author:linkvalue pairs are separated '
'by the pair_separator string argument with no added spaces. '
'It is up to you to choose separator strings that do '
'not occur in author names or links. An author is '
'included even if the author link is empty.')
def evaluate(self, formatter, kwargs, mi, locals): def evaluate(self, formatter, kwargs, mi, locals, val_sep, pair_sep):
if hasattr(mi, '_proxy_metadata'): if hasattr(mi, '_proxy_metadata'):
link_data = mi._proxy_metadata.author_link_map link_data = mi._proxy_metadata.author_link_map
if not link_data: if not link_data:
return '' return ''
names = sorted(link_data.keys(), key=sort_key) names = sorted(link_data.keys(), key=sort_key)
return ' & '.join(n + ':' + link_data[n] for n in names) return pair_sep.join(n + val_sep + link_data[n] for n in names)
return _('This function can be used only in the GUI') return _('This function can be used only in the GUI')
_formatter_builtins = [ _formatter_builtins = [