mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
Implement ffsum
This commit is contained in:
parent
4fe4823dc7
commit
4e097f7e4b
@ -27,7 +27,7 @@ def formatter_funcs():
|
||||
from calibre.utils.ffml_processor import FFMLProcessor
|
||||
from calibre.utils.formatter_functions import formatter_functions
|
||||
|
||||
ans = {}
|
||||
ans = {'doc': {}, 'sum': {}}
|
||||
with TemporaryDirectory() as tdir:
|
||||
db = LibraryDatabase(tdir) # needed to load formatter_funcs
|
||||
ffml = FFMLProcessor()
|
||||
@ -37,7 +37,9 @@ def formatter_funcs():
|
||||
# if we need no indent we can create a new role like
|
||||
# :ffdoc-no-indent:
|
||||
text = ffml.document_to_rst(func.doc, func_name, indent=1)
|
||||
ans[func_name] = text.strip()
|
||||
ans['doc'][func_name] = text.strip()
|
||||
text = ffml.document_to_summary_rst(func.doc, func_name, indent=1)
|
||||
ans['sum'][func_name] = text.strip()
|
||||
db.close()
|
||||
del db
|
||||
return ans
|
||||
@ -45,7 +47,12 @@ def formatter_funcs():
|
||||
|
||||
def ffdoc(m):
|
||||
func_name = m.group(1)
|
||||
return formatter_funcs()[func_name]
|
||||
return formatter_funcs()['doc'][func_name]
|
||||
|
||||
|
||||
def ffsum(m):
|
||||
func_name = m.group(1)
|
||||
return formatter_funcs()['sum'][func_name]
|
||||
|
||||
|
||||
def source_read_handler(app, docname, source):
|
||||
@ -59,6 +66,7 @@ def source_read_handler(app, docname, source):
|
||||
if docname == 'template_lang':
|
||||
try:
|
||||
src = re.sub(r':ffdoc:`(.+?)`', ffdoc, src)
|
||||
src = re.sub(r':ffsum:`(.+?)`', ffsum, src)
|
||||
except Exception:
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
|
@ -184,43 +184,43 @@ shows the tags for a book, if any. If it has no tags then it show `No tags on th
|
||||
|
||||
The following functions are usable in Single Function Mode because their first parameter is ``value``.
|
||||
|
||||
* :ffsum:`ff_capitalize`
|
||||
* :ffsum:`ff_ceiling`
|
||||
* :ffsum:`ff_cmp`
|
||||
* :ffsum:`ff_contains`
|
||||
* :ffsum:`ff_date_arithmetic`
|
||||
* :ffsum:`ff_floor`
|
||||
* :ffsum:`ff_format_date`
|
||||
* :ffsum:`ff_format_number`
|
||||
* :ffsum:`ff_fractional_part`
|
||||
* :ffsum:`ff_human_readable`
|
||||
* :ffsum:`ff_ifempty`
|
||||
* :ffsum:`ff_language_strings`
|
||||
* :ffsum:`ff_list_contains`
|
||||
* :ffsum:`ff_list_count`
|
||||
* :ffsum:`ff_list_count_matching`
|
||||
* :ffsum:`ff_list_item`
|
||||
* :ffsum:`ff_list_sort`
|
||||
* :ffsum:`ff_lookup`
|
||||
* :ffsum:`ff_lowercase`
|
||||
* :ffsum:`ff_mod`
|
||||
* :ffsum:`ff_rating_to_stars`
|
||||
* :ffsum:`ff_re`
|
||||
* :ffsum:`ff_re_group`
|
||||
* :ffsum:`ff_round`
|
||||
* :ffsum:`ff_select`
|
||||
* :ffsum:`ff_shorten`
|
||||
* :ffsum:`ff_str_in_list`
|
||||
* :ffsum:`ff_subitems`
|
||||
* :ffsum:`ff_sublist`
|
||||
* :ffsum:`ff_substr`
|
||||
* :ffsum:`ff_swap_around_articles`
|
||||
* :ffsum:`ff_swap_around_comma`
|
||||
* :ffsum:`ff_switch`
|
||||
* :ffsum:`ff_test`
|
||||
* :ffsum:`ff_titlecase`
|
||||
* :ffsum:`ff_transliterate`
|
||||
* :ffsum:`ff_uppercase`
|
||||
* :ffsum:`capitalize`
|
||||
* :ffsum:`ceiling`
|
||||
* :ffsum:`cmp`
|
||||
* :ffsum:`contains`
|
||||
* :ffsum:`date_arithmetic`
|
||||
* :ffsum:`floor`
|
||||
* :ffsum:`format_date`
|
||||
* :ffsum:`format_number`
|
||||
* :ffsum:`fractional_part`
|
||||
* :ffsum:`human_readable`
|
||||
* :ffsum:`ifempty`
|
||||
* :ffsum:`language_strings`
|
||||
* :ffsum:`list_contains`
|
||||
* :ffsum:`list_count`
|
||||
* :ffsum:`list_count_matching`
|
||||
* :ffsum:`list_item`
|
||||
* :ffsum:`list_sort`
|
||||
* :ffsum:`lookup`
|
||||
* :ffsum:`lowercase`
|
||||
* :ffsum:`mod`
|
||||
* :ffsum:`rating_to_stars`
|
||||
* :ffsum:`re`
|
||||
* :ffsum:`re_group`
|
||||
* :ffsum:`round`
|
||||
* :ffsum:`select`
|
||||
* :ffsum:`shorten`
|
||||
* :ffsum:`str_in_list`
|
||||
* :ffsum:`subitems`
|
||||
* :ffsum:`sublist`
|
||||
* :ffsum:`substr`
|
||||
* :ffsum:`swap_around_articles`
|
||||
* :ffsum:`swap_around_comma`
|
||||
* :ffsum:`switch`
|
||||
* :ffsum:`test`
|
||||
* :ffsum:`titlecase`
|
||||
* :ffsum:`transliterate`
|
||||
* :ffsum:`uppercase`
|
||||
|
||||
**Using functions and formatting in the same template**
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user