Some minor documentation fixes and tests.
This commit is contained in:
parent
498e3f5064
commit
08b18524fd
1 changed files with 9 additions and 6 deletions
|
|
@ -98,12 +98,14 @@ def time(text, *args):
|
||||||
strformat = str(args[0])
|
strformat = str(args[0])
|
||||||
return time.strftime(strformat)
|
return time.strftime(strformat)
|
||||||
|
|
||||||
|
|
||||||
# load functions from module (including this one, if using default settings)
|
# load functions from module (including this one, if using default settings)
|
||||||
_INLINE_FUNCS = {}
|
_INLINE_FUNCS = {}
|
||||||
for module in utils.make_iter(settings.INLINEFUNC_MODULES):
|
for module in utils.make_iter(settings.INLINEFUNC_MODULES):
|
||||||
_INLINE_FUNCS.update(utils.all_from_module(module))
|
_INLINE_FUNCS.update(utils.all_from_module(module))
|
||||||
_INLINE_FUNCS.pop("inline_func_parse", None)
|
_INLINE_FUNCS.pop("inline_func_parse", None)
|
||||||
|
|
||||||
|
|
||||||
# dynamically build regexes for found functions
|
# dynamically build regexes for found functions
|
||||||
_RE_FUNCFULL = r"\{%s\((.*?)\)(.*?){/%s"
|
_RE_FUNCFULL = r"\{%s\((.*?)\)(.*?){/%s"
|
||||||
_RE_FUNCSTART = r"\{((?:%s))"
|
_RE_FUNCSTART = r"\{((?:%s))"
|
||||||
|
|
@ -143,11 +145,11 @@ def parse_inlinefunc(text, strip=False):
|
||||||
"""
|
"""
|
||||||
Parse inline function-replacement.
|
Parse inline function-replacement.
|
||||||
|
|
||||||
Default is to ignore such functions,
|
strip - remove all supported inlinefuncs from text
|
||||||
use strip=False to leave them in.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if strip:
|
if strip:
|
||||||
|
# strip all functions
|
||||||
return _FUNCCLEAN_REGEX.sub("", text)
|
return _FUNCCLEAN_REGEX.sub("", text)
|
||||||
|
|
||||||
stack = []
|
stack = []
|
||||||
|
|
@ -169,8 +171,9 @@ def parse_inlinefunc(text, strip=False):
|
||||||
return "".join(stack)
|
return "".join(stack)
|
||||||
|
|
||||||
def _test():
|
def _test():
|
||||||
# this should pad everything
|
# this should all be handled
|
||||||
s = "This is a {crop()text at {time(){/time with a{pad(78,r,-)text {pad(5)of{/pad {pad(8)nice{/pad size{/pad inside {pad(4,l)it{/pad.{/crop"
|
s = "This is a text with a{pad(78,c,-)text {pad(5)of{/pad {pad(30)nice{/pad size{/pad inside {pad(4,l)it{/pad."
|
||||||
print " intext:", s
|
s2 = "This is a text with a----------------text of nice size---------------- inside it ."
|
||||||
t = parse_inlinefunc(s)
|
t = parse_inlinefunc(s)
|
||||||
print "outtext:", t
|
assert(t == s2)
|
||||||
|
return t
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue