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