mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Make function signature detection more robust when generating template langauge help for the User Manual.
This commit is contained in:
parent
42ca1149e5
commit
e8304084df
@ -1,9 +1,11 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
|
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
__license__ = 'GPL v3'
|
__license__ = 'GPL v3'
|
||||||
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||||
|
|
||||||
|
import re
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
|
||||||
PREAMBLE = '''\
|
PREAMBLE = '''\
|
||||||
@ -12,7 +14,10 @@ PREAMBLE = '''\
|
|||||||
Reference for all built-in template language functions
|
Reference for all built-in template language functions
|
||||||
========================================================
|
========================================================
|
||||||
|
|
||||||
Here, we document all the built-in functions available in the calibre template language. Every function is implemented as a class in python and you can click the source links to see the source code, in case the documentation is insufficient. The functions are arranged in logical groups by type.
|
Here, we document all the built-in functions available in the calibre template
|
||||||
|
language. Every function is implemented as a class in python and you can click
|
||||||
|
the source links to see the source code, in case the documentation is
|
||||||
|
insufficient. The functions are arranged in logical groups by type.
|
||||||
|
|
||||||
.. contents::
|
.. contents::
|
||||||
:depth: 2
|
:depth: 2
|
||||||
@ -41,7 +46,9 @@ POSTAMBLE = '''\
|
|||||||
API of the Metadata objects
|
API of the Metadata objects
|
||||||
----------------------------
|
----------------------------
|
||||||
|
|
||||||
The python implementation of the template functions is passed in a Metadata object. Knowing it's API is useful if you want to define your own template functions.
|
The python implementation of the template functions is passed in a Metadata
|
||||||
|
object. Knowing it's API is useful if you want to define your own template
|
||||||
|
functions.
|
||||||
|
|
||||||
.. module:: calibre.ebooks.metadata.book.base
|
.. module:: calibre.ebooks.metadata.book.base
|
||||||
|
|
||||||
@ -60,17 +67,18 @@ The python implementation of the template functions is passed in a Metadata obje
|
|||||||
|
|
||||||
def generate_template_language_help(language):
|
def generate_template_language_help(language):
|
||||||
from calibre.utils.formatter_functions import formatter_functions
|
from calibre.utils.formatter_functions import formatter_functions
|
||||||
|
pat = re.compile(r'\)\s*-{1,2}')
|
||||||
|
|
||||||
funcs = defaultdict(dict)
|
funcs = defaultdict(dict)
|
||||||
|
|
||||||
for func in formatter_functions().get_builtins().values():
|
for func in formatter_functions().get_builtins().values():
|
||||||
class_name = func.__class__.__name__
|
class_name = func.__class__.__name__
|
||||||
func_sig = getattr(func, 'doc')
|
func_sig = getattr(func, 'doc')
|
||||||
x = func_sig.find(' -- ')
|
m = pat.search(func_sig)
|
||||||
if x < 0:
|
if m is None:
|
||||||
print 'No sig for ', class_name
|
print ('No signature for template function ', class_name)
|
||||||
continue
|
continue
|
||||||
func_sig = func_sig[:x]
|
func_sig = func_sig[:m.start()+1]
|
||||||
func_cat = getattr(func, 'category')
|
func_cat = getattr(func, 'category')
|
||||||
funcs[func_cat][func_sig] = class_name
|
funcs[func_cat][func_sig] = class_name
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user